|
1 | 1 | /* |
2 | 2 | * Copyright 2022 Apollo Authors |
3 | 3 | * |
4 | | - * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | | - * you may not use this file except in compliance with the License. |
6 | | - * You may obtain a copy of the License at |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
| 5 | + * in compliance with the License. You may obtain a copy of the License at |
7 | 6 | * |
8 | 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
9 | 8 | * |
10 | | - * Unless required by applicable law or agreed to in writing, software |
11 | | - * distributed under the License is distributed on an "AS IS" BASIS, |
12 | | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | | - * See the License for the specific language governing permissions and |
14 | | - * limitations under the License. |
| 9 | + * Unless required by applicable law or agreed to in writing, software distributed under the License |
| 10 | + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
| 11 | + * or implied. See the License for the specific language governing permissions and limitations under |
| 12 | + * the License. |
15 | 13 | * |
16 | 14 | */ |
17 | 15 | package com.ctrip.framework.apollo.biz.utils; |
18 | 16 |
|
19 | 17 | import static org.junit.Assert.assertNotNull; |
20 | | -import static org.junit.Assert.assertTrue; |
| 18 | +import static org.junit.jupiter.api.Assertions.assertFalse; |
| 19 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
21 | 20 |
|
22 | | -import com.ctrip.framework.apollo.biz.MockBeanFactory; |
23 | | -import com.ctrip.framework.apollo.biz.entity.Item; |
24 | 21 | import org.junit.Before; |
25 | 22 | import org.junit.Test; |
26 | 23 |
|
| 24 | +import com.ctrip.framework.apollo.biz.MockBeanFactory; |
| 25 | +import com.ctrip.framework.apollo.biz.entity.Item; |
| 26 | + |
27 | 27 | /** |
28 | 28 | * @author jian.tan |
29 | 29 | */ |
30 | 30 |
|
31 | 31 | public class ConfigChangeContentBuilderTest { |
32 | 32 |
|
33 | | - private final ConfigChangeContentBuilder configChangeContentBuilder = new ConfigChangeContentBuilder(); |
| 33 | + private ConfigChangeContentBuilder configChangeContentBuilder; |
34 | 34 | private String configString; |
| 35 | + private Item createdItem; |
| 36 | + private Item updatedItem; |
| 37 | + private Item updatedItemFalseCheck; |
| 38 | + private Item createdItemFalseCheck; |
35 | 39 |
|
36 | 40 | @Before |
37 | 41 | public void initConfig() { |
38 | | - |
39 | | - Item createdItem = MockBeanFactory.mockItem(1, 1, "timeout", "100", 1); |
40 | | - Item updatedItem = MockBeanFactory.mockItem(1, 1, "timeout", "1001", 1); |
41 | | - |
| 42 | + configChangeContentBuilder = new ConfigChangeContentBuilder(); |
| 43 | + createdItem = MockBeanFactory.mockItem(1, 1, "timeout", "100", 1); |
| 44 | + updatedItem = MockBeanFactory.mockItem(1, 1, "timeout", "1001", 1); |
| 45 | + updatedItemFalseCheck = MockBeanFactory.mockItem(1, 1, "timeout", "100", 1); |
| 46 | + createdItemFalseCheck = MockBeanFactory.mockItem(1, 1, "", "100", 1); |
42 | 47 | configChangeContentBuilder.createItem(createdItem); |
| 48 | + configChangeContentBuilder.createItem(createdItemFalseCheck); |
43 | 49 | configChangeContentBuilder.updateItem(createdItem, updatedItem); |
| 50 | + configChangeContentBuilder.updateItem(createdItem, updatedItemFalseCheck); |
44 | 51 | configChangeContentBuilder.deleteItem(updatedItem); |
45 | | - |
| 52 | + configChangeContentBuilder.deleteItem(createdItemFalseCheck); |
46 | 53 | configString = configChangeContentBuilder.build(); |
47 | 54 | } |
48 | 55 |
|
49 | 56 | @Test |
50 | 57 | public void testHasContent() { |
51 | 58 | assertTrue(configChangeContentBuilder.hasContent()); |
| 59 | + configChangeContentBuilder.getCreateItems().clear(); |
| 60 | + assertTrue(configChangeContentBuilder.hasContent()); |
| 61 | + configChangeContentBuilder.getUpdateItems().clear(); |
| 62 | + assertTrue(configChangeContentBuilder.hasContent()); |
52 | 63 | } |
53 | 64 |
|
54 | 65 | @Test |
55 | | - public void testConvertJsonString() { |
56 | | - ConfigChangeContentBuilder contentBuilder = ConfigChangeContentBuilder |
57 | | - .convertJsonString(configString); |
| 66 | + public void testHasContentFalseCheck() { |
| 67 | + configChangeContentBuilder.getCreateItems().clear(); |
| 68 | + configChangeContentBuilder.getUpdateItems().clear(); |
| 69 | + configChangeContentBuilder.getDeleteItems().clear(); |
| 70 | + assertFalse(configChangeContentBuilder.hasContent()); |
| 71 | + } |
58 | 72 |
|
| 73 | + @Test |
| 74 | + public void testConvertJsonString() { |
| 75 | + ConfigChangeContentBuilder contentBuilder = |
| 76 | + ConfigChangeContentBuilder.convertJsonString(configString); |
59 | 77 | assertNotNull(contentBuilder.getCreateItems()); |
60 | 78 | assertNotNull(contentBuilder.getUpdateItems().get(0).oldItem); |
61 | 79 | assertNotNull(contentBuilder.getUpdateItems().get(0).newItem); |
|
0 commit comments