Issue 973 - Update Unit version - spring-cloud-context (#977)

* Upgraded more JUnit test versions
This commit is contained in:
Robert McNees
2021-07-12 16:14:49 -04:00
committed by GitHub
parent d43a4acd2f
commit ea459cee64
96 changed files with 238 additions and 389 deletions

View File

@@ -20,7 +20,7 @@ import java.util.List;
import java.util.function.Function;
import org.assertj.core.util.Lists;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;

View File

@@ -18,8 +18,8 @@ package org.springframework.cloud.autoconfigure;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
@@ -27,7 +27,8 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.test.system.OutputCaptureRule;
import org.springframework.boot.test.system.CapturedOutput;
import org.springframework.boot.test.system.OutputCaptureExtension;
import org.springframework.cloud.context.refresh.ContextRefresher;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Configuration;
@@ -38,11 +39,9 @@ import static org.assertj.core.api.BDDAssertions.then;
/**
* @author Dave Syer
*/
@ExtendWith(OutputCaptureExtension.class)
public class RefreshAutoConfigurationTests {
@Rule
public OutputCaptureRule output = new OutputCaptureRule();
private static ConfigurableApplicationContext getApplicationContext(WebApplicationType type, Class<?> configuration,
String... properties) {
return new SpringApplicationBuilder(configuration).web(type).properties(properties).properties("server.port=0")
@@ -50,10 +49,10 @@ public class RefreshAutoConfigurationTests {
}
@Test
public void noWarnings() {
public void noWarnings(CapturedOutput output) {
try (ConfigurableApplicationContext context = getApplicationContext(WebApplicationType.NONE, Config.class)) {
then(context.containsBean("refreshScope")).isTrue();
then(this.output.toString()).doesNotContain("WARN");
then(output.toString()).doesNotContain("WARN");
}
}

View File

@@ -16,8 +16,7 @@
package org.springframework.cloud.bootstrap;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
@@ -25,11 +24,9 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.bootstrap.BootstrapDisabledAutoConfigurationIntegrationTests.Application;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.BDDAssertions.then;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class, properties = "spring.cloud.bootstrap.enabled:false")
public class BootstrapDisabledAutoConfigurationIntegrationTests {

View File

@@ -16,8 +16,7 @@
package org.springframework.cloud.bootstrap;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
@@ -26,11 +25,9 @@ import org.springframework.cloud.bootstrap.BootstrapOrderingAutoConfigurationInt
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.BDDAssertions.then;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class,
properties = { "encrypt.key:deadbeef", "spring.config.use-legacy-processing=true" })
@ActiveProfiles("encrypt")

View File

@@ -21,8 +21,7 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
@@ -35,12 +34,10 @@ import org.springframework.core.env.Environment;
import org.springframework.core.env.MapPropertySource;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.core.env.PropertySource;
import org.springframework.test.context.junit4.SpringRunner;
import static java.util.Collections.singletonMap;
import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class,
properties = { "spring.config.use-legacy-processing=true", "spring.cloud.bootstrap.name:ordering" })
public class BootstrapOrderingCustomOverrideSystemPropertiesIntegrationTests {

View File

@@ -20,8 +20,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
@@ -34,11 +33,9 @@ import org.springframework.core.env.Environment;
import org.springframework.core.env.MapPropertySource;
import org.springframework.core.env.PropertySource;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.BDDAssertions.then;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class, properties = { "encrypt.key:deadbeef",
"spring.cloud.bootstrap.name:custom", "spring.config.use-legacy-processing=true" })
@ActiveProfiles("encrypt")

View File

@@ -16,10 +16,9 @@
package org.springframework.cloud.bootstrap;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
@@ -27,23 +26,21 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.bootstrap.BootstrapOrderingSpringApplicationJsonIntegrationTests.Application;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.BDDAssertions.then;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class, properties = "spring.cloud.bootstrap.name:json")
public class BootstrapOrderingSpringApplicationJsonIntegrationTests {
@Autowired
private ConfigurableEnvironment environment;
@BeforeClass
@BeforeAll
public static void spikeJson() {
System.setProperty("SPRING_APPLICATION_JSON", "{\"message\":\"From JSON\"}");
}
@AfterClass
@AfterAll
public static void unspikeJson() {
System.clearProperty("SPRING_APPLICATION_JSON");
}

View File

@@ -16,19 +16,16 @@
package org.springframework.cloud.bootstrap;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.bootstrap.BootstrapOrderingSpringApplicationJsonIntegrationTests.Application;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.BDDAssertions.then;
import static org.springframework.cloud.bootstrap.TestHigherPriorityBootstrapConfiguration.firstToBeCreated;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class, properties = "spring.config.use-legacy-processing=true")
public class BootstrapSourcesOrderingTests {

View File

@@ -23,8 +23,7 @@ package org.springframework.cloud.bootstrap;
import java.util.Locale;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
@@ -32,11 +31,9 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.bootstrap.MessageSourceConfigurationTests.TestApplication;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.BDDAssertions.then;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = TestApplication.class, properties = "debug=true")
public class MessageSourceConfigurationTests {

View File

@@ -21,11 +21,10 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.junit.After;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.builder.SpringApplicationBuilder;
@@ -53,14 +52,11 @@ import static org.assertj.core.api.BDDAssertions.then;
*/
public class BootstrapConfigurationTests {
@Rule
public ExpectedException expected = ExpectedException.none();
private ConfigurableApplicationContext context;
private ConfigurableApplicationContext sibling;
@After
@AfterEach
public void close() {
// Expected.* is bound to the PropertySourceConfiguration below
System.clearProperty("expected.name");
@@ -148,9 +144,11 @@ public class BootstrapConfigurationTests {
@Test
public void failsOnPropertySource() {
System.setProperty("expected.fail", "true");
this.expected.expectMessage("Planned");
this.context = new SpringApplicationBuilder().web(WebApplicationType.NONE)
.properties("spring.config.use-legacy-processing=true").sources(BareConfiguration.class).run();
Throwable throwable = Assertions.assertThrows(RuntimeException.class, () -> {
this.context = new SpringApplicationBuilder().web(WebApplicationType.NONE)
.properties("spring.config.use-legacy-processing=true").sources(BareConfiguration.class).run();
});
then(throwable.getMessage().equals("Planned"));
}
@Test
@@ -336,7 +334,7 @@ public class BootstrapConfigurationTests {
}
@Test
@Ignore // FIXME: legacy
@Disabled // FIXME: legacy
public void differentProfileInChild() {
PropertySourceConfiguration.MAP.put("bootstrap.foo", "bar");
// Profiles are always merged with the child

View File

@@ -16,7 +16,7 @@
package org.springframework.cloud.bootstrap.config;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.ConfigurableApplicationContext;

View File

@@ -16,7 +16,7 @@
package org.springframework.cloud.bootstrap.encrypt;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.builder.SpringApplicationBuilder;

View File

@@ -16,7 +16,7 @@
package org.springframework.cloud.bootstrap.encrypt;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;

View File

@@ -18,7 +18,8 @@ package org.springframework.cloud.bootstrap.encrypt;
import java.nio.charset.Charset;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.cloud.context.encrypt.EncryptorFactory;
import org.springframework.core.io.ClassPathResource;
@@ -44,11 +45,13 @@ public class EncryptorFactoryTests {
then(encryptor.decrypt(encrypted)).isEqualTo(toEncrypt);
}
@Test(expected = RuntimeException.class)
@Test
public void testWithInvalidRsaPrivateKey() {
String key = "-----BEGIN RSA PRIVATE KEY-----\n"
+ "MIIEowIBAAKCAQEAwClFgrRa/PUHPIJr9gvIPL6g6Rjp/TVZmVNOf2fL96DYbkj5\n";
new EncryptorFactory().create(key);
Assertions.assertThrows(RuntimeException.class, () -> {
new EncryptorFactory().create(key);
});
}
}

View File

@@ -21,10 +21,11 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.boot.test.system.OutputCaptureRule;
import org.springframework.boot.test.system.CapturedOutput;
import org.springframework.boot.test.system.OutputCaptureExtension;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.boot.test.util.TestPropertyValues.Type;
import org.springframework.context.ApplicationContext;
@@ -53,14 +54,12 @@ import static org.springframework.cloud.bootstrap.encrypt.EnvironmentDecryptAppl
* @author Biju Kunjummen
* @author Tim Ysewyn
*/
@ExtendWith(OutputCaptureExtension.class)
public class EnvironmentDecryptApplicationInitializerTests {
private EnvironmentDecryptApplicationInitializer listener = new EnvironmentDecryptApplicationInitializer(
Encryptors.noOpText());
@Rule
public OutputCaptureRule outputCapture = new OutputCaptureRule();
@Test
public void decryptCipherKey() {
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext();
@@ -89,7 +88,7 @@ public class EnvironmentDecryptApplicationInitializerTests {
}
@Test
public void errorOnDecrypt() {
public void errorOnDecrypt(CapturedOutput output) {
this.listener = new EnvironmentDecryptApplicationInitializer(Encryptors.text("deadbeef", "AFFE37"));
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext();
TestPropertyValues.of("spring.cloud.bootstrap.enabled=true", "foo: {cipher}bar").applyTo(context);
@@ -101,19 +100,19 @@ public class EnvironmentDecryptApplicationInitializerTests {
then(e).isInstanceOf(IllegalStateException.class);
}
// Assert logs contain warning even when exception thrown
String sysOutput = this.outputCapture.toString();
String sysOutput = output.toString();
then(sysOutput).contains("Cannot decrypt: key=foo");
}
@Test
public void errorOnDecryptWithEmpty() {
public void errorOnDecryptWithEmpty(CapturedOutput output) {
this.listener = new EnvironmentDecryptApplicationInitializer(Encryptors.text("deadbeef", "AFFE37"));
this.listener.setFailOnError(false);
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext();
TestPropertyValues.of("spring.cloud.bootstrap.enabled=true", "foo: {cipher}bar").applyTo(context);
this.listener.initialize(context);
// Assert logs contain warning
String sysOutput = this.outputCapture.toString();
String sysOutput = output.toString();
then(sysOutput).contains("Cannot decrypt: key=foo");
// Empty is safest fallback for undecryptable cipher
then(context.getEnvironment().getProperty("foo")).isEqualTo("");

View File

@@ -24,8 +24,7 @@ import javax.servlet.ServletException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties;
@@ -40,7 +39,6 @@ import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import static org.assertj.core.api.Assertions.fail;
@@ -50,7 +48,6 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = TestConfiguration.class,
properties = { "management.endpoints.web.exposure.include=*", "management.endpoint.env.post.enabled=true" })
@AutoConfigureMockMvc

View File

@@ -16,7 +16,7 @@
package org.springframework.cloud.context.environment;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.springframework.context.ApplicationEvent;

View File

@@ -20,7 +20,7 @@ import java.util.Arrays;
import java.util.Map;
import org.assertj.core.api.Assertions;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;

View File

@@ -19,8 +19,7 @@ package org.springframework.cloud.context.properties;
import javax.annotation.PostConstruct;
import org.aopalliance.intercept.MethodInterceptor;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -39,11 +38,9 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.BDDAssertions.then;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = TestConfiguration.class, properties = "spring.config.use-legacy-processing=true")
@ActiveProfiles("config")
public class ConfigurationPropertiesRebinderIntegrationTests {

View File

@@ -16,8 +16,7 @@
package org.springframework.cloud.context.properties;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
@@ -35,11 +34,9 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.BDDAssertions.then;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = TestConfiguration.class)
public class ConfigurationPropertiesRebinderLifecycleIntegrationTests {

View File

@@ -21,9 +21,8 @@ import java.util.Map;
import javax.annotation.PostConstruct;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
@@ -40,11 +39,9 @@ import org.springframework.context.annotation.Import;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.PropertySource;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.BDDAssertions.then;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = TestConfiguration.class, properties = "messages=one,two")
public class ConfigurationPropertiesRebinderListIntegrationTests {
@@ -68,7 +65,7 @@ public class ConfigurationPropertiesRebinderListIntegrationTests {
@Test
@DirtiesContext
@Ignore("Can't rebind to list and re-initialize it (need refresh scope for this to work)")
@Disabled("Can't rebind to list and re-initialize it (need refresh scope for this to work)")
public void testReplaceProperties() throws Exception {
then("[one, two]").isEqualTo(this.properties.getMessages().toString());
Map<String, Object> map = findTestProperties();

View File

@@ -21,8 +21,7 @@ import java.util.Map;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.aop.AopAutoConfiguration;
@@ -39,11 +38,9 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.BDDAssertions.then;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = TestConfiguration.class, properties = { "messages.expiry.one=168", "messages.expiry.two=76" })
public class ConfigurationPropertiesRebinderProxyIntegrationTests {

View File

@@ -18,8 +18,7 @@ package org.springframework.cloud.context.properties;
import javax.annotation.PostConstruct;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
@@ -36,11 +35,9 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.BDDAssertions.then;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = TestConfiguration.class, properties = "spring.config.use-legacy-processing=true")
public class ConfigurationPropertiesRebinderRefreshScopeIntegrationTests {

View File

@@ -16,8 +16,7 @@
package org.springframework.cloud.context.refresh;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
@@ -31,11 +30,9 @@ import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.jmx.export.annotation.ManagedAttribute;
import org.springframework.jmx.export.annotation.ManagedResource;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.BDDAssertions.then;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = TestConfiguration.class,
properties = { "spring.datasource.hikari.read-only=false", "spring.config.use-legacy-processing=true" })
public class ContextRefresherIntegrationTests {

View File

@@ -21,10 +21,9 @@ import java.util.Collection;
import java.util.Collections;
import java.util.concurrent.atomic.AtomicBoolean;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringBootConfiguration;
@@ -38,12 +37,10 @@ import org.springframework.core.env.MapPropertySource;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.core.env.PropertySource;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
import static java.util.Collections.singletonMap;
import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringRunner.class)
@SpringBootTest(properties = "spring.config.use-legacy-processing=true")
@DirtiesContext
public class ContextRefresherOrderingIntegrationTests {
@@ -56,14 +53,14 @@ public class ContextRefresherOrderingIntegrationTests {
private static String original;
@BeforeClass
@BeforeAll
public static void beforeClass() {
original = System.getProperty("spring.cloud.bootstrap.sources");
System.setProperty("spring.cloud.bootstrap.sources",
"org.springframework.cloud.context.refresh.ContextRefresherOrderingIntegrationTests.PropertySourceConfiguration");
}
@AfterClass
@AfterAll
public static void afterClass() {
if (original != null) {
System.setProperty("spring.cloud.bootstrap.sources", original);

View File

@@ -22,9 +22,9 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.junit.After;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.boot.SpringApplication;
@@ -52,14 +52,14 @@ public class ContextRefresherTests {
private RefreshScope scope = Mockito.mock(RefreshScope.class);
@After
@AfterEach
public void close() {
System.clearProperty(LoggingSystem.SYSTEM_PROPERTY);
TestLoggingSystem.count = 0;
}
@Test
@Ignore // FIXME: legacy config
@Disabled // FIXME: legacy config
public void orderNewPropertiesConsistentWithNewContext() {
try (ConfigurableApplicationContext context = SpringApplication.run(Empty.class,
"--spring.config.use-legacy-processing=true", "--spring.main.web-application-type=none",

View File

@@ -16,8 +16,8 @@
package org.springframework.cloud.context.restart;
import org.junit.After;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
@@ -35,7 +35,7 @@ public class RestartIntegrationTests {
SpringApplication.run(TestConfiguration.class, args);
}
@After
@AfterEach
public void close() {
if (this.context != null) {
this.context.close();

View File

@@ -16,8 +16,7 @@
package org.springframework.cloud.context.scope.refresh;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.aop.scope.ScopedProxyUtils;
import org.springframework.beans.factory.annotation.Autowired;
@@ -28,11 +27,9 @@ import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.cloud.context.scope.refresh.ImportRefreshScopeIntegrationTests.TestConfiguration;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.BDDAssertions.then;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = TestConfiguration.class)
public class ImportRefreshScopeIntegrationTests {

View File

@@ -18,10 +18,9 @@ package org.springframework.cloud.context.scope.refresh;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.aop.framework.Advised;
import org.springframework.beans.factory.BeanCreationException;
@@ -40,12 +39,10 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.fail;
import static org.assertj.core.api.BDDAssertions.then;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = TestConfiguration.class)
public class MoreRefreshScopeIntegrationTests {
@@ -58,13 +55,13 @@ public class MoreRefreshScopeIntegrationTests {
@Autowired
private ConfigurableEnvironment environment;
@Before
@BeforeEach
public void init() {
then(TestService.getInitCount()).isEqualTo(1);
TestService.reset();
}
@After
@AfterEach
public void close() {
TestService.reset();
}

View File

@@ -21,8 +21,7 @@ import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
@@ -39,7 +38,6 @@ import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.RequestEntity;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@@ -50,7 +48,7 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
* @author Dave Syer
*
*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = ClientApp.class,
properties = { "management.endpoints.web.exposure.include=*", "management.endpoint.env.post.enabled=true" },
webEnvironment = RANDOM_PORT)

View File

@@ -25,8 +25,7 @@ import java.util.concurrent.TimeUnit;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
@@ -45,11 +44,9 @@ import org.springframework.jmx.export.annotation.ManagedAttribute;
import org.springframework.jmx.export.annotation.ManagedResource;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.Repeat;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.BDDAssertions.then;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = TestConfiguration.class)
public class RefreshScopeConcurrencyTests {

View File

@@ -27,8 +27,7 @@ import java.util.concurrent.TimeUnit;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
@@ -47,12 +46,10 @@ import org.springframework.context.annotation.Import;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.Repeat;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.util.ObjectUtils;
import static org.assertj.core.api.BDDAssertions.then;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = TestConfiguration.class, properties = {
"logging.level.org.springframework.cloud.context.scope.refresh.RefreshScopeConfigurationScaleTests=DEBUG" })
public class RefreshScopeConfigurationScaleTests {

View File

@@ -16,10 +16,8 @@
package org.springframework.cloud.context.scope.refresh;
import org.junit.After;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.springframework.aop.scope.ScopedProxyUtils;
import org.springframework.beans.factory.annotation.Value;
@@ -44,12 +42,9 @@ import static org.assertj.core.api.BDDAssertions.then;
*/
public class RefreshScopeConfigurationTests {
@Rule
public ExpectedException expected = ExpectedException.none();
private AnnotationConfigApplicationContext context;
@After
@AfterEach
public void init() {
if (this.context != null) {
this.context.close();

View File

@@ -18,10 +18,10 @@ package org.springframework.cloud.context.scope.refresh;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.aop.framework.Advised;
import org.springframework.aop.scope.ScopedProxyUtils;
@@ -40,11 +40,9 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.jmx.export.annotation.ManagedAttribute;
import org.springframework.jmx.export.annotation.ManagedResource;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.BDDAssertions.then;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = TestConfiguration.class)
public class RefreshScopeIntegrationTests {
@@ -57,13 +55,13 @@ public class RefreshScopeIntegrationTests {
@Autowired
private org.springframework.cloud.context.scope.refresh.RefreshScope scope;
@Before
@BeforeEach
public void init() {
then(ExampleService.getInitCount()).isEqualTo(1);
ExampleService.reset();
}
@After
@AfterEach
public void close() {
ExampleService.reset();
}
@@ -119,10 +117,12 @@ public class RefreshScopeIntegrationTests {
}
// see gh-349
@Test(expected = ServiceException.class)
@Test
@DirtiesContext
public void testCheckedException() throws Exception {
this.service.throwsException();
public void testCheckedException() {
Assertions.assertThrows(ServiceException.class, () -> {
this.service.throwsException();
});
}
public interface Service {

View File

@@ -18,10 +18,9 @@ package org.springframework.cloud.context.scope.refresh;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.aop.framework.Advised;
import org.springframework.aop.scope.ScopedProxyUtils;
@@ -42,11 +41,9 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.jmx.export.annotation.ManagedAttribute;
import org.springframework.jmx.export.annotation.ManagedResource;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.BDDAssertions.then;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = TestConfiguration.class)
public class RefreshScopeLazyIntegrationTests {
@@ -59,14 +56,14 @@ public class RefreshScopeLazyIntegrationTests {
@Autowired
private org.springframework.cloud.context.scope.refresh.RefreshScope scope;
@Before
@BeforeEach
public void init() {
// The RefreshScope is lazy (eager=false) so it won't have been instantiated yet
then(ExampleService.getInitCount()).isEqualTo(0);
ExampleService.reset();
}
@After
@AfterEach
public void close() {
ExampleService.reset();
}

View File

@@ -20,8 +20,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.aop.framework.Advised;
import org.springframework.beans.factory.annotation.Autowired;
@@ -40,11 +39,9 @@ import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.PropertySource;
import org.springframework.jmx.export.annotation.ManagedResource;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.BDDAssertions.then;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = TestConfiguration.class, properties = { "test.messages[0]=one", "test.messages[1]=two" })
public class RefreshScopeListBindingIntegrationTests {

View File

@@ -16,8 +16,7 @@
package org.springframework.cloud.context.scope.refresh;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
@@ -28,11 +27,9 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.BDDAssertions.then;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = { RefreshScopeNullBeanIntegrationTests.TestConfiguration.class })
public class RefreshScopeNullBeanIntegrationTests {

View File

@@ -27,8 +27,7 @@ import java.util.concurrent.TimeUnit;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
@@ -43,12 +42,10 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.Repeat;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.util.ObjectUtils;
import static org.assertj.core.api.BDDAssertions.then;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = TestConfiguration.class)
// ,
// properties="logging.level.org.springframework.cloud.context.scope.refresh.RefreshScopePureScaleTests=DEBUG")

View File

@@ -25,8 +25,7 @@ import java.util.concurrent.TimeUnit;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
@@ -45,11 +44,9 @@ import org.springframework.jmx.export.annotation.ManagedAttribute;
import org.springframework.jmx.export.annotation.ManagedResource;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.Repeat;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.BDDAssertions.then;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = TestConfiguration.class)
public class RefreshScopeScaleTests {

View File

@@ -16,7 +16,7 @@
package org.springframework.cloud.context.scope.refresh;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.boot.WebApplicationType;

View File

@@ -16,8 +16,7 @@
package org.springframework.cloud.context.scope.refresh;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.aop.scope.ScopedProxyUtils;
import org.springframework.beans.factory.annotation.Autowired;
@@ -31,7 +30,6 @@ import org.springframework.cloud.context.environment.EnvironmentManager;
import org.springframework.cloud.context.scope.refresh.RefreshScopeWebIntegrationTests.Application;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@@ -41,7 +39,6 @@ import static org.assertj.core.api.BDDAssertions.then;
* @author Dave Syer
*
*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class)
public class RefreshScopeWebIntegrationTests {

View File

@@ -18,8 +18,8 @@ package org.springframework.cloud.health;
import java.util.Collections;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.BDDMockito;
import org.springframework.beans.factory.ObjectProvider;
@@ -45,7 +45,7 @@ public class RefreshScopeHealthIndicatorTests {
private RefreshScopeHealthIndicator indicator = new RefreshScopeHealthIndicator(this.scopeProvider, this.rebinder);
@Before
@BeforeEach
public void init() {
BDDMockito.willReturn(this.scope).given(this.scopeProvider).getIfAvailable();
when(this.rebinder.getErrors()).thenReturn(Collections.emptyMap());

View File

@@ -19,8 +19,8 @@ package org.springframework.cloud.logging;
import java.util.Collections;
import ch.qos.logback.classic.Level;
import org.junit.After;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -43,7 +43,7 @@ public class LoggingRebinderTests {
private Logger logger = LoggerFactory.getLogger("org.springframework.web");
@After
@AfterEach
public void reset() {
LoggingSystem.get(getClass().getClassLoader()).setLogLevel("org.springframework.web", LogLevel.INFO);
}