Skip to content

Commit 9082384

Browse files
fix junit replace org.junit.Assert. by org.junit.jupiter.api.Assertions with springboot4.0.1
1 parent 6ff1aaa commit 9082384

File tree

107 files changed

+957
-896
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+957
-896
lines changed

apollo-client-config-data/src/test/java/com/ctrip/framework/apollo/config/data/extension/initialize/ApolloClientPropertiesFactoryTest.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import java.io.IOException;
2222
import java.util.LinkedHashMap;
2323
import java.util.Map;
24-
import org.junit.Assert;
24+
import org.junit.jupiter.api.Assertions;
2525
import org.junit.jupiter.api.Test;
2626
import org.springframework.boot.context.properties.bind.Binder;
2727
import org.springframework.boot.context.properties.source.MapConfigurationPropertySource;
@@ -31,19 +31,19 @@
3131
*/
3232
public class ApolloClientPropertiesFactoryTest {
3333

34-
@Test
35-
public void testCreateApolloClientProperties() throws IOException {
36-
Map<String, String> map = new LinkedHashMap<>();
37-
map.put("apollo.client.extension.enabled", "true");
38-
map.put("apollo.client.extension.messaging-type", "long_polling");
39-
MapConfigurationPropertySource propertySource = new MapConfigurationPropertySource(map);
40-
Binder binder = new Binder(propertySource);
41-
ApolloClientPropertiesFactory factory = new ApolloClientPropertiesFactory();
42-
ApolloClientProperties apolloClientProperties = factory
43-
.createApolloClientProperties(binder, null);
34+
@Test
35+
public void testCreateApolloClientProperties() throws IOException {
36+
Map<String, String> map = new LinkedHashMap<>();
37+
map.put("apollo.client.extension.enabled", "true");
38+
map.put("apollo.client.extension.messaging-type", "long_polling");
39+
MapConfigurationPropertySource propertySource = new MapConfigurationPropertySource(map);
40+
Binder binder = new Binder(propertySource);
41+
ApolloClientPropertiesFactory factory = new ApolloClientPropertiesFactory();
42+
ApolloClientProperties apolloClientProperties = factory
43+
.createApolloClientProperties(binder, null);
4444

45-
Assert.assertEquals(apolloClientProperties.getExtension().getEnabled(), true);
46-
Assert.assertEquals(apolloClientProperties.getExtension().getMessagingType(),
47-
ApolloClientMessagingType.LONG_POLLING);
48-
}
45+
Assertions.assertEquals(apolloClientProperties.getExtension().getEnabled(), true);
46+
Assertions.assertEquals(apolloClientProperties.getExtension().getMessagingType(),
47+
ApolloClientMessagingType.LONG_POLLING);
48+
}
4949
}

apollo-client-config-data/src/test/java/com/ctrip/framework/apollo/config/data/importer/PureApolloConfigTest.java

Lines changed: 56 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import com.ctrip.framework.apollo.spi.DefaultConfigFactory;
2525
import com.github.stefanbirkner.systemlambda.SystemLambda;
2626
import org.junit.jupiter.api.AfterEach;
27-
import org.junit.Assert;
27+
import org.junit.jupiter.api.Assertions;
2828
import org.junit.jupiter.api.BeforeEach;
2929
import org.junit.jupiter.api.Test;
3030

@@ -33,63 +33,64 @@
3333
*/
3434
public class PureApolloConfigTest {
3535

36-
@BeforeEach
37-
public void before() {
38-
System.setProperty("env", "local");
39-
}
36+
@BeforeEach
37+
public void before() {
38+
System.setProperty("env", "local");
39+
}
4040

41-
@AfterEach
42-
public void after() {
43-
System.clearProperty("spring.profiles.active");
44-
System.clearProperty("env");
45-
ApolloMockInjectorCustomizer.clear();
46-
}
41+
@AfterEach
42+
public void after() {
43+
System.clearProperty("spring.profiles.active");
44+
System.clearProperty("env");
45+
ApolloMockInjectorCustomizer.clear();
46+
}
4747

48-
@Test
49-
public void testDefaultConfigWithSystemProperties() {
50-
System.setProperty("spring.profiles.active", "test");
51-
ApolloMockInjectorCustomizer.register(ConfigFactory.class,
52-
DefaultConfigFactory::new);
53-
ConfigFactory configFactory = ApolloInjector.getInstance(ConfigFactory.class);
54-
Config config = configFactory.create("application");
55-
Assert.assertEquals("test", config.getProperty("spring.profiles.active", null));
56-
}
48+
@Test
49+
public void testDefaultConfigWithSystemProperties() {
50+
System.setProperty("spring.profiles.active", "test");
51+
ApolloMockInjectorCustomizer.register(ConfigFactory.class,
52+
DefaultConfigFactory::new);
53+
ConfigFactory configFactory = ApolloInjector.getInstance(ConfigFactory.class);
54+
Config config = configFactory.create("application");
55+
Assertions.assertEquals("test", config.getProperty("spring.profiles.active", null));
56+
}
5757

58-
@Test
59-
public void testPureApolloConfigWithSystemProperties() {
60-
System.setProperty("spring.profiles.active", "test");
61-
ApolloMockInjectorCustomizer.register(ConfigFactory.class,
62-
PureApolloConfigFactory::new);
63-
ConfigFactory configFactory = ApolloInjector.getInstance(ConfigFactory.class);
64-
Config config = configFactory.create("application");
65-
Assert.assertNull(config.getProperty("spring.profiles.active", null));
66-
}
58+
@Test
59+
public void testPureApolloConfigWithSystemProperties() {
60+
System.setProperty("spring.profiles.active", "test");
61+
ApolloMockInjectorCustomizer.register(ConfigFactory.class,
62+
PureApolloConfigFactory::new);
63+
ConfigFactory configFactory = ApolloInjector.getInstance(ConfigFactory.class);
64+
Config config = configFactory.create("application");
65+
Assertions.assertNull(config.getProperty("spring.profiles.active", null));
66+
}
6767

68-
@Test
69-
public void testDefaultConfigWithEnvironmentVariables() throws Exception {
70-
SystemLambda.withEnvironmentVariable(
71-
"SPRING_PROFILES_ACTIVE",
72-
"test-env")
73-
.execute(() -> {
74-
ApolloMockInjectorCustomizer.register(ConfigFactory.class,
75-
DefaultConfigFactory::new);
76-
ConfigFactory configFactory = ApolloInjector.getInstance(ConfigFactory.class);
77-
Config config = configFactory.create("application");
78-
Assert.assertEquals("test-env", config.getProperty("SPRING_PROFILES_ACTIVE", null));
79-
});
80-
}
68+
@Test
69+
public void testDefaultConfigWithEnvironmentVariables() throws Exception {
70+
SystemLambda.withEnvironmentVariable(
71+
"SPRING_PROFILES_ACTIVE",
72+
"test-env")
73+
.execute(() -> {
74+
ApolloMockInjectorCustomizer.register(ConfigFactory.class,
75+
DefaultConfigFactory::new);
76+
ConfigFactory configFactory = ApolloInjector.getInstance(ConfigFactory.class);
77+
Config config = configFactory.create("application");
78+
Assertions.assertEquals("test-env",
79+
config.getProperty("SPRING_PROFILES_ACTIVE", null));
80+
});
81+
}
8182

82-
@Test
83-
public void testPureApolloConfigWithEnvironmentVariables() throws Exception {
84-
SystemLambda.withEnvironmentVariable(
85-
"SPRING_PROFILES_ACTIVE",
86-
"test-env")
87-
.execute(() -> {
88-
ApolloMockInjectorCustomizer.register(ConfigFactory.class,
89-
PureApolloConfigFactory::new);
90-
ConfigFactory configFactory = ApolloInjector.getInstance(ConfigFactory.class);
91-
Config config = configFactory.create("application");
92-
Assert.assertNull(config.getProperty("SPRING_PROFILES_ACTIVE", null));
93-
});
94-
}
83+
@Test
84+
public void testPureApolloConfigWithEnvironmentVariables() throws Exception {
85+
SystemLambda.withEnvironmentVariable(
86+
"SPRING_PROFILES_ACTIVE",
87+
"test-env")
88+
.execute(() -> {
89+
ApolloMockInjectorCustomizer.register(ConfigFactory.class,
90+
PureApolloConfigFactory::new);
91+
ConfigFactory configFactory = ApolloInjector.getInstance(ConfigFactory.class);
92+
Config config = configFactory.create("application");
93+
Assertions.assertNull(config.getProperty("SPRING_PROFILES_ACTIVE", null));
94+
});
95+
}
9596
}

apollo-client-config-data/src/test/java/com/ctrip/framework/apollo/config/data/system/ApolloClientApplicationPropertiesCompatibleTest.java

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,14 @@
1919
import com.ctrip.framework.apollo.core.ApolloClientSystemConsts;
2020
import com.ctrip.framework.apollo.spring.boot.ApolloApplicationContextInitializer;
2121
import org.junit.jupiter.api.AfterEach;
22-
import org.junit.Assert;
22+
import org.junit.jupiter.api.Assertions;
2323
import org.junit.jupiter.api.Test;
2424
import org.junit.jupiter.api.extension.ExtendWith;
25-
import org.junit.runner.RunWith;
2625
import org.springframework.beans.factory.annotation.Autowired;
2726
import org.springframework.boot.test.context.SpringBootTest;
2827
import org.springframework.core.env.ConfigurableEnvironment;
2928
import org.springframework.test.context.ActiveProfiles;
3029
import org.springframework.test.context.junit.jupiter.SpringExtension;
31-
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
3230

3331
/**
3432
* @author vdisk <vdisk@foxmail.com>
@@ -39,23 +37,23 @@
3937
@ActiveProfiles("test-compatible")
4038
public class ApolloClientApplicationPropertiesCompatibleTest {
4139

42-
@Autowired
43-
private ConfigurableEnvironment environment;
40+
@Autowired
41+
private ConfigurableEnvironment environment;
4442

45-
@Test
46-
public void testApplicationPropertiesCompatible() {
47-
Assert.assertEquals("test-1/cacheDir",
48-
this.environment.getProperty(ApolloClientSystemConsts.APOLLO_CACHE_DIR));
49-
Assert.assertEquals("test-1-secret",
50-
this.environment.getProperty(ApolloClientSystemConsts.APOLLO_ACCESS_KEY_SECRET));
51-
Assert.assertEquals("https://test-1-config-service",
52-
this.environment.getProperty(ApolloClientSystemConsts.APOLLO_CONFIG_SERVICE));
53-
}
43+
@Test
44+
public void testApplicationPropertiesCompatible() {
45+
Assertions.assertEquals("test-1/cacheDir",
46+
this.environment.getProperty(ApolloClientSystemConsts.APOLLO_CACHE_DIR));
47+
Assertions.assertEquals("test-1-secret",
48+
this.environment.getProperty(ApolloClientSystemConsts.APOLLO_ACCESS_KEY_SECRET));
49+
Assertions.assertEquals("https://test-1-config-service",
50+
this.environment.getProperty(ApolloClientSystemConsts.APOLLO_CONFIG_SERVICE));
51+
}
5452

55-
@AfterEach
56-
public void clearProperty() {
57-
for (String propertyName : ApolloApplicationContextInitializer.APOLLO_SYSTEM_PROPERTIES) {
58-
System.clearProperty(propertyName);
53+
@AfterEach
54+
public void clearProperty() {
55+
for (String propertyName : ApolloApplicationContextInitializer.APOLLO_SYSTEM_PROPERTIES) {
56+
System.clearProperty(propertyName);
57+
}
5958
}
60-
}
6159
}

apollo-client-config-data/src/test/java/com/ctrip/framework/apollo/config/data/system/ApolloClientEnvironmentVariablesCompatibleTest.java

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

1919
import com.ctrip.framework.apollo.core.ApolloClientSystemConsts;
2020
import com.ctrip.framework.apollo.spring.boot.ApolloApplicationContextInitializer;
21-
import com.github.stefanbirkner.systemlambda.SystemLambda;
2221
import org.junit.jupiter.api.AfterEach;
23-
import org.junit.Assert;
2422
import org.junit.jupiter.api.Assertions;
2523
import org.junit.jupiter.api.Test;
26-
import org.junit.jupiter.api.extension.ExtendWith;
2724
import org.springframework.beans.factory.annotation.Autowired;
2825
import org.springframework.boot.test.context.SpringBootTest;
2926
import org.springframework.core.env.ConfigurableEnvironment;
3027
import org.springframework.test.context.DynamicPropertyRegistry;
3128
import org.springframework.test.context.DynamicPropertySource;
32-
import org.springframework.test.context.junit.jupiter.SpringExtension;
3329

3430
/**
3531
* @author vdisk <vdisk@foxmail.com>
@@ -71,11 +67,11 @@ public void testEnvironmentVariablesCompatible() throws Exception {
7167
// .and(ApolloClientSystemConsts.DEPRECATED_APOLLO_CONFIG_SERVICE_ENVIRONMENT_VARIABLES,
7268
// "https://test-2-config-service")
7369
// .execute(() -> {
74-
// Assert.assertEquals("test-2/cacheDir",
70+
// assertEquals("test-2/cacheDir",
7571
// this.environment.getProperty(ApolloClientSystemConsts.APOLLO_CACHE_DIR));
76-
// Assert.assertEquals("test-2-secret",
72+
// assertEquals("test-2-secret",
7773
// this.environment.getProperty(ApolloClientSystemConsts.APOLLO_ACCESS_KEY_SECRET));
78-
// Assert.assertEquals("https://test-2-config-service",
74+
// assertEquals("https://test-2-config-service",
7975
// this.environment.getProperty(ApolloClientSystemConsts.APOLLO_CONFIG_SERVICE));
8076
// });
8177
Assertions.assertEquals(

apollo-client-config-data/src/test/java/com/ctrip/framework/apollo/config/data/system/ApolloClientSystemPropertiesCompatibleTest.java

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,13 @@
1919
import com.ctrip.framework.apollo.core.ApolloClientSystemConsts;
2020
import com.ctrip.framework.apollo.spring.boot.ApolloApplicationContextInitializer;
2121
import org.junit.jupiter.api.AfterEach;
22-
import org.junit.Assert;
22+
import org.junit.jupiter.api.Assertions;
2323
import org.junit.jupiter.api.Test;
2424
import org.junit.jupiter.api.extension.ExtendWith;
25-
import org.junit.runner.RunWith;
2625
import org.springframework.beans.factory.annotation.Autowired;
2726
import org.springframework.boot.test.context.SpringBootTest;
2827
import org.springframework.core.env.ConfigurableEnvironment;
2928
import org.springframework.test.context.junit.jupiter.SpringExtension;
30-
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
3129

3230
/**
3331
* @author vdisk <vdisk@foxmail.com>
@@ -37,33 +35,34 @@
3735
webEnvironment = SpringBootTest.WebEnvironment.NONE)
3836
public class ApolloClientSystemPropertiesCompatibleTest {
3937

40-
@Autowired
41-
private ConfigurableEnvironment environment;
38+
@Autowired
39+
private ConfigurableEnvironment environment;
4240

43-
@Test
44-
public void testSystemPropertiesCompatible() {
45-
System.setProperty(ApolloClientSystemConsts.DEPRECATED_APOLLO_CACHE_DIR, "test-3/cacheDir");
46-
System
47-
.setProperty(ApolloClientSystemConsts.DEPRECATED_APOLLO_ACCESS_KEY_SECRET, "test-3-secret");
48-
System.setProperty(ApolloClientSystemConsts.DEPRECATED_APOLLO_CONFIG_SERVICE,
49-
"https://test-3-config-service");
41+
@Test
42+
public void testSystemPropertiesCompatible() {
43+
System.setProperty(ApolloClientSystemConsts.DEPRECATED_APOLLO_CACHE_DIR, "test-3/cacheDir");
44+
System
45+
.setProperty(ApolloClientSystemConsts.DEPRECATED_APOLLO_ACCESS_KEY_SECRET,
46+
"test-3-secret");
47+
System.setProperty(ApolloClientSystemConsts.DEPRECATED_APOLLO_CONFIG_SERVICE,
48+
"https://test-3-config-service");
5049

51-
Assert.assertEquals("test-3/cacheDir",
52-
this.environment.getProperty(ApolloClientSystemConsts.APOLLO_CACHE_DIR));
53-
Assert.assertEquals("test-3-secret",
54-
this.environment.getProperty(ApolloClientSystemConsts.APOLLO_ACCESS_KEY_SECRET));
55-
Assert.assertEquals("https://test-3-config-service",
56-
this.environment.getProperty(ApolloClientSystemConsts.APOLLO_CONFIG_SERVICE));
50+
Assertions.assertEquals("test-3/cacheDir",
51+
this.environment.getProperty(ApolloClientSystemConsts.APOLLO_CACHE_DIR));
52+
Assertions.assertEquals("test-3-secret",
53+
this.environment.getProperty(ApolloClientSystemConsts.APOLLO_ACCESS_KEY_SECRET));
54+
Assertions.assertEquals("https://test-3-config-service",
55+
this.environment.getProperty(ApolloClientSystemConsts.APOLLO_CONFIG_SERVICE));
5756

58-
System.clearProperty(ApolloClientSystemConsts.DEPRECATED_APOLLO_CACHE_DIR);
59-
System.clearProperty(ApolloClientSystemConsts.DEPRECATED_APOLLO_ACCESS_KEY_SECRET);
60-
System.clearProperty(ApolloClientSystemConsts.DEPRECATED_APOLLO_CONFIG_SERVICE);
61-
}
57+
System.clearProperty(ApolloClientSystemConsts.DEPRECATED_APOLLO_CACHE_DIR);
58+
System.clearProperty(ApolloClientSystemConsts.DEPRECATED_APOLLO_ACCESS_KEY_SECRET);
59+
System.clearProperty(ApolloClientSystemConsts.DEPRECATED_APOLLO_CONFIG_SERVICE);
60+
}
6261

63-
@AfterEach
64-
public void clearProperty() {
65-
for (String propertyName : ApolloApplicationContextInitializer.APOLLO_SYSTEM_PROPERTIES) {
66-
System.clearProperty(propertyName);
62+
@AfterEach
63+
public void clearProperty() {
64+
for (String propertyName : ApolloApplicationContextInitializer.APOLLO_SYSTEM_PROPERTIES) {
65+
System.clearProperty(propertyName);
66+
}
6767
}
68-
}
6968
}

0 commit comments

Comments
 (0)