Skip to content

Commit c828d29

Browse files
committed
more
Signed-off-by: wind57 <[email protected]>
1 parent 21d2c61 commit c828d29

File tree

17 files changed

+240
-250
lines changed

17 files changed

+240
-250
lines changed

spring-cloud-kubernetes-commons/src/test/java/org/springframework/cloud/kubernetes/commons/config/ConfigUtilsProcessSourceTests.java

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import java.util.List;
2121
import java.util.Map;
2222

23-
import org.junit.jupiter.api.Assertions;
23+
import org.assertj.core.api.Assertions;
2424
import org.junit.jupiter.api.Test;
2525
import org.junit.jupiter.api.extension.ExtendWith;
2626

@@ -58,7 +58,7 @@ void testProcessSourceOne() {
5858
Map<String, String> sourceRawData = Map.of();
5959

6060
boolean result = ConfigUtils.processSource(includeDefaultProfileData, environment, sourceName, sourceRawData);
61-
Assertions.assertTrue(result);
61+
Assertions.assertThat(result).isTrue();
6262
}
6363

6464
/**
@@ -79,9 +79,9 @@ void testProcessNamedDataOne() {
7979

8080
MultipleSourcesContainer result = ConfigUtils.processNamedData(strippedSources, environment, sourceNames,
8181
namespace, decode, includeDefaultProfileData);
82-
Assertions.assertNotNull(result);
83-
Assertions.assertEquals(result.names().toString(), "[configmap-a]");
84-
Assertions.assertEquals(result.data(), Map.of("one", "1"));
82+
Assertions.assertThat(result).isNotNull();
83+
Assertions.assertThat(result.names()).containsExactlyInAnyOrder("configmap-a");
84+
Assertions.assertThat(result.data()).containsExactlyInAnyOrderEntriesOf(Map.of("one", "1"));
8585
}
8686

8787
/**
@@ -104,7 +104,7 @@ void testProcessSourceTwo() {
104104
Map<String, String> sourceRawData = Map.of();
105105

106106
boolean result = ConfigUtils.processSource(includeDefaultProfileData, environment, sourceName, sourceRawData);
107-
Assertions.assertTrue(result);
107+
Assertions.assertThat(result).isTrue();
108108
}
109109

110110
/**
@@ -158,8 +158,8 @@ void testProcessNamedDataTwo(CapturedOutput output) {
158158

159159
MultipleSourcesContainer result = ConfigUtils.processNamedData(strippedSources, environment, sourceNames,
160160
namespace, decode, includeDefaultProfileData);
161-
Assertions.assertNotNull(result);
162-
Assertions.assertEquals(result.names().toString(), "[account]");
161+
Assertions.assertThat(result).isNotNull();
162+
Assertions.assertThat(result.names()).containsExactlyInAnyOrder("account");
163163

164164
/**
165165
* <pre>
@@ -173,8 +173,8 @@ void testProcessNamedDataTwo(CapturedOutput output) {
173173
* since 'k8s' is not an active profile.
174174
* </pre>
175175
*/
176-
Assertions.assertEquals(result.data(), Map.of("one", "1", "two", "2", "three", "3", "five", "5"));
177-
Assertions.assertTrue(output.getOut().contains("entry : account-k8s.properties will be skipped"));
176+
Assertions.assertThat(result.data()).containsExactlyInAnyOrderEntriesOf(Map.of("one", "1", "two", "2", "three", "3", "five", "5"));
177+
Assertions.assertThat(output.getOut()).contains("entry : account-k8s.properties will be skipped");
178178
}
179179

180180
/**
@@ -197,7 +197,7 @@ void testProcessSourceThree() {
197197
Map<String, String> sourceRawData = Map.of();
198198

199199
boolean result = ConfigUtils.processSource(includeDefaultProfileData, environment, sourceName, sourceRawData);
200-
Assertions.assertTrue(result);
200+
Assertions.assertThat(result).isTrue();
201201
}
202202

203203
/**
@@ -251,8 +251,8 @@ void testProcessNamedDataThree(CapturedOutput output) {
251251

252252
MultipleSourcesContainer result = ConfigUtils.processNamedData(strippedSources, environment, sourceNames,
253253
namespace, decode, includeDefaultProfileData);
254-
Assertions.assertNotNull(result);
255-
Assertions.assertEquals(result.names().toString(), "[account-default]");
254+
Assertions.assertThat(result).isNotNull();
255+
Assertions.assertThat(result.names()).containsExactlyInAnyOrder("account-default");
256256

257257
/**
258258
* <pre>
@@ -268,8 +268,8 @@ void testProcessNamedDataThree(CapturedOutput output) {
268268
* 6. we do not have 'four=4' since we do not read 'account-k8s.properties'
269269
* </pre>
270270
*/
271-
Assertions.assertEquals(result.data(), Map.of("one", "1", "two", "2", "three", "3", "five", "5"));
272-
Assertions.assertTrue(output.getOut().contains("entry : account-k8s.properties will be skipped"));
271+
Assertions.assertThat(result.data()).containsExactlyInAnyOrderEntriesOf(Map.of("one", "1", "two", "2", "three", "3", "five", "5"));
272+
Assertions.assertThat(output.getOut()).contains("entry : account-k8s.properties will be skipped");
273273

274274
}
275275

@@ -292,7 +292,7 @@ void testProcessSourceFour() {
292292
Map<String, String> sourceRawData = Map.of("one", "1");
293293

294294
boolean result = ConfigUtils.processSource(includeDefaultProfileData, environment, sourceName, sourceRawData);
295-
Assertions.assertFalse(result);
295+
Assertions.assertThat(result).isFalse();
296296
}
297297

298298
/**
@@ -314,7 +314,7 @@ void testProcessSourceFive() {
314314
Map<String, String> sourceRawData = Map.of("one", "1", "account-k8s.properties", "one=11");
315315

316316
boolean result = ConfigUtils.processSource(includeDefaultProfileData, environment, sourceName, sourceRawData);
317-
Assertions.assertTrue(result);
317+
Assertions.assertThat(result).isTrue();
318318
}
319319

320320
/**
@@ -363,17 +363,17 @@ void testProcessNamedDataFive(CapturedOutput output) {
363363

364364
MultipleSourcesContainer result = ConfigUtils.processNamedData(strippedSources, environment, sourceNames,
365365
namespace, decode, includeDefaultProfileData);
366-
Assertions.assertNotNull(result);
367-
Assertions.assertEquals(result.names().toString(), "[account]");
366+
Assertions.assertThat(result).isNotNull();
367+
Assertions.assertThat(result.names()).containsExactlyInAnyOrder("account");
368368

369369
/**
370370
* <pre>
371371
* - we only read from 'account-k8s.properties'
372372
* </pre>
373373
*/
374-
Assertions.assertEquals(result.data(), Map.of("one", "1111", "four", "4"));
375-
Assertions.assertTrue(output.getOut().contains("entry : account.properties will be skipped"));
376-
Assertions.assertTrue(output.getOut().contains("entry : account-default.properties will be skipped"));
374+
Assertions.assertThat(result.data()).containsExactlyInAnyOrderEntriesOf(Map.of("one", "1111", "four", "4"));
375+
Assertions.assertThat(output.getOut()).contains("entry : account.properties will be skipped");
376+
Assertions.assertThat(output.getOut()).contains("entry : account-default.properties will be skipped");
377377

378378
}
379379

@@ -396,7 +396,7 @@ void testProcessSourceSix() {
396396
Map<String, String> sourceRawData = Map.of("one", "1", "account-k8s.properties", "one=11");
397397

398398
boolean result = ConfigUtils.processSource(includeDefaultProfileData, environment, sourceName, sourceRawData);
399-
Assertions.assertTrue(result);
399+
Assertions.assertThat(result).isTrue();
400400
}
401401

402402
/**
@@ -451,8 +451,8 @@ void testProcessNamedDataSix(CapturedOutput output) {
451451

452452
MultipleSourcesContainer result = ConfigUtils.processNamedData(strippedSources, environment, sourceNames,
453453
namespace, decode, includeDefaultProfileData);
454-
Assertions.assertNotNull(result);
455-
Assertions.assertEquals(result.names().toString(), "[account-k8s]");
454+
Assertions.assertThat(result).isNotNull();
455+
Assertions.assertThat(result.names()).containsExactlyInAnyOrder("account-k8s");
456456

457457
/**
458458
* <pre>
@@ -471,10 +471,10 @@ void testProcessNamedDataSix(CapturedOutput output) {
471471
* (because 'prod' is not an active profile)
472472
* </pre>
473473
*/
474-
Assertions.assertEquals(result.data(), Map.of("one", "1111", "five", "5"));
475-
Assertions.assertTrue(output.getOut().contains("entry : account-prod.properties will be skipped"));
476-
Assertions.assertTrue(output.getOut().contains("entry : account.properties will be skipped"));
477-
Assertions.assertTrue(output.getOut().contains("entry : account-default.properties will be skipped"));
474+
Assertions.assertThat(result.data()).containsExactlyInAnyOrderEntriesOf(Map.of("one", "1111", "five", "5"));
475+
Assertions.assertThat(output.getOut()).contains("entry : account-prod.properties will be skipped");
476+
Assertions.assertThat(output.getOut()).contains("entry : account.properties will be skipped");
477+
Assertions.assertThat(output.getOut()).contains("entry : account-default.properties will be skipped");
478478

479479
}
480480

spring-cloud-kubernetes-commons/src/test/java/org/springframework/cloud/kubernetes/commons/config/SourceDataEntriesProcessorOrderedPropertiesTests.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import java.util.LinkedHashMap;
2020
import java.util.Map;
2121

22-
import org.junit.jupiter.api.Assertions;
22+
import org.assertj.core.api.Assertions;
2323
import org.junit.jupiter.api.Test;
2424

2525
import org.springframework.mock.env.MockEnvironment;
@@ -42,7 +42,7 @@ void testSingleNonFileProperty() {
4242
MockEnvironment mockEnvironment = new MockEnvironment();
4343
Map<String, Object> result = SourceDataEntriesProcessor.processAllEntries(map, mockEnvironment);
4444

45-
Assertions.assertEquals(Map.of("my-key", "my-value"), result);
45+
Assertions.assertThat(result).containsExactlyInAnyOrderEntriesOf(Map.of("my-key", "my-value"));
4646
}
4747

4848
/**
@@ -58,7 +58,7 @@ void testSingleFileProperty() {
5858
MockEnvironment mockEnvironment = new MockEnvironment();
5959
Map<String, Object> result = SourceDataEntriesProcessor.processAllEntries(map, mockEnvironment);
6060

61-
Assertions.assertEquals(Map.of("my-key", "from-app"), result);
61+
Assertions.assertThat(result).containsExactlyInAnyOrderEntriesOf(Map.of("my-key", "from-app"));
6262
}
6363

6464
/**
@@ -86,7 +86,8 @@ void testThree() {
8686
MockEnvironment mockEnvironment = new MockEnvironment();
8787
Map<String, Object> result = SourceDataEntriesProcessor.processAllEntries(map, mockEnvironment);
8888

89-
Assertions.assertEquals(Map.of("firstKey", "abc", "secondKey", "secondFromProperties"), result);
89+
Assertions.assertThat(result).containsExactlyInAnyOrderEntriesOf(
90+
Map.of("firstKey", "abc", "secondKey", "secondFromProperties"));
9091
}
9192

9293
/**
@@ -127,9 +128,8 @@ void testFour() {
127128
mockEnvironment.setActiveProfiles("dev");
128129
Map<String, Object> result = SourceDataEntriesProcessor.processAllEntries(map, mockEnvironment);
129130

130-
Assertions.assertEquals(
131-
Map.of("firstKey", "abc", "secondKey", "secondFromDevProperties", "thirdKey", "thirdFromProperties"),
132-
result);
131+
Assertions.assertThat(result).containsExactlyInAnyOrderEntriesOf(
132+
Map.of("firstKey", "abc", "secondKey", "secondFromDevProperties", "thirdKey", "thirdFromProperties"));
133133
}
134134

135135
/**
@@ -175,8 +175,9 @@ void testFive() {
175175
mockEnvironment.setActiveProfiles("dev");
176176
Map<String, Object> result = SourceDataEntriesProcessor.processAllEntries(map, mockEnvironment);
177177

178-
Assertions.assertEquals(Map.of("firstKey", "abc", "secondKey", "secondFromDevProperties", "thirdKey",
179-
"thirdFromProperties", "fourthKey", "def"), result);
178+
Assertions.assertThat(result).containsExactlyInAnyOrderEntriesOf(
179+
Map.of("firstKey", "abc", "secondKey", "secondFromDevProperties", "thirdKey",
180+
"thirdFromProperties", "fourthKey", "def"));
180181
}
181182

182183
}

spring-cloud-kubernetes-commons/src/test/java/org/springframework/cloud/kubernetes/commons/config/SourceDataEntriesProcessorTests.java

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import java.util.Map;
2020

21-
import org.junit.jupiter.api.Assertions;
21+
import org.assertj.core.api.Assertions;
2222
import org.junit.jupiter.api.Test;
2323

2424
import org.springframework.mock.env.MockEnvironment;
@@ -34,8 +34,7 @@ void testSingleYml() {
3434
Map<String, Object> result = SourceDataEntriesProcessor.processAllEntries(Map.of("one.yml", "key: \n value"),
3535
new MockEnvironment());
3636

37-
Assertions.assertEquals(1, result.size());
38-
Assertions.assertEquals("value", result.get("key"));
37+
Assertions.assertThat(result).containsExactlyInAnyOrderEntriesOf(Map.of("key", "value"));
3938
}
4039

4140
@Test
@@ -44,8 +43,7 @@ void testSingleYaml() {
4443
Map<String, Object> result = SourceDataEntriesProcessor.processAllEntries(Map.of("one.yaml", "key: \n value"),
4544
new MockEnvironment());
4645

47-
Assertions.assertEquals(1, result.size());
48-
Assertions.assertEquals("value", result.get("key"));
46+
Assertions.assertThat(result).containsExactlyInAnyOrderEntriesOf(Map.of("key", "value"));
4947
}
5048

5149
@Test
@@ -54,8 +52,7 @@ void testSingleProperties() {
5452
Map<String, Object> result = SourceDataEntriesProcessor.processAllEntries(Map.of("one.properties", "key=value"),
5553
new MockEnvironment());
5654

57-
Assertions.assertEquals(1, result.size());
58-
Assertions.assertEquals("value", result.get("key"));
55+
Assertions.assertThat(result).containsExactlyInAnyOrderEntriesOf(Map.of("key", "value"));;
5956
}
6057

6158
/**
@@ -72,9 +69,7 @@ void twoEntriesNoneFileTreated() {
7269

7370
Map<String, Object> result = SourceDataEntriesProcessor.processAllEntries(map, new MockEnvironment());
7471

75-
Assertions.assertEquals(2, result.size());
76-
Assertions.assertEquals("1", result.get("one"));
77-
Assertions.assertEquals("2", result.get("two"));
72+
Assertions.assertThat(result).containsExactlyInAnyOrderEntriesOf(Map.of("one", "1", "two", "2"));
7873
}
7974

8075
/**
@@ -92,8 +87,7 @@ void twoEntriesOneIsYamlButNotTaken() {
9287

9388
Map<String, Object> result = SourceDataEntriesProcessor.processAllEntries(map, new MockEnvironment());
9489

95-
Assertions.assertEquals(1, result.size());
96-
Assertions.assertEquals("1", result.get("one"));
90+
Assertions.assertThat(result).containsExactlyInAnyOrderEntriesOf(Map.of("one", "1"));
9791
}
9892

9993
/**
@@ -111,9 +105,7 @@ void twoEntriesBothTaken() {
111105

112106
Map<String, Object> result = SourceDataEntriesProcessor.processAllEntries(map, new MockEnvironment());
113107

114-
Assertions.assertEquals(2, result.size());
115-
Assertions.assertEquals("1", result.get("one"));
116-
Assertions.assertEquals("blue", result.get("color"));
108+
Assertions.assertThat(result).containsExactlyInAnyOrderEntriesOf(Map.of("one", "1", "color", "blue"));
117109
}
118110

119111
/**
@@ -135,10 +127,7 @@ void threeEntriesAllTaken() {
135127
env.setActiveProfiles("dev");
136128
Map<String, Object> result = SourceDataEntriesProcessor.processAllEntries(map, env);
137129

138-
Assertions.assertEquals(3, result.size());
139-
Assertions.assertEquals("1", result.get("one"));
140-
Assertions.assertEquals("blue", result.get("color"));
141-
Assertions.assertEquals("sport", result.get("fit"));
130+
Assertions.assertThat(result).containsExactlyInAnyOrderEntriesOf(Map.of("one", "1", "color", "blue", "fit", "sport"));
142131
}
143132

144133
/**
@@ -164,11 +153,7 @@ void fiveEntriesFourTaken() {
164153
env.setActiveProfiles("fit", "color");
165154
Map<String, Object> result = SourceDataEntriesProcessor.processAllEntries(map, env);
166155

167-
Assertions.assertEquals(4, result.size());
168-
Assertions.assertEquals("1", result.get("one"));
169-
Assertions.assertEquals("jacket", result.get("name"));
170-
Assertions.assertEquals("sport", result.get("fit"));
171-
Assertions.assertEquals("black", result.get("color"));
156+
Assertions.assertThat(result).containsExactlyInAnyOrderEntriesOf(Map.of("one", "1", "name", "jacket", "color", "black", "fit", "sport"));
172157
}
173158

174159
}

spring-cloud-kubernetes-commons/src/test/java/org/springframework/cloud/kubernetes/commons/config/reload/ConfigReloadUtilTests.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import java.util.List;
2323
import java.util.Map;
2424

25-
import org.junit.jupiter.api.Assertions;
25+
import org.assertj.core.api.Assertions;
2626
import org.junit.jupiter.api.Test;
2727

2828
import org.springframework.cloud.bootstrap.config.BootstrapPropertySource;
@@ -143,11 +143,11 @@ public Object getProperty(String name) {
143143

144144
List<? extends PropertySource> result = ConfigReloadUtil.findPropertySources(PlainPropertySource.class,
145145
environment);
146-
Assertions.assertEquals(4, result.size());
147-
Assertions.assertEquals("b", result.get(0).getProperty("a"));
148-
Assertions.assertEquals("plain", result.get(1).getProperty(""));
149-
Assertions.assertEquals("from-bootstrap", result.get(2).getProperty(""));
150-
Assertions.assertEquals("from-inner-two-composite", result.get(3).getProperty(""));
146+
Assertions.assertThat(result.size()).isEqualTo(4);
147+
Assertions.assertThat(result.get(0).getProperty("a")).isEqualTo("b");
148+
Assertions.assertThat(result.get(1).getProperty("")).isEqualTo("plain");
149+
Assertions.assertThat(result.get(2).getProperty("")).isEqualTo("from-bootstrap");
150+
Assertions.assertThat(result.get(3).getProperty("")).isEqualTo("from-inner-two-composite");
151151
}
152152

153153
private static final class OneComposite extends CompositePropertySource {

0 commit comments

Comments
 (0)