Move tests to JUnit 5 wherever possible
This commit is contained in:
@@ -21,7 +21,6 @@ import java.io.OutputStream;
|
||||
import java.io.PrintStream;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Deque;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
@@ -143,11 +142,13 @@ class OutputCapture implements CapturedOutput {
|
||||
*/
|
||||
private static class SystemCapture {
|
||||
|
||||
private final Object monitor = new Object();
|
||||
|
||||
private final PrintStreamCapture out;
|
||||
|
||||
private final PrintStreamCapture err;
|
||||
|
||||
private final List<CapturedString> capturedStrings = Collections.synchronizedList(new ArrayList<>());
|
||||
private final List<CapturedString> capturedStrings = new ArrayList<>();
|
||||
|
||||
SystemCapture() {
|
||||
this.out = new PrintStreamCapture(System.out, this::captureOut);
|
||||
@@ -162,23 +163,31 @@ class OutputCapture implements CapturedOutput {
|
||||
}
|
||||
|
||||
private void captureOut(String string) {
|
||||
this.capturedStrings.add(new CapturedString(Type.OUT, string));
|
||||
synchronized (this.monitor) {
|
||||
this.capturedStrings.add(new CapturedString(Type.OUT, string));
|
||||
}
|
||||
}
|
||||
|
||||
private void captureErr(String string) {
|
||||
this.capturedStrings.add(new CapturedString(Type.ERR, string));
|
||||
synchronized (this.monitor) {
|
||||
this.capturedStrings.add(new CapturedString(Type.ERR, string));
|
||||
}
|
||||
}
|
||||
|
||||
public void append(StringBuilder builder, Predicate<Type> filter) {
|
||||
for (CapturedString stringCapture : this.capturedStrings) {
|
||||
if (filter.test(stringCapture.getType())) {
|
||||
builder.append(stringCapture);
|
||||
synchronized (this.monitor) {
|
||||
for (CapturedString stringCapture : this.capturedStrings) {
|
||||
if (filter.test(stringCapture.getType())) {
|
||||
builder.append(stringCapture);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
this.capturedStrings.clear();
|
||||
synchronized (this.monitor) {
|
||||
this.capturedStrings.clear();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ import static org.hamcrest.Matchers.allOf;
|
||||
*/
|
||||
public class OutputCaptureRule implements TestRule {
|
||||
|
||||
private final org.springframework.boot.test.system.OutputCapture delegate = new org.springframework.boot.test.system.OutputCapture();
|
||||
private final OutputCapture delegate = new OutputCapture();
|
||||
|
||||
private List<Matcher<? super String>> matchers = new ArrayList<>();
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public abstract class AbstractSpringBootTestEmbeddedReactiveWebEnvironmentTests {
|
||||
abstract class AbstractSpringBootTestEmbeddedReactiveWebEnvironmentTests {
|
||||
|
||||
@LocalServerPort
|
||||
private int port = 0;
|
||||
@@ -64,25 +64,25 @@ public abstract class AbstractSpringBootTestEmbeddedReactiveWebEnvironmentTests
|
||||
}
|
||||
|
||||
@Test
|
||||
public void runAndTestHttpEndpoint() {
|
||||
void runAndTestHttpEndpoint() {
|
||||
assertThat(this.port).isNotEqualTo(8080).isNotEqualTo(0);
|
||||
WebTestClient.bindToServer().baseUrl("http://localhost:" + this.port).build().get().uri("/").exchange()
|
||||
.expectBody(String.class).isEqualTo("Hello World");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void injectWebTestClient() {
|
||||
void injectWebTestClient() {
|
||||
this.webClient.get().uri("/").exchange().expectBody(String.class).isEqualTo("Hello World");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void injectTestRestTemplate() {
|
||||
void injectTestRestTemplate() {
|
||||
String body = this.restTemplate.getForObject("/", String.class);
|
||||
assertThat(body).isEqualTo("Hello World");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void annotationAttributesOverridePropertiesFile() {
|
||||
void annotationAttributesOverridePropertiesFile() {
|
||||
assertThat(this.value).isEqualTo(123);
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Phillip Webb
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public abstract class AbstractSpringBootTestWebServerWebEnvironmentTests {
|
||||
abstract class AbstractSpringBootTestWebServerWebEnvironmentTests {
|
||||
|
||||
@LocalServerPort
|
||||
private int port = 0;
|
||||
@@ -69,25 +69,25 @@ public abstract class AbstractSpringBootTestWebServerWebEnvironmentTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void runAndTestHttpEndpoint() {
|
||||
void runAndTestHttpEndpoint() {
|
||||
assertThat(this.port).isNotEqualTo(8080).isNotEqualTo(0);
|
||||
String body = new RestTemplate().getForObject("http://localhost:" + this.port + "/", String.class);
|
||||
assertThat(body).isEqualTo("Hello World");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void injectTestRestTemplate() {
|
||||
void injectTestRestTemplate() {
|
||||
String body = this.restTemplate.getForObject("/", String.class);
|
||||
assertThat(body).isEqualTo("Hello World");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void annotationAttributesOverridePropertiesFile() {
|
||||
void annotationAttributesOverridePropertiesFile() {
|
||||
assertThat(this.value).isEqualTo(123);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validateWebApplicationContextIsSet() {
|
||||
void validateWebApplicationContextIsSet() {
|
||||
assertThat(this.context).isSameAs(WebApplicationContextUtils.getWebApplicationContext(this.servletContext));
|
||||
}
|
||||
|
||||
|
||||
@@ -30,36 +30,36 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class AnnotatedClassFinderTests {
|
||||
class AnnotatedClassFinderTests {
|
||||
|
||||
private AnnotatedClassFinder finder = new AnnotatedClassFinder(SpringBootConfiguration.class);
|
||||
|
||||
@Test
|
||||
public void findFromClassWhenSourceIsNullShouldThrowException() {
|
||||
void findFromClassWhenSourceIsNullShouldThrowException() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> this.finder.findFromClass((Class<?>) null))
|
||||
.withMessageContaining("Source must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findFromPackageWhenSourceIsNullShouldThrowException() {
|
||||
void findFromPackageWhenSourceIsNullShouldThrowException() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> this.finder.findFromPackage((String) null))
|
||||
.withMessageContaining("Source must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findFromPackageWhenNoConfigurationFoundShouldReturnNull() {
|
||||
void findFromPackageWhenNoConfigurationFoundShouldReturnNull() {
|
||||
Class<?> config = this.finder.findFromPackage("org.springframework.boot");
|
||||
assertThat(config).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findFromClassWhenConfigurationIsFoundShouldReturnConfiguration() {
|
||||
void findFromClassWhenConfigurationIsFoundShouldReturnConfiguration() {
|
||||
Class<?> config = this.finder.findFromClass(Example.class);
|
||||
assertThat(config).isEqualTo(ExampleConfig.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findFromPackageWhenConfigurationIsFoundShouldReturnConfiguration() {
|
||||
void findFromPackageWhenConfigurationIsFoundShouldReturnConfiguration() {
|
||||
Class<?> config = this.finder.findFromPackage("org.springframework.boot.test.context.example.scan");
|
||||
assertThat(config).isEqualTo(ExampleConfig.class);
|
||||
}
|
||||
|
||||
@@ -37,13 +37,13 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
@DirtiesContext
|
||||
@ContextConfiguration(classes = ConfigFileApplicationContextInitializerTests.Config.class,
|
||||
initializers = ConfigFileApplicationContextInitializer.class)
|
||||
public class ConfigFileApplicationContextInitializerTests {
|
||||
class ConfigFileApplicationContextInitializerTests {
|
||||
|
||||
@Autowired
|
||||
private Environment environment;
|
||||
|
||||
@Test
|
||||
public void initializerPopulatesEnvironment() {
|
||||
void initializerPopulatesEnvironment() {
|
||||
assertThat(this.environment.getProperty("foo")).isEqualTo("bucket");
|
||||
}
|
||||
|
||||
|
||||
@@ -33,13 +33,13 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
* @author Phillip Webb
|
||||
* @author Roy Jacobs
|
||||
*/
|
||||
public class FilteredClassLoaderTests {
|
||||
class FilteredClassLoaderTests {
|
||||
|
||||
private static ClassPathResource TEST_RESOURCE = new ClassPathResource(
|
||||
"org/springframework/boot/test/context/FilteredClassLoaderTestsResource.txt");
|
||||
|
||||
@Test
|
||||
public void loadClassWhenFilteredOnPackageShouldThrowClassNotFound() throws Exception {
|
||||
void loadClassWhenFilteredOnPackageShouldThrowClassNotFound() throws Exception {
|
||||
try (FilteredClassLoader classLoader = new FilteredClassLoader(
|
||||
FilteredClassLoaderTests.class.getPackage().getName())) {
|
||||
assertThatExceptionOfType(ClassNotFoundException.class)
|
||||
@@ -48,7 +48,7 @@ public class FilteredClassLoaderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loadClassWhenFilteredOnClassShouldThrowClassNotFound() throws Exception {
|
||||
void loadClassWhenFilteredOnClassShouldThrowClassNotFound() throws Exception {
|
||||
try (FilteredClassLoader classLoader = new FilteredClassLoader(FilteredClassLoaderTests.class)) {
|
||||
assertThatExceptionOfType(ClassNotFoundException.class)
|
||||
.isThrownBy(() -> classLoader.loadClass(getClass().getName()));
|
||||
@@ -56,7 +56,7 @@ public class FilteredClassLoaderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loadClassWhenNotFilteredShouldLoadClass() throws Exception {
|
||||
void loadClassWhenNotFilteredShouldLoadClass() throws Exception {
|
||||
FilteredClassLoader classLoader = new FilteredClassLoader((className) -> false);
|
||||
Class<?> loaded = classLoader.loadClass(getClass().getName());
|
||||
assertThat(loaded.getName()).isEqualTo(getClass().getName());
|
||||
@@ -64,7 +64,7 @@ public class FilteredClassLoaderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loadResourceWhenFilteredOnResourceShouldReturnNotFound() throws Exception {
|
||||
void loadResourceWhenFilteredOnResourceShouldReturnNotFound() throws Exception {
|
||||
try (FilteredClassLoader classLoader = new FilteredClassLoader(TEST_RESOURCE)) {
|
||||
final URL loaded = classLoader.getResource(TEST_RESOURCE.getPath());
|
||||
assertThat(loaded).isNull();
|
||||
@@ -72,7 +72,7 @@ public class FilteredClassLoaderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loadResourceWhenNotFilteredShouldLoadResource() throws Exception {
|
||||
void loadResourceWhenNotFilteredShouldLoadResource() throws Exception {
|
||||
try (FilteredClassLoader classLoader = new FilteredClassLoader((resourceName) -> false)) {
|
||||
final URL loaded = classLoader.getResource(TEST_RESOURCE.getPath());
|
||||
assertThat(loaded).isNotNull();
|
||||
@@ -80,7 +80,7 @@ public class FilteredClassLoaderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loadResourcesWhenFilteredOnResourceShouldReturnNotFound() throws Exception {
|
||||
void loadResourcesWhenFilteredOnResourceShouldReturnNotFound() throws Exception {
|
||||
try (FilteredClassLoader classLoader = new FilteredClassLoader(TEST_RESOURCE)) {
|
||||
final Enumeration<URL> loaded = classLoader.getResources(TEST_RESOURCE.getPath());
|
||||
assertThat(loaded.hasMoreElements()).isFalse();
|
||||
@@ -88,7 +88,7 @@ public class FilteredClassLoaderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loadResourcesWhenNotFilteredShouldLoadResource() throws Exception {
|
||||
void loadResourcesWhenNotFilteredShouldLoadResource() throws Exception {
|
||||
try (FilteredClassLoader classLoader = new FilteredClassLoader((resourceName) -> false)) {
|
||||
final Enumeration<URL> loaded = classLoader.getResources(TEST_RESOURCE.getPath());
|
||||
assertThat(loaded.hasMoreElements()).isTrue();
|
||||
@@ -96,7 +96,7 @@ public class FilteredClassLoaderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loadResourceAsStreamWhenFilteredOnResourceShouldReturnNotFound() throws Exception {
|
||||
void loadResourceAsStreamWhenFilteredOnResourceShouldReturnNotFound() throws Exception {
|
||||
try (FilteredClassLoader classLoader = new FilteredClassLoader(TEST_RESOURCE)) {
|
||||
final InputStream loaded = classLoader.getResourceAsStream(TEST_RESOURCE.getPath());
|
||||
assertThat(loaded).isNull();
|
||||
@@ -104,7 +104,7 @@ public class FilteredClassLoaderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loadResourceAsStreamWhenNotFilteredShouldLoadResource() throws Exception {
|
||||
void loadResourceAsStreamWhenNotFilteredShouldLoadResource() throws Exception {
|
||||
try (FilteredClassLoader classLoader = new FilteredClassLoader((resourceName) -> false)) {
|
||||
final InputStream loaded = classLoader.getResourceAsStream(TEST_RESOURCE.getPath());
|
||||
assertThat(loaded).isNotNull();
|
||||
|
||||
@@ -38,7 +38,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@Import(ImportedBean.class)
|
||||
public class ImportsContextCustomizerFactoryIntegrationTests {
|
||||
class ImportsContextCustomizerFactoryIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext context;
|
||||
@@ -47,12 +47,12 @@ public class ImportsContextCustomizerFactoryIntegrationTests {
|
||||
private ImportedBean bean;
|
||||
|
||||
@Test
|
||||
public void beanWasImported() {
|
||||
void beanWasImported() {
|
||||
assertThat(this.bean).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testItselfIsNotABean() {
|
||||
void testItselfIsNotABean() {
|
||||
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
|
||||
.isThrownBy(() -> this.context.getBean(getClass()));
|
||||
}
|
||||
|
||||
@@ -39,30 +39,30 @@ import static org.mockito.Mockito.mock;
|
||||
* @author Phillip Webb
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class ImportsContextCustomizerFactoryTests {
|
||||
class ImportsContextCustomizerFactoryTests {
|
||||
|
||||
private ImportsContextCustomizerFactory factory = new ImportsContextCustomizerFactory();
|
||||
|
||||
@Test
|
||||
public void getContextCustomizerWhenHasNoImportAnnotationShouldReturnNull() {
|
||||
void getContextCustomizerWhenHasNoImportAnnotationShouldReturnNull() {
|
||||
ContextCustomizer customizer = this.factory.createContextCustomizer(TestWithNoImport.class, null);
|
||||
assertThat(customizer).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getContextCustomizerWhenHasImportAnnotationShouldReturnCustomizer() {
|
||||
void getContextCustomizerWhenHasImportAnnotationShouldReturnCustomizer() {
|
||||
ContextCustomizer customizer = this.factory.createContextCustomizer(TestWithImport.class, null);
|
||||
assertThat(customizer).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getContextCustomizerWhenHasMetaImportAnnotationShouldReturnCustomizer() {
|
||||
void getContextCustomizerWhenHasMetaImportAnnotationShouldReturnCustomizer() {
|
||||
ContextCustomizer customizer = this.factory.createContextCustomizer(TestWithMetaImport.class, null);
|
||||
assertThat(customizer).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void contextCustomizerEqualsAndHashCode() {
|
||||
void contextCustomizerEqualsAndHashCode() {
|
||||
ContextCustomizer customizer1 = this.factory.createContextCustomizer(TestWithImport.class, null);
|
||||
ContextCustomizer customizer2 = this.factory.createContextCustomizer(TestWithImport.class, null);
|
||||
ContextCustomizer customizer3 = this.factory.createContextCustomizer(TestWithImportAndMetaImport.class, null);
|
||||
@@ -75,14 +75,14 @@ public class ImportsContextCustomizerFactoryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getContextCustomizerWhenClassHasBeanMethodsShouldThrowException() {
|
||||
void getContextCustomizerWhenClassHasBeanMethodsShouldThrowException() {
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> this.factory.createContextCustomizer(TestWithImportAndBeanMethod.class, null))
|
||||
.withMessageContaining("Test classes cannot include @Bean methods");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void contextCustomizerImportsBeans() {
|
||||
void contextCustomizerImportsBeans() {
|
||||
ContextCustomizer customizer = this.factory.createContextCustomizer(TestWithImport.class, null);
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
customizer.customizeContext(context, mock(MergedContextConfiguration.class));
|
||||
@@ -91,7 +91,7 @@ public class ImportsContextCustomizerFactoryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void selfAnnotatingAnnotationDoesNotCauseStackOverflow() {
|
||||
void selfAnnotatingAnnotationDoesNotCauseStackOverflow() {
|
||||
assertThat(this.factory.createContextCustomizer(TestWithImportAndSelfAnnotatingAnnotation.class, null))
|
||||
.isNotNull();
|
||||
}
|
||||
|
||||
@@ -40,34 +40,34 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class ImportsContextCustomizerTests {
|
||||
class ImportsContextCustomizerTests {
|
||||
|
||||
@Test
|
||||
public void importSelectorsCouldUseAnyAnnotations() {
|
||||
void importSelectorsCouldUseAnyAnnotations() {
|
||||
assertThat(new ImportsContextCustomizer(FirstImportSelectorAnnotatedClass.class))
|
||||
.isNotEqualTo(new ImportsContextCustomizer(SecondImportSelectorAnnotatedClass.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void determinableImportSelector() {
|
||||
void determinableImportSelector() {
|
||||
assertThat(new ImportsContextCustomizer(FirstDeterminableImportSelectorAnnotatedClass.class))
|
||||
.isEqualTo(new ImportsContextCustomizer(SecondDeterminableImportSelectorAnnotatedClass.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customizersForTestClassesWithDifferentKotlinMetadataAreEqual() {
|
||||
void customizersForTestClassesWithDifferentKotlinMetadataAreEqual() {
|
||||
assertThat(new ImportsContextCustomizer(FirstKotlinAnnotatedTestClass.class))
|
||||
.isEqualTo(new ImportsContextCustomizer(SecondKotlinAnnotatedTestClass.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customizersForTestClassesWithDifferentSpockFrameworkAnnotationsAreEqual() {
|
||||
void customizersForTestClassesWithDifferentSpockFrameworkAnnotationsAreEqual() {
|
||||
assertThat(new ImportsContextCustomizer(FirstSpockFrameworkAnnotatedTestClass.class))
|
||||
.isEqualTo(new ImportsContextCustomizer(SecondSpockFrameworkAnnotatedTestClass.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customizersForTestClassesWithDifferentSpockLangAnnotationsAreEqual() {
|
||||
void customizersForTestClassesWithDifferentSpockLangAnnotationsAreEqual() {
|
||||
assertThat(new ImportsContextCustomizer(FirstSpockLangAnnotatedTestClass.class))
|
||||
.isEqualTo(new ImportsContextCustomizer(SecondSpockLangAnnotatedTestClass.class));
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
@DirtiesContext
|
||||
@ContextConfiguration(loader = SpringBootContextLoader.class)
|
||||
@WebAppConfiguration
|
||||
public class SpringBootContextLoaderMockMvcTests {
|
||||
class SpringBootContextLoaderMockMvcTests {
|
||||
|
||||
@Autowired
|
||||
private WebApplicationContext context;
|
||||
@@ -66,12 +66,12 @@ public class SpringBootContextLoaderMockMvcTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMockHttpEndpoint() throws Exception {
|
||||
void testMockHttpEndpoint() throws Exception {
|
||||
this.mvc.perform(get("/")).andExpect(status().isOk()).andExpect(content().string("Hello World"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validateWebApplicationContextIsSet() {
|
||||
void validateWebApplicationContextIsSet() {
|
||||
assertThat(this.context).isSameAs(WebApplicationContextUtils.getWebApplicationContext(this.servletContext));
|
||||
}
|
||||
|
||||
|
||||
@@ -36,44 +36,44 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class SpringBootContextLoaderTests {
|
||||
class SpringBootContextLoaderTests {
|
||||
|
||||
@Test
|
||||
public void environmentPropertiesSimple() {
|
||||
void environmentPropertiesSimple() {
|
||||
Map<String, Object> config = getEnvironmentProperties(SimpleConfig.class);
|
||||
assertKey(config, "key", "myValue");
|
||||
assertKey(config, "anotherKey", "anotherValue");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void environmentPropertiesSimpleNonAlias() {
|
||||
void environmentPropertiesSimpleNonAlias() {
|
||||
Map<String, Object> config = getEnvironmentProperties(SimpleConfigNonAlias.class);
|
||||
assertKey(config, "key", "myValue");
|
||||
assertKey(config, "anotherKey", "anotherValue");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void environmentPropertiesOverrideDefaults() {
|
||||
void environmentPropertiesOverrideDefaults() {
|
||||
Map<String, Object> config = getEnvironmentProperties(OverrideConfig.class);
|
||||
assertKey(config, "server.port", "2345");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void environmentPropertiesAppend() {
|
||||
void environmentPropertiesAppend() {
|
||||
Map<String, Object> config = getEnvironmentProperties(AppendConfig.class);
|
||||
assertKey(config, "key", "myValue");
|
||||
assertKey(config, "otherKey", "otherValue");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void environmentPropertiesSeparatorInValue() {
|
||||
void environmentPropertiesSeparatorInValue() {
|
||||
Map<String, Object> config = getEnvironmentProperties(SameSeparatorInValue.class);
|
||||
assertKey(config, "key", "my=Value");
|
||||
assertKey(config, "anotherKey", "another:Value");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void environmentPropertiesAnotherSeparatorInValue() {
|
||||
void environmentPropertiesAnotherSeparatorInValue() {
|
||||
Map<String, Object> config = getEnvironmentProperties(AnotherSeparatorInValue.class);
|
||||
assertKey(config, "key", "my:Value");
|
||||
assertKey(config, "anotherKey", "another=Value");
|
||||
@@ -81,7 +81,7 @@ public class SpringBootContextLoaderTests {
|
||||
|
||||
@Test
|
||||
@Disabled
|
||||
public void environmentPropertiesNewLineInValue() {
|
||||
void environmentPropertiesNewLineInValue() {
|
||||
// gh-4384
|
||||
Map<String, Object> config = getEnvironmentProperties(NewLineInValue.class);
|
||||
assertKey(config, "key", "myValue");
|
||||
|
||||
@@ -34,13 +34,13 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
@DirtiesContext
|
||||
@SpringBootTest("spring.config.name=enableother")
|
||||
@ActiveProfiles("override")
|
||||
public class SpringBootTestActiveProfileTests {
|
||||
class SpringBootTestActiveProfileTests {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext context;
|
||||
|
||||
@Test
|
||||
public void profiles() {
|
||||
void profiles() {
|
||||
assertThat(this.context.getEnvironment().getActiveProfiles()).containsExactly("override");
|
||||
}
|
||||
|
||||
|
||||
@@ -31,13 +31,13 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@SpringBootTest(args = { "--option.foo=foo-value", "other.bar=other-bar-value" })
|
||||
public class SpringBootTestArgsTests {
|
||||
class SpringBootTestArgsTests {
|
||||
|
||||
@Autowired
|
||||
private ApplicationArguments args;
|
||||
|
||||
@Test
|
||||
public void applicationArgumentsPopulated() {
|
||||
void applicationArgumentsPopulated() {
|
||||
assertThat(this.args.getOptionNames()).containsOnly("option.foo");
|
||||
assertThat(this.args.getOptionValues("option.foo")).containsOnly("foo-value");
|
||||
assertThat(this.args.getNonOptionArgs()).containsOnly("other.bar=other-bar-value");
|
||||
|
||||
@@ -34,10 +34,10 @@ import org.springframework.test.context.ContextHierarchy;
|
||||
@SpringBootTest
|
||||
@ContextHierarchy({ @ContextConfiguration(classes = ParentConfiguration.class),
|
||||
@ContextConfiguration(classes = ChildConfiguration.class) })
|
||||
public class SpringBootTestContextHierarchyTests {
|
||||
class SpringBootTestContextHierarchyTests {
|
||||
|
||||
@Test
|
||||
public void contextLoads() {
|
||||
void contextLoads() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -30,13 +30,13 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
@SpringBootTest(properties = "spring.config.name=custom-config-name")
|
||||
public class SpringBootTestCustomConfigNameTests {
|
||||
class SpringBootTestCustomConfigNameTests {
|
||||
|
||||
@Value("${test.foo}")
|
||||
private String foo;
|
||||
|
||||
@Test
|
||||
public void propertyIsLoadedFromConfigFileWithCustomName() {
|
||||
void propertyIsLoadedFromConfigFileWithCustomName() {
|
||||
assertThat(this.foo).isEqualTo("bar");
|
||||
}
|
||||
|
||||
|
||||
@@ -31,13 +31,13 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@SpringBootTest(properties = "server.port=12345")
|
||||
public class SpringBootTestCustomPortTests {
|
||||
class SpringBootTestCustomPortTests {
|
||||
|
||||
@Autowired
|
||||
private Environment environment;
|
||||
|
||||
@Test
|
||||
public void validatePortIsNotOverwritten() {
|
||||
void validatePortIsNotOverwritten() {
|
||||
String port = this.environment.getProperty("server.port");
|
||||
assertThat(port).isEqualTo("12345");
|
||||
}
|
||||
|
||||
@@ -33,13 +33,13 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@DirtiesContext
|
||||
public class SpringBootTestDefaultConfigurationTests {
|
||||
class SpringBootTestDefaultConfigurationTests {
|
||||
|
||||
@Autowired
|
||||
private Config config;
|
||||
|
||||
@Test
|
||||
public void nestedConfigClasses() {
|
||||
void nestedConfigClasses() {
|
||||
assertThat(this.config).isNotNull();
|
||||
}
|
||||
|
||||
|
||||
@@ -32,13 +32,13 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
@DirtiesContext
|
||||
@SpringBootTest
|
||||
@ContextConfiguration(locations = "classpath:test.groovy")
|
||||
public class SpringBootTestGroovyConfigurationTests {
|
||||
class SpringBootTestGroovyConfigurationTests {
|
||||
|
||||
@Autowired
|
||||
private String foo;
|
||||
|
||||
@Test
|
||||
public void groovyConfigLoaded() {
|
||||
void groovyConfigLoaded() {
|
||||
assertThat(this.foo).isNotNull();
|
||||
}
|
||||
|
||||
|
||||
@@ -30,13 +30,13 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
@SpringBootTest
|
||||
@DirtiesContext
|
||||
public class SpringBootTestGroovyConventionConfigurationTests {
|
||||
class SpringBootTestGroovyConventionConfigurationTests {
|
||||
|
||||
@Autowired
|
||||
private String foo;
|
||||
|
||||
@Test
|
||||
public void groovyConfigLoaded() {
|
||||
void groovyConfigLoaded() {
|
||||
assertThat(this.foo).isEqualTo("World");
|
||||
}
|
||||
|
||||
|
||||
@@ -33,13 +33,13 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
@DirtiesContext
|
||||
@SpringBootTest
|
||||
public class SpringBootTestJmxTests {
|
||||
class SpringBootTestJmxTests {
|
||||
|
||||
@Value("${spring.jmx.enabled}")
|
||||
private boolean jmx;
|
||||
|
||||
@Test
|
||||
public void disabledByDefault() {
|
||||
void disabledByDefault() {
|
||||
assertThat(this.jmx).isFalse();
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
@DirtiesContext
|
||||
@SpringBootTest
|
||||
@ContextConfiguration(classes = Config.class, locations = "classpath:test.groovy")
|
||||
public class SpringBootTestMixedConfigurationTests {
|
||||
class SpringBootTestMixedConfigurationTests {
|
||||
|
||||
@Autowired
|
||||
private String foo;
|
||||
@@ -43,7 +43,7 @@ public class SpringBootTestMixedConfigurationTests {
|
||||
private Config config;
|
||||
|
||||
@Test
|
||||
public void mixedConfigClasses() {
|
||||
void mixedConfigClasses() {
|
||||
assertThat(this.foo).isNotNull();
|
||||
assertThat(this.config).isNotNull();
|
||||
}
|
||||
|
||||
@@ -37,11 +37,11 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
@DirtiesContext
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT,
|
||||
properties = { "spring.main.web-application-type=reactive", "value=123" })
|
||||
public class SpringBootTestReactiveWebEnvironmentUserDefinedTestRestTemplateTests
|
||||
class SpringBootTestReactiveWebEnvironmentUserDefinedTestRestTemplateTests
|
||||
extends AbstractSpringBootTestEmbeddedReactiveWebEnvironmentTests {
|
||||
|
||||
@Test
|
||||
public void restTemplateIsUserDefined() {
|
||||
void restTemplateIsUserDefined() {
|
||||
assertThat(getContext().getBean("testRestTemplate")).isInstanceOf(RestTemplate.class);
|
||||
}
|
||||
|
||||
|
||||
@@ -37,10 +37,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
@DirtiesContext
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { "value=123" })
|
||||
public class SpringBootTestUserDefinedTestRestTemplateTests extends AbstractSpringBootTestWebServerWebEnvironmentTests {
|
||||
class SpringBootTestUserDefinedTestRestTemplateTests extends AbstractSpringBootTestWebServerWebEnvironmentTests {
|
||||
|
||||
@Test
|
||||
public void restTemplateIsUserDefined() {
|
||||
void restTemplateIsUserDefined() {
|
||||
assertThat(getContext().getBean("testRestTemplate")).isInstanceOf(RestTemplate.class);
|
||||
}
|
||||
|
||||
|
||||
@@ -45,13 +45,13 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT, properties = { "server.port=0", "value=123" })
|
||||
@ContextHierarchy({ @ContextConfiguration(classes = ParentConfiguration.class),
|
||||
@ContextConfiguration(classes = ChildConfiguration.class) })
|
||||
public class SpringBootTestWebEnvironmentContextHierarchyTests {
|
||||
class SpringBootTestWebEnvironmentContextHierarchyTests {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext context;
|
||||
|
||||
@Test
|
||||
public void testShouldOnlyStartSingleServer() {
|
||||
void testShouldOnlyStartSingleServer() {
|
||||
ApplicationContext parent = this.context.getParent();
|
||||
assertThat(this.context).isInstanceOf(WebApplicationContext.class);
|
||||
assertThat(parent).isNotInstanceOf(WebApplicationContext.class);
|
||||
|
||||
@@ -44,7 +44,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
@SpringBootTest("value=123")
|
||||
@DirtiesContext
|
||||
public class SpringBootTestWebEnvironmentMockTests {
|
||||
class SpringBootTestWebEnvironmentMockTests {
|
||||
|
||||
@Value("${value}")
|
||||
private int value = 0;
|
||||
@@ -56,25 +56,25 @@ public class SpringBootTestWebEnvironmentMockTests {
|
||||
private ServletContext servletContext;
|
||||
|
||||
@Test
|
||||
public void annotationAttributesOverridePropertiesFile() {
|
||||
void annotationAttributesOverridePropertiesFile() {
|
||||
assertThat(this.value).isEqualTo(123);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validateWebApplicationContextIsSet() {
|
||||
void validateWebApplicationContextIsSet() {
|
||||
WebApplicationContext fromServletContext = WebApplicationContextUtils
|
||||
.getWebApplicationContext(this.servletContext);
|
||||
assertThat(fromServletContext).isSameAs(this.context);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setsRequestContextHolder() {
|
||||
void setsRequestContextHolder() {
|
||||
RequestAttributes attributes = RequestContextHolder.getRequestAttributes();
|
||||
assertThat(attributes).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resourcePath() {
|
||||
void resourcePath() {
|
||||
assertThat(this.servletContext).hasFieldOrPropertyWithValue("resourceBasePath", "src/main/webapp");
|
||||
}
|
||||
|
||||
|
||||
@@ -41,13 +41,13 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
@SpringBootTest
|
||||
@DirtiesContext
|
||||
@WebAppConfiguration("src/mymain/mywebapp")
|
||||
public class SpringBootTestWebEnvironmentMockWithWebAppConfigurationTests {
|
||||
class SpringBootTestWebEnvironmentMockWithWebAppConfigurationTests {
|
||||
|
||||
@Autowired
|
||||
private ServletContext servletContext;
|
||||
|
||||
@Test
|
||||
public void resourcePath() {
|
||||
void resourcePath() {
|
||||
assertThat(this.servletContext).hasFieldOrPropertyWithValue("resourceBasePath", "src/mymain/mywebapp");
|
||||
}
|
||||
|
||||
|
||||
@@ -36,13 +36,13 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
@DirtiesContext
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { "server.port=12345" })
|
||||
public class SpringBootTestWebEnvironmentRandomPortCustomPortTests {
|
||||
class SpringBootTestWebEnvironmentRandomPortCustomPortTests {
|
||||
|
||||
@Autowired
|
||||
private Environment environment;
|
||||
|
||||
@Test
|
||||
public void validatePortIsNotOverwritten() {
|
||||
void validatePortIsNotOverwritten() {
|
||||
String port = this.environment.getProperty("server.port");
|
||||
assertThat(port).isEqualTo("0");
|
||||
}
|
||||
|
||||
@@ -38,10 +38,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
@DirtiesContext
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { "value=123" })
|
||||
public class SpringBootTestWebEnvironmentRandomPortTests extends AbstractSpringBootTestWebServerWebEnvironmentTests {
|
||||
class SpringBootTestWebEnvironmentRandomPortTests extends AbstractSpringBootTestWebServerWebEnvironmentTests {
|
||||
|
||||
@Test
|
||||
public void testRestTemplateShouldUseBuilder() {
|
||||
void testRestTemplateShouldUseBuilder() {
|
||||
assertThat(getRestTemplate().getRestTemplate().getMessageConverters())
|
||||
.hasAtLeastOneElementOfType(MyConverter.class);
|
||||
}
|
||||
|
||||
@@ -34,13 +34,13 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
*/
|
||||
@DirtiesContext
|
||||
@SpringBootTest(classes = SpringBootTestWithClassesIntegrationTests.Config.class)
|
||||
public class SpringBootTestWithClassesIntegrationTests {
|
||||
class SpringBootTestWithClassesIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext context;
|
||||
|
||||
@Test
|
||||
public void injectsOnlyConfig() {
|
||||
void injectsOnlyConfig() {
|
||||
assertThat(this.context.getBean(Config.class)).isNotNull();
|
||||
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
|
||||
.isThrownBy(() -> this.context.getBean(AdditionalConfig.class));
|
||||
|
||||
@@ -37,13 +37,13 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
@DirtiesContext
|
||||
@SpringBootTest
|
||||
@ContextConfiguration(classes = SpringBootTestWithContextConfigurationIntegrationTests.Config.class)
|
||||
public class SpringBootTestWithContextConfigurationIntegrationTests {
|
||||
class SpringBootTestWithContextConfigurationIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext context;
|
||||
|
||||
@Test
|
||||
public void injectsOnlyConfig() {
|
||||
void injectsOnlyConfig() {
|
||||
assertThat(this.context.getBean(Config.class)).isNotNull();
|
||||
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
|
||||
.isThrownBy(() -> this.context.getBean(AdditionalConfig.class));
|
||||
|
||||
@@ -42,39 +42,39 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
@TestPropertySource(
|
||||
properties = { "property-source-inlined=bar", "a=property-source-inlined", "c=property-source-inlined" },
|
||||
locations = "classpath:/test-property-source-annotation.properties")
|
||||
public class SpringBootTestWithTestPropertySourceTests {
|
||||
class SpringBootTestWithTestPropertySourceTests {
|
||||
|
||||
@Autowired
|
||||
private Config config;
|
||||
|
||||
@Test
|
||||
public void propertyFromSpringBootTestProperties() {
|
||||
void propertyFromSpringBootTestProperties() {
|
||||
assertThat(this.config.bootTestInlined).isEqualTo("foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void propertyFromTestPropertySourceProperties() {
|
||||
void propertyFromTestPropertySourceProperties() {
|
||||
assertThat(this.config.propertySourceInlined).isEqualTo("bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void propertyFromTestPropertySourceLocations() {
|
||||
void propertyFromTestPropertySourceLocations() {
|
||||
assertThat(this.config.propertySourceLocation).isEqualTo("baz");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void propertyFromPropertySourcePropertiesOverridesPropertyFromPropertySourceLocations() {
|
||||
void propertyFromPropertySourcePropertiesOverridesPropertyFromPropertySourceLocations() {
|
||||
assertThat(this.config.propertySourceInlinedOverridesPropertySourceLocation)
|
||||
.isEqualTo("property-source-inlined");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void propertyFromBootTestPropertiesOverridesPropertyFromPropertySourceLocations() {
|
||||
void propertyFromBootTestPropertiesOverridesPropertyFromPropertySourceLocations() {
|
||||
assertThat(this.config.bootTestInlinedOverridesPropertySourceLocation).isEqualTo("boot-test-inlined");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void propertyFromPropertySourcePropertiesOverridesPropertyFromBootTestProperties() {
|
||||
void propertyFromPropertySourcePropertiesOverridesPropertyFromBootTestProperties() {
|
||||
assertThat(this.config.propertySourceInlinedOverridesBootTestInlined).isEqualTo("property-source-inlined");
|
||||
}
|
||||
|
||||
|
||||
@@ -30,13 +30,13 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
@DirtiesContext
|
||||
@SpringBootTest
|
||||
public class SpringBootTestXmlConventionConfigurationTests {
|
||||
class SpringBootTestXmlConventionConfigurationTests {
|
||||
|
||||
@Autowired
|
||||
private String foo;
|
||||
|
||||
@Test
|
||||
public void xmlConfigLoaded() {
|
||||
void xmlConfigLoaded() {
|
||||
assertThat(this.foo).isEqualTo("World");
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ import static org.mockito.Mockito.verify;
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class ApplicationContextAssertProviderTests {
|
||||
class ApplicationContextAssertProviderTests {
|
||||
|
||||
@Mock
|
||||
private ConfigurableApplicationContext mockContext;
|
||||
@@ -60,21 +60,21 @@ public class ApplicationContextAssertProviderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getWhenTypeIsNullShouldThrowException() {
|
||||
void getWhenTypeIsNullShouldThrowException() {
|
||||
assertThatIllegalArgumentException().isThrownBy(
|
||||
() -> ApplicationContextAssertProvider.get(null, ApplicationContext.class, this.mockContextSupplier))
|
||||
.withMessageContaining("Type must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getWhenTypeIsClassShouldThrowException() {
|
||||
void getWhenTypeIsClassShouldThrowException() {
|
||||
assertThatIllegalArgumentException().isThrownBy(
|
||||
() -> ApplicationContextAssertProvider.get(null, ApplicationContext.class, this.mockContextSupplier))
|
||||
.withMessageContaining("Type must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getWhenContextTypeIsNullShouldThrowException() {
|
||||
void getWhenContextTypeIsNullShouldThrowException() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> ApplicationContextAssertProvider.get(TestAssertProviderApplicationContextClass.class,
|
||||
ApplicationContext.class, this.mockContextSupplier))
|
||||
@@ -82,14 +82,14 @@ public class ApplicationContextAssertProviderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getWhenContextTypeIsClassShouldThrowException() {
|
||||
void getWhenContextTypeIsClassShouldThrowException() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> ApplicationContextAssertProvider
|
||||
.get(TestAssertProviderApplicationContext.class, null, this.mockContextSupplier))
|
||||
.withMessageContaining("ContextType must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getWhenSupplierIsNullShouldThrowException() {
|
||||
void getWhenSupplierIsNullShouldThrowException() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> ApplicationContextAssertProvider.get(TestAssertProviderApplicationContext.class,
|
||||
StaticApplicationContext.class, this.mockContextSupplier))
|
||||
@@ -97,7 +97,7 @@ public class ApplicationContextAssertProviderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getWhenContextStartsShouldReturnProxyThatCallsRealMethods() {
|
||||
void getWhenContextStartsShouldReturnProxyThatCallsRealMethods() {
|
||||
ApplicationContextAssertProvider<ApplicationContext> context = get(this.mockContextSupplier);
|
||||
assertThat((Object) context).isNotNull();
|
||||
context.getBean("foo");
|
||||
@@ -105,7 +105,7 @@ public class ApplicationContextAssertProviderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getWhenContextFailsShouldReturnProxyThatThrowsExceptions() {
|
||||
void getWhenContextFailsShouldReturnProxyThatThrowsExceptions() {
|
||||
ApplicationContextAssertProvider<ApplicationContext> context = get(this.startupFailureSupplier);
|
||||
assertThat((Object) context).isNotNull();
|
||||
assertThatIllegalStateException().isThrownBy(() -> context.getBean("foo")).withCause(this.startupFailure)
|
||||
@@ -113,26 +113,26 @@ public class ApplicationContextAssertProviderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSourceContextWhenContextStartsShouldReturnSourceContext() {
|
||||
void getSourceContextWhenContextStartsShouldReturnSourceContext() {
|
||||
ApplicationContextAssertProvider<ApplicationContext> context = get(this.mockContextSupplier);
|
||||
assertThat(context.getSourceApplicationContext()).isSameAs(this.mockContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSourceContextWhenContextFailsShouldThrowException() {
|
||||
void getSourceContextWhenContextFailsShouldThrowException() {
|
||||
ApplicationContextAssertProvider<ApplicationContext> context = get(this.startupFailureSupplier);
|
||||
assertThatIllegalStateException().isThrownBy(context::getSourceApplicationContext)
|
||||
.withCause(this.startupFailure).withMessageContaining("failed to start");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSourceContextOfTypeWhenContextStartsShouldReturnSourceContext() {
|
||||
void getSourceContextOfTypeWhenContextStartsShouldReturnSourceContext() {
|
||||
ApplicationContextAssertProvider<ApplicationContext> context = get(this.mockContextSupplier);
|
||||
assertThat(context.getSourceApplicationContext(ApplicationContext.class)).isSameAs(this.mockContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSourceContextOfTypeWhenContextFailsToStartShouldThrowException() {
|
||||
void getSourceContextOfTypeWhenContextFailsToStartShouldThrowException() {
|
||||
ApplicationContextAssertProvider<ApplicationContext> context = get(this.startupFailureSupplier);
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> context.getSourceApplicationContext(ApplicationContext.class))
|
||||
@@ -140,19 +140,19 @@ public class ApplicationContextAssertProviderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getStartupFailureWhenContextStartsShouldReturnNull() {
|
||||
void getStartupFailureWhenContextStartsShouldReturnNull() {
|
||||
ApplicationContextAssertProvider<ApplicationContext> context = get(this.mockContextSupplier);
|
||||
assertThat(context.getStartupFailure()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getStartupFailureWhenContextFailsToStartShouldReturnException() {
|
||||
void getStartupFailureWhenContextFailsToStartShouldReturnException() {
|
||||
ApplicationContextAssertProvider<ApplicationContext> context = get(this.startupFailureSupplier);
|
||||
assertThat(context.getStartupFailure()).isEqualTo(this.startupFailure);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void assertThatWhenContextStartsShouldReturnAssertions() {
|
||||
void assertThatWhenContextStartsShouldReturnAssertions() {
|
||||
ApplicationContextAssertProvider<ApplicationContext> context = get(this.mockContextSupplier);
|
||||
ApplicationContextAssert<ApplicationContext> contextAssert = assertThat(context);
|
||||
assertThat(contextAssert.getApplicationContext()).isSameAs(context);
|
||||
@@ -160,7 +160,7 @@ public class ApplicationContextAssertProviderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void assertThatWhenContextFailsShouldReturnAssertions() {
|
||||
void assertThatWhenContextFailsShouldReturnAssertions() {
|
||||
ApplicationContextAssertProvider<ApplicationContext> context = get(this.startupFailureSupplier);
|
||||
ApplicationContextAssert<ApplicationContext> contextAssert = assertThat(context);
|
||||
assertThat(contextAssert.getApplicationContext()).isSameAs(context);
|
||||
@@ -168,21 +168,21 @@ public class ApplicationContextAssertProviderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toStringWhenContextStartsShouldReturnSimpleString() {
|
||||
void toStringWhenContextStartsShouldReturnSimpleString() {
|
||||
ApplicationContextAssertProvider<ApplicationContext> context = get(this.mockContextSupplier);
|
||||
assertThat(context.toString()).startsWith("Started application [ConfigurableApplicationContext.MockitoMock")
|
||||
.endsWith("id = [null], applicationName = [null], beanDefinitionCount = 0]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toStringWhenContextFailsToStartShouldReturnSimpleString() {
|
||||
void toStringWhenContextFailsToStartShouldReturnSimpleString() {
|
||||
ApplicationContextAssertProvider<ApplicationContext> context = get(this.startupFailureSupplier);
|
||||
assertThat(context.toString()).isEqualTo("Unstarted application context "
|
||||
+ "org.springframework.context.ApplicationContext" + "[startupFailure=java.lang.RuntimeException]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void closeShouldCloseContext() {
|
||||
void closeShouldCloseContext() {
|
||||
ApplicationContextAssertProvider<ApplicationContext> context = get(this.mockContextSupplier);
|
||||
context.close();
|
||||
verify(this.mockContext).close();
|
||||
|
||||
@@ -38,7 +38,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
|
||||
* @author Phillip Webb
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class ApplicationContextAssertTests {
|
||||
class ApplicationContextAssertTests {
|
||||
|
||||
private StaticApplicationContext parent;
|
||||
|
||||
@@ -60,56 +60,56 @@ public class ApplicationContextAssertTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWhenApplicationContextIsNullShouldThrowException() {
|
||||
void createWhenApplicationContextIsNullShouldThrowException() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new ApplicationContextAssert<>(null, null))
|
||||
.withMessageContaining("ApplicationContext must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWhenHasApplicationContextShouldSetActual() {
|
||||
void createWhenHasApplicationContextShouldSetActual() {
|
||||
assertThat(getAssert(this.context).getSourceApplicationContext()).isSameAs(this.context);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWhenHasExceptionShouldSetFailure() {
|
||||
void createWhenHasExceptionShouldSetFailure() {
|
||||
assertThat(getAssert(this.failure)).getFailure().isSameAs(this.failure);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasBeanWhenHasBeanShouldPass() {
|
||||
void hasBeanWhenHasBeanShouldPass() {
|
||||
this.context.registerSingleton("foo", Foo.class);
|
||||
assertThat(getAssert(this.context)).hasBean("foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasBeanWhenHasNoBeanShouldFail() {
|
||||
void hasBeanWhenHasNoBeanShouldFail() {
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(getAssert(this.context)).hasBean("foo"))
|
||||
.withMessageContaining("no such bean");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasBeanWhenNotStartedShouldFail() {
|
||||
void hasBeanWhenNotStartedShouldFail() {
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(getAssert(this.failure)).hasBean("foo"))
|
||||
.withMessageContaining(String.format("but context failed to start:%n java.lang.RuntimeException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasSingleBeanWhenHasSingleBeanShouldPass() {
|
||||
void hasSingleBeanWhenHasSingleBeanShouldPass() {
|
||||
this.context.registerSingleton("foo", Foo.class);
|
||||
assertThat(getAssert(this.context)).hasSingleBean(Foo.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasSingleBeanWhenHasNoBeansShouldFail() {
|
||||
void hasSingleBeanWhenHasNoBeansShouldFail() {
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(getAssert(this.context)).hasSingleBean(Foo.class))
|
||||
.withMessageContaining("to have a single bean of type");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasSingleBeanWhenHasMultipleShouldFail() {
|
||||
void hasSingleBeanWhenHasMultipleShouldFail() {
|
||||
this.context.registerSingleton("foo", Foo.class);
|
||||
this.context.registerSingleton("bar", Foo.class);
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
@@ -118,7 +118,7 @@ public class ApplicationContextAssertTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasSingleBeanWhenFailedToStartShouldFail() {
|
||||
void hasSingleBeanWhenFailedToStartShouldFail() {
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(getAssert(this.failure)).hasSingleBean(Foo.class))
|
||||
.withMessageContaining("to have a single bean of type")
|
||||
@@ -126,7 +126,7 @@ public class ApplicationContextAssertTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasSingleBeanWhenInParentShouldFail() {
|
||||
void hasSingleBeanWhenInParentShouldFail() {
|
||||
this.parent.registerSingleton("foo", Foo.class);
|
||||
this.context.registerSingleton("bar", Foo.class);
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
@@ -135,19 +135,19 @@ public class ApplicationContextAssertTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasSingleBeanWithLimitedScopeWhenInParentShouldPass() {
|
||||
void hasSingleBeanWithLimitedScopeWhenInParentShouldPass() {
|
||||
this.parent.registerSingleton("foo", Foo.class);
|
||||
this.context.registerSingleton("bar", Foo.class);
|
||||
assertThat(getAssert(this.context)).hasSingleBean(Foo.class, Scope.NO_ANCESTORS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doesNotHaveBeanOfTypeWhenHasNoBeanOfTypeShouldPass() {
|
||||
void doesNotHaveBeanOfTypeWhenHasNoBeanOfTypeShouldPass() {
|
||||
assertThat(getAssert(this.context)).doesNotHaveBean(Foo.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doesNotHaveBeanOfTypeWhenHasBeanOfTypeShouldFail() {
|
||||
void doesNotHaveBeanOfTypeWhenHasBeanOfTypeShouldFail() {
|
||||
this.context.registerSingleton("foo", Foo.class);
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(getAssert(this.context)).doesNotHaveBean(Foo.class))
|
||||
@@ -155,7 +155,7 @@ public class ApplicationContextAssertTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doesNotHaveBeanOfTypeWhenFailedToStartShouldFail() {
|
||||
void doesNotHaveBeanOfTypeWhenFailedToStartShouldFail() {
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(getAssert(this.failure)).doesNotHaveBean(Foo.class))
|
||||
.withMessageContaining("not to have any beans of type")
|
||||
@@ -163,7 +163,7 @@ public class ApplicationContextAssertTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doesNotHaveBeanOfTypeWhenInParentShouldFail() {
|
||||
void doesNotHaveBeanOfTypeWhenInParentShouldFail() {
|
||||
this.parent.registerSingleton("foo", Foo.class);
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(getAssert(this.context)).doesNotHaveBean(Foo.class))
|
||||
@@ -171,18 +171,18 @@ public class ApplicationContextAssertTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doesNotHaveBeanOfTypeWithLimitedScopeWhenInParentShouldPass() {
|
||||
void doesNotHaveBeanOfTypeWithLimitedScopeWhenInParentShouldPass() {
|
||||
this.parent.registerSingleton("foo", Foo.class);
|
||||
assertThat(getAssert(this.context)).doesNotHaveBean(Foo.class, Scope.NO_ANCESTORS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doesNotHaveBeanOfNameWhenHasNoBeanOfTypeShouldPass() {
|
||||
void doesNotHaveBeanOfNameWhenHasNoBeanOfTypeShouldPass() {
|
||||
assertThat(getAssert(this.context)).doesNotHaveBean("foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doesNotHaveBeanOfNameWhenHasBeanOfTypeShouldFail() {
|
||||
void doesNotHaveBeanOfNameWhenHasBeanOfTypeShouldFail() {
|
||||
this.context.registerSingleton("foo", Foo.class);
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(getAssert(this.context)).doesNotHaveBean("foo"))
|
||||
@@ -190,26 +190,26 @@ public class ApplicationContextAssertTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doesNotHaveBeanOfNameWhenFailedToStartShouldFail() {
|
||||
void doesNotHaveBeanOfNameWhenFailedToStartShouldFail() {
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(getAssert(this.failure)).doesNotHaveBean("foo"))
|
||||
.withMessageContaining("not to have any beans of name").withMessageContaining("failed to start");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBeanNamesWhenHasNamesShouldReturnNamesAssert() {
|
||||
void getBeanNamesWhenHasNamesShouldReturnNamesAssert() {
|
||||
this.context.registerSingleton("foo", Foo.class);
|
||||
this.context.registerSingleton("bar", Foo.class);
|
||||
assertThat(getAssert(this.context)).getBeanNames(Foo.class).containsOnly("foo", "bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBeanNamesWhenHasNoNamesShouldReturnEmptyAssert() {
|
||||
void getBeanNamesWhenHasNoNamesShouldReturnEmptyAssert() {
|
||||
assertThat(getAssert(this.context)).getBeanNames(Foo.class).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBeanNamesWhenFailedToStartShouldFail() {
|
||||
void getBeanNamesWhenFailedToStartShouldFail() {
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(getAssert(this.failure)).doesNotHaveBean("foo"))
|
||||
.withMessageContaining("not to have any beans of name")
|
||||
@@ -217,18 +217,18 @@ public class ApplicationContextAssertTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBeanOfTypeWhenHasBeanShouldReturnBeanAssert() {
|
||||
void getBeanOfTypeWhenHasBeanShouldReturnBeanAssert() {
|
||||
this.context.registerSingleton("foo", Foo.class);
|
||||
assertThat(getAssert(this.context)).getBean(Foo.class).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBeanOfTypeWhenHasNoBeanShouldReturnNullAssert() {
|
||||
void getBeanOfTypeWhenHasNoBeanShouldReturnNullAssert() {
|
||||
assertThat(getAssert(this.context)).getBean(Foo.class).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBeanOfTypeWhenHasMultipleBeansShouldFail() {
|
||||
void getBeanOfTypeWhenHasMultipleBeansShouldFail() {
|
||||
this.context.registerSingleton("foo", Foo.class);
|
||||
this.context.registerSingleton("bar", Foo.class);
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
@@ -237,14 +237,14 @@ public class ApplicationContextAssertTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBeanOfTypeWhenHasPrimaryBeanShouldReturnPrimary() {
|
||||
void getBeanOfTypeWhenHasPrimaryBeanShouldReturnPrimary() {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(PrimaryFooConfig.class);
|
||||
assertThat(getAssert(context)).getBean(Foo.class).isInstanceOf(Bar.class);
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBeanOfTypeWhenFailedToStartShouldFail() {
|
||||
void getBeanOfTypeWhenFailedToStartShouldFail() {
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(getAssert(this.failure)).getBean(Foo.class))
|
||||
.withMessageContaining("to contain bean of type")
|
||||
@@ -252,19 +252,19 @@ public class ApplicationContextAssertTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBeanOfTypeWhenInParentShouldReturnBeanAssert() {
|
||||
void getBeanOfTypeWhenInParentShouldReturnBeanAssert() {
|
||||
this.parent.registerSingleton("foo", Foo.class);
|
||||
assertThat(getAssert(this.context)).getBean(Foo.class).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBeanOfTypeWhenInParentWithLimitedScopeShouldReturnNullAssert() {
|
||||
void getBeanOfTypeWhenInParentWithLimitedScopeShouldReturnNullAssert() {
|
||||
this.parent.registerSingleton("foo", Foo.class);
|
||||
assertThat(getAssert(this.context)).getBean(Foo.class, Scope.NO_ANCESTORS).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBeanOfTypeWhenHasMultipleBeansIncludingParentShouldFail() {
|
||||
void getBeanOfTypeWhenHasMultipleBeansIncludingParentShouldFail() {
|
||||
this.parent.registerSingleton("foo", Foo.class);
|
||||
this.context.registerSingleton("bar", Foo.class);
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
@@ -273,25 +273,25 @@ public class ApplicationContextAssertTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBeanOfTypeWithLimitedScopeWhenHasMultipleBeansIncludingParentShouldReturnBeanAssert() {
|
||||
void getBeanOfTypeWithLimitedScopeWhenHasMultipleBeansIncludingParentShouldReturnBeanAssert() {
|
||||
this.parent.registerSingleton("foo", Foo.class);
|
||||
this.context.registerSingleton("bar", Foo.class);
|
||||
assertThat(getAssert(this.context)).getBean(Foo.class, Scope.NO_ANCESTORS).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBeanOfNameWhenHasBeanShouldReturnBeanAssert() {
|
||||
void getBeanOfNameWhenHasBeanShouldReturnBeanAssert() {
|
||||
this.context.registerSingleton("foo", Foo.class);
|
||||
assertThat(getAssert(this.context)).getBean("foo").isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBeanOfNameWhenHasNoBeanOfNameShouldReturnNullAssert() {
|
||||
void getBeanOfNameWhenHasNoBeanOfNameShouldReturnNullAssert() {
|
||||
assertThat(getAssert(this.context)).getBean("foo").isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBeanOfNameWhenFailedToStartShouldFail() {
|
||||
void getBeanOfNameWhenFailedToStartShouldFail() {
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(getAssert(this.failure)).getBean("foo"))
|
||||
.withMessageContaining("to contain a bean of name")
|
||||
@@ -299,18 +299,18 @@ public class ApplicationContextAssertTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBeanOfNameAndTypeWhenHasBeanShouldReturnBeanAssert() {
|
||||
void getBeanOfNameAndTypeWhenHasBeanShouldReturnBeanAssert() {
|
||||
this.context.registerSingleton("foo", Foo.class);
|
||||
assertThat(getAssert(this.context)).getBean("foo", Foo.class).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBeanOfNameAndTypeWhenHasNoBeanOfNameShouldReturnNullAssert() {
|
||||
void getBeanOfNameAndTypeWhenHasNoBeanOfNameShouldReturnNullAssert() {
|
||||
assertThat(getAssert(this.context)).getBean("foo", Foo.class).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBeanOfNameAndTypeWhenHasNoBeanOfNameButDifferentTypeShouldFail() {
|
||||
void getBeanOfNameAndTypeWhenHasNoBeanOfNameButDifferentTypeShouldFail() {
|
||||
this.context.registerSingleton("foo", Foo.class);
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(getAssert(this.context)).getBean("foo", String.class))
|
||||
@@ -318,7 +318,7 @@ public class ApplicationContextAssertTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBeanOfNameAndTypeWhenFailedToStartShouldFail() {
|
||||
void getBeanOfNameAndTypeWhenFailedToStartShouldFail() {
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(getAssert(this.failure)).getBean("foo", Foo.class))
|
||||
.withMessageContaining("to contain a bean of name")
|
||||
@@ -326,19 +326,19 @@ public class ApplicationContextAssertTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBeansWhenHasBeansShouldReturnMapAssert() {
|
||||
void getBeansWhenHasBeansShouldReturnMapAssert() {
|
||||
this.context.registerSingleton("foo", Foo.class);
|
||||
this.context.registerSingleton("bar", Foo.class);
|
||||
assertThat(getAssert(this.context)).getBeans(Foo.class).hasSize(2).containsKeys("foo", "bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBeansWhenHasNoBeansShouldReturnEmptyMapAssert() {
|
||||
void getBeansWhenHasNoBeansShouldReturnEmptyMapAssert() {
|
||||
assertThat(getAssert(this.context)).getBeans(Foo.class).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBeansWhenFailedToStartShouldFail() {
|
||||
void getBeansWhenFailedToStartShouldFail() {
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(getAssert(this.failure)).getBeans(Foo.class))
|
||||
.withMessageContaining("to get beans of type")
|
||||
@@ -346,45 +346,45 @@ public class ApplicationContextAssertTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBeansShouldIncludeBeansFromParentScope() {
|
||||
void getBeansShouldIncludeBeansFromParentScope() {
|
||||
this.parent.registerSingleton("foo", Foo.class);
|
||||
this.context.registerSingleton("bar", Foo.class);
|
||||
assertThat(getAssert(this.context)).getBeans(Foo.class).hasSize(2).containsKeys("foo", "bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBeansWithLimitedScopeShouldNotIncludeBeansFromParentScope() {
|
||||
void getBeansWithLimitedScopeShouldNotIncludeBeansFromParentScope() {
|
||||
this.parent.registerSingleton("foo", Foo.class);
|
||||
this.context.registerSingleton("bar", Foo.class);
|
||||
assertThat(getAssert(this.context)).getBeans(Foo.class, Scope.NO_ANCESTORS).hasSize(1).containsKeys("bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getFailureWhenFailedShouldReturnFailure() {
|
||||
void getFailureWhenFailedShouldReturnFailure() {
|
||||
assertThat(getAssert(this.failure)).getFailure().isSameAs(this.failure);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getFailureWhenDidNotFailShouldFail() {
|
||||
void getFailureWhenDidNotFailShouldFail() {
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(getAssert(this.context)).getFailure())
|
||||
.withMessageContaining("context started");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasFailedWhenFailedShouldPass() {
|
||||
void hasFailedWhenFailedShouldPass() {
|
||||
assertThat(getAssert(this.failure)).hasFailed();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasFailedWhenNotFailedShouldFail() {
|
||||
void hasFailedWhenNotFailedShouldFail() {
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(getAssert(this.context)).hasFailed())
|
||||
.withMessageContaining("to have failed");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasNotFailedWhenFailedShouldFail() {
|
||||
void hasNotFailedWhenFailedShouldFail() {
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(getAssert(this.failure)).hasNotFailed())
|
||||
.withMessageContaining("to have not failed")
|
||||
@@ -392,7 +392,7 @@ public class ApplicationContextAssertTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasNotFailedWhenNotFailedShouldPass() {
|
||||
void hasNotFailedWhenNotFailedShouldPass() {
|
||||
assertThat(getAssert(this.context)).hasNotFailed();
|
||||
}
|
||||
|
||||
|
||||
@@ -29,10 +29,10 @@ import static org.mockito.Mockito.mock;
|
||||
* @author Phillip Webb
|
||||
* @see ApplicationContextAssertProviderTests
|
||||
*/
|
||||
public class AssertableApplicationContextTests {
|
||||
class AssertableApplicationContextTests {
|
||||
|
||||
@Test
|
||||
public void getShouldReturnProxy() {
|
||||
void getShouldReturnProxy() {
|
||||
AssertableApplicationContext context = AssertableApplicationContext
|
||||
.get(() -> mock(ConfigurableApplicationContext.class));
|
||||
assertThat(context).isInstanceOf(ConfigurableApplicationContext.class);
|
||||
|
||||
@@ -29,10 +29,10 @@ import static org.mockito.Mockito.mock;
|
||||
* @author Phillip Webb
|
||||
* @see ApplicationContextAssertProviderTests
|
||||
*/
|
||||
public class AssertableReactiveWebApplicationContextTests {
|
||||
class AssertableReactiveWebApplicationContextTests {
|
||||
|
||||
@Test
|
||||
public void getShouldReturnProxy() {
|
||||
void getShouldReturnProxy() {
|
||||
AssertableReactiveWebApplicationContext context = AssertableReactiveWebApplicationContext
|
||||
.get(() -> mock(ConfigurableReactiveWebApplicationContext.class));
|
||||
assertThat(context).isInstanceOf(ConfigurableReactiveWebApplicationContext.class);
|
||||
|
||||
@@ -29,10 +29,10 @@ import static org.mockito.Mockito.mock;
|
||||
* @author Phillip Webb
|
||||
* @see ApplicationContextAssertProviderTests
|
||||
*/
|
||||
public class AssertableWebApplicationContextTests {
|
||||
class AssertableWebApplicationContextTests {
|
||||
|
||||
@Test
|
||||
public void getShouldReturnProxy() {
|
||||
void getShouldReturnProxy() {
|
||||
AssertableWebApplicationContext context = AssertableWebApplicationContext
|
||||
.get(() -> mock(ConfigurableWebApplicationContext.class));
|
||||
assertThat(context).isInstanceOf(ConfigurableWebApplicationContext.class);
|
||||
|
||||
@@ -37,7 +37,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@BootstrapWith(SpringBootTestContextBootstrapper.class)
|
||||
public class SpringBootTestContextBootstrapperIntegrationTests {
|
||||
class SpringBootTestContextBootstrapperIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext context;
|
||||
@@ -48,22 +48,22 @@ public class SpringBootTestContextBootstrapperIntegrationTests {
|
||||
boolean defaultTestExecutionListenersPostProcessorCalled = false;
|
||||
|
||||
@Test
|
||||
public void findConfigAutomatically() {
|
||||
void findConfigAutomatically() {
|
||||
assertThat(this.config).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void contextWasCreatedViaSpringApplication() {
|
||||
void contextWasCreatedViaSpringApplication() {
|
||||
assertThat(this.context.getId()).startsWith("application");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConfigurationWasApplied() {
|
||||
void testConfigurationWasApplied() {
|
||||
assertThat(this.context.getBean(ExampleBean.class)).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultTestExecutionListenersPostProcessorShouldBeCalled() {
|
||||
void defaultTestExecutionListenersPostProcessorShouldBeCalled() {
|
||||
assertThat(this.defaultTestExecutionListenersPostProcessorCalled).isTrue();
|
||||
}
|
||||
|
||||
|
||||
@@ -34,10 +34,10 @@ import static org.mockito.Mockito.mock;
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class SpringBootTestContextBootstrapperTests {
|
||||
class SpringBootTestContextBootstrapperTests {
|
||||
|
||||
@Test
|
||||
public void springBootTestWithANonMockWebEnvironmentAndWebAppConfigurationFailsFast() {
|
||||
void springBootTestWithANonMockWebEnvironmentAndWebAppConfigurationFailsFast() {
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> buildTestContext(SpringBootTestNonMockWebEnvironmentAndWebAppConfiguration.class))
|
||||
.withMessageContaining("@WebAppConfiguration should only be used with "
|
||||
@@ -46,7 +46,7 @@ public class SpringBootTestContextBootstrapperTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void springBootTestWithAMockWebEnvironmentCanBeUsedWithWebAppConfiguration() {
|
||||
void springBootTestWithAMockWebEnvironmentCanBeUsedWithWebAppConfiguration() {
|
||||
buildTestContext(SpringBootTestMockWebEnvironmentAndWebAppConfiguration.class);
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@BootstrapWith(SpringBootTestContextBootstrapper.class)
|
||||
@ContextConfiguration
|
||||
public class SpringBootTestContextBootstrapperWithContextConfigurationTests {
|
||||
class SpringBootTestContextBootstrapperWithContextConfigurationTests {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext context;
|
||||
@@ -46,12 +46,12 @@ public class SpringBootTestContextBootstrapperWithContextConfigurationTests {
|
||||
private SpringBootTestContextBootstrapperExampleConfig config;
|
||||
|
||||
@Test
|
||||
public void findConfigAutomatically() {
|
||||
void findConfigAutomatically() {
|
||||
assertThat(this.config).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void contextWasCreatedViaSpringApplication() {
|
||||
void contextWasCreatedViaSpringApplication() {
|
||||
assertThat(this.context.getId()).startsWith("application");
|
||||
}
|
||||
|
||||
|
||||
@@ -40,13 +40,13 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@BootstrapWith(SpringBootTestContextBootstrapper.class)
|
||||
@ContextConfiguration(initializers = CustomInitializer.class)
|
||||
public class SpringBootTestContextBootstrapperWithInitializersTests {
|
||||
class SpringBootTestContextBootstrapperWithInitializersTests {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext context;
|
||||
|
||||
@Test
|
||||
public void foundConfiguration() {
|
||||
void foundConfiguration() {
|
||||
Object bean = this.context.getBean(SpringBootTestContextBootstrapperExampleConfig.class);
|
||||
assertThat(bean).isNotNull();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,10 +17,9 @@
|
||||
package org.springframework.boot.test.context.example;
|
||||
|
||||
import org.springframework.boot.SpringBootConfiguration;
|
||||
import org.springframework.boot.test.context.AnnotatedClassFinderTests;
|
||||
|
||||
/**
|
||||
* Example config used in {@link AnnotatedClassFinderTests}.
|
||||
* Example config used in {@code AnnotatedClassFinderTests}.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,10 +16,8 @@
|
||||
|
||||
package org.springframework.boot.test.context.example.scan;
|
||||
|
||||
import org.springframework.boot.test.context.AnnotatedClassFinderTests;
|
||||
|
||||
/**
|
||||
* Example class used in {@link AnnotatedClassFinderTests}.
|
||||
* Example class used in {@code AnnotatedClassFinderTests}.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,10 +17,9 @@
|
||||
package org.springframework.boot.test.context.example.scan.sub;
|
||||
|
||||
import org.springframework.boot.SpringBootConfiguration;
|
||||
import org.springframework.boot.test.context.AnnotatedClassFinderTests;
|
||||
|
||||
/**
|
||||
* Example config used in {@link AnnotatedClassFinderTests}. Should not be found since
|
||||
* Example config used in {@code AnnotatedClassFinderTests}. Should not be found since
|
||||
* scanner should only search upwards.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
|
||||
@@ -18,10 +18,10 @@ package org.springframework.boot.test.context.filter;
|
||||
|
||||
import org.junit.jupiter.api.RepeatedTest;
|
||||
|
||||
public class JupiterRepeatedTestExample {
|
||||
class JupiterRepeatedTestExample {
|
||||
|
||||
@RepeatedTest(5)
|
||||
public void repeatedTest() {
|
||||
void repeatedTest() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -18,10 +18,10 @@ package org.springframework.boot.test.context.filter;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class JupiterTestExample {
|
||||
class JupiterTestExample {
|
||||
|
||||
@Test
|
||||
public void repeatedTest() {
|
||||
void repeatedTest() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -23,10 +23,10 @@ import org.junit.jupiter.api.DynamicNode;
|
||||
import org.junit.jupiter.api.DynamicTest;
|
||||
import org.junit.jupiter.api.TestFactory;
|
||||
|
||||
public class JupiterTestFactoryExample {
|
||||
class JupiterTestFactoryExample {
|
||||
|
||||
@TestFactory
|
||||
public Collection<DynamicNode> testFactory() {
|
||||
Collection<DynamicNode> testFactory() {
|
||||
return Arrays.asList(DynamicTest.dynamicTest("Some dynamic test", () -> {
|
||||
// Test
|
||||
}));
|
||||
|
||||
@@ -33,64 +33,64 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Phillip Webb
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class TestTypeExcludeFilterTests {
|
||||
class TestTypeExcludeFilterTests {
|
||||
|
||||
private TestTypeExcludeFilter filter = new TestTypeExcludeFilter();
|
||||
|
||||
private MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
|
||||
|
||||
@Test
|
||||
public void matchesJUnit4TestClass() throws Exception {
|
||||
void matchesJUnit4TestClass() throws Exception {
|
||||
assertThat(this.filter.match(getMetadataReader(TestTypeExcludeFilterTests.class), this.metadataReaderFactory))
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchesJUnitJupiterTestClass() throws Exception {
|
||||
void matchesJUnitJupiterTestClass() throws Exception {
|
||||
assertThat(this.filter.match(getMetadataReader(JupiterTestExample.class), this.metadataReaderFactory)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchesJUnitJupiterRepeatedTestClass() throws Exception {
|
||||
void matchesJUnitJupiterRepeatedTestClass() throws Exception {
|
||||
assertThat(this.filter.match(getMetadataReader(JupiterRepeatedTestExample.class), this.metadataReaderFactory))
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchesJUnitJupiterTestFactoryClass() throws Exception {
|
||||
void matchesJUnitJupiterTestFactoryClass() throws Exception {
|
||||
assertThat(this.filter.match(getMetadataReader(JupiterTestFactoryExample.class), this.metadataReaderFactory))
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchesNestedConfiguration() throws Exception {
|
||||
void matchesNestedConfiguration() throws Exception {
|
||||
assertThat(this.filter.match(getMetadataReader(NestedConfig.class), this.metadataReaderFactory)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchesNestedConfigurationClassWithoutTestMethodsIfItHasRunWith() throws Exception {
|
||||
void matchesNestedConfigurationClassWithoutTestMethodsIfItHasRunWith() throws Exception {
|
||||
assertThat(this.filter.match(getMetadataReader(AbstractTestWithConfigAndRunWith.Config.class),
|
||||
this.metadataReaderFactory)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchesNestedConfigurationClassWithoutTestMethodsIfItHasExtendWith() throws Exception {
|
||||
void matchesNestedConfigurationClassWithoutTestMethodsIfItHasExtendWith() throws Exception {
|
||||
assertThat(this.filter.match(getMetadataReader(AbstractJupiterTestWithConfigAndExtendWith.Config.class),
|
||||
this.metadataReaderFactory)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchesTestConfiguration() throws Exception {
|
||||
void matchesTestConfiguration() throws Exception {
|
||||
assertThat(this.filter.match(getMetadataReader(SampleTestConfig.class), this.metadataReaderFactory)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doesNotMatchRegularConfiguration() throws Exception {
|
||||
void doesNotMatchRegularConfiguration() throws Exception {
|
||||
assertThat(this.filter.match(getMetadataReader(SampleConfig.class), this.metadataReaderFactory)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchesNestedConfigurationClassWithoutTestNgAnnotation() throws Exception {
|
||||
void matchesNestedConfigurationClassWithoutTestNgAnnotation() throws Exception {
|
||||
assertThat(this.filter.match(getMetadataReader(AbstractTestNgTestWithConfig.Config.class),
|
||||
this.metadataReaderFactory)).isTrue();
|
||||
}
|
||||
|
||||
@@ -49,10 +49,10 @@ import static org.assertj.core.api.Assertions.assertThatIOException;
|
||||
* @author Stephane Nicoll
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public abstract class AbstractApplicationContextRunnerTests<T extends AbstractApplicationContextRunner<T, C, A>, C extends ConfigurableApplicationContext, A extends ApplicationContextAssertProvider<C>> {
|
||||
abstract class AbstractApplicationContextRunnerTests<T extends AbstractApplicationContextRunner<T, C, A>, C extends ConfigurableApplicationContext, A extends ApplicationContextAssertProvider<C>> {
|
||||
|
||||
@Test
|
||||
public void runWithInitializerShouldInitialize() {
|
||||
void runWithInitializerShouldInitialize() {
|
||||
AtomicBoolean called = new AtomicBoolean();
|
||||
get().withInitializer((context) -> called.set(true)).run((context) -> {
|
||||
});
|
||||
@@ -60,7 +60,7 @@ public abstract class AbstractApplicationContextRunnerTests<T extends AbstractAp
|
||||
}
|
||||
|
||||
@Test
|
||||
public void runWithSystemPropertiesShouldSetAndRemoveProperties() {
|
||||
void runWithSystemPropertiesShouldSetAndRemoveProperties() {
|
||||
String key = "test." + UUID.randomUUID();
|
||||
assertThat(System.getProperties().containsKey(key)).isFalse();
|
||||
get().withSystemProperties(key + "=value")
|
||||
@@ -69,7 +69,7 @@ public abstract class AbstractApplicationContextRunnerTests<T extends AbstractAp
|
||||
}
|
||||
|
||||
@Test
|
||||
public void runWithSystemPropertiesWhenContextFailsShouldRemoveProperties() {
|
||||
void runWithSystemPropertiesWhenContextFailsShouldRemoveProperties() {
|
||||
String key = "test." + UUID.randomUUID();
|
||||
assertThat(System.getProperties().containsKey(key)).isFalse();
|
||||
get().withSystemProperties(key + "=value").withUserConfiguration(FailingConfig.class)
|
||||
@@ -78,7 +78,7 @@ public abstract class AbstractApplicationContextRunnerTests<T extends AbstractAp
|
||||
}
|
||||
|
||||
@Test
|
||||
public void runWithSystemPropertiesShouldRestoreOriginalProperties() {
|
||||
void runWithSystemPropertiesShouldRestoreOriginalProperties() {
|
||||
String key = "test." + UUID.randomUUID();
|
||||
System.setProperty(key, "value");
|
||||
try {
|
||||
@@ -93,7 +93,7 @@ public abstract class AbstractApplicationContextRunnerTests<T extends AbstractAp
|
||||
}
|
||||
|
||||
@Test
|
||||
public void runWithSystemPropertiesWhenValueIsNullShouldRemoveProperty() {
|
||||
void runWithSystemPropertiesWhenValueIsNullShouldRemoveProperty() {
|
||||
String key = "test." + UUID.randomUUID();
|
||||
System.setProperty(key, "value");
|
||||
try {
|
||||
@@ -108,7 +108,7 @@ public abstract class AbstractApplicationContextRunnerTests<T extends AbstractAp
|
||||
}
|
||||
|
||||
@Test
|
||||
public void runWithMultiplePropertyValuesShouldAllAllValues() {
|
||||
void runWithMultiplePropertyValuesShouldAllAllValues() {
|
||||
get().withPropertyValues("test.foo=1").withPropertyValues("test.bar=2").run((context) -> {
|
||||
Environment environment = context.getEnvironment();
|
||||
assertThat(environment.getProperty("test.foo")).isEqualTo("1");
|
||||
@@ -117,7 +117,7 @@ public abstract class AbstractApplicationContextRunnerTests<T extends AbstractAp
|
||||
}
|
||||
|
||||
@Test
|
||||
public void runWithPropertyValuesWhenHasExistingShouldReplaceValue() {
|
||||
void runWithPropertyValuesWhenHasExistingShouldReplaceValue() {
|
||||
get().withPropertyValues("test.foo=1").withPropertyValues("test.foo=2").run((context) -> {
|
||||
Environment environment = context.getEnvironment();
|
||||
assertThat(environment.getProperty("test.foo")).isEqualTo("2");
|
||||
@@ -125,22 +125,22 @@ public abstract class AbstractApplicationContextRunnerTests<T extends AbstractAp
|
||||
}
|
||||
|
||||
@Test
|
||||
public void runWithConfigurationsShouldRegisterConfigurations() {
|
||||
void runWithConfigurationsShouldRegisterConfigurations() {
|
||||
get().withUserConfiguration(FooConfig.class).run((context) -> assertThat(context).hasBean("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void runWithUserNamedBeanShouldRegisterBean() {
|
||||
void runWithUserNamedBeanShouldRegisterBean() {
|
||||
get().withBean("foo", String.class, () -> "foo").run((context) -> assertThat(context).hasBean("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void runWithUserBeanShouldRegisterBeanWithDefaultName() {
|
||||
void runWithUserBeanShouldRegisterBeanWithDefaultName() {
|
||||
get().withBean(String.class, () -> "foo").run((context) -> assertThat(context).hasBean("string"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void runWithUserBeanShouldBeRegisteredInOrder() {
|
||||
void runWithUserBeanShouldBeRegisteredInOrder() {
|
||||
get().withBean(String.class, () -> "one").withBean(String.class, () -> "two")
|
||||
.withBean(String.class, () -> "three").run((context) -> {
|
||||
assertThat(context).hasBean("string");
|
||||
@@ -149,7 +149,7 @@ public abstract class AbstractApplicationContextRunnerTests<T extends AbstractAp
|
||||
}
|
||||
|
||||
@Test
|
||||
public void runWithConfigurationsAndUserBeanShouldRegisterUserBeanLast() {
|
||||
void runWithConfigurationsAndUserBeanShouldRegisterUserBeanLast() {
|
||||
get().withUserConfiguration(FooConfig.class).withBean("foo", String.class, () -> "overridden")
|
||||
.run((context) -> {
|
||||
assertThat(context).hasBean("foo");
|
||||
@@ -158,32 +158,32 @@ public abstract class AbstractApplicationContextRunnerTests<T extends AbstractAp
|
||||
}
|
||||
|
||||
@Test
|
||||
public void runWithMultipleConfigurationsShouldRegisterAllConfigurations() {
|
||||
void runWithMultipleConfigurationsShouldRegisterAllConfigurations() {
|
||||
get().withUserConfiguration(FooConfig.class).withConfiguration(UserConfigurations.of(BarConfig.class))
|
||||
.run((context) -> assertThat(context).hasBean("foo").hasBean("bar"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void runWithFailedContextShouldReturnFailedAssertableContext() {
|
||||
void runWithFailedContextShouldReturnFailedAssertableContext() {
|
||||
get().withUserConfiguration(FailingConfig.class).run((context) -> assertThat(context).hasFailed());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void runWithClassLoaderShouldSetClassLoaderOnContext() {
|
||||
void runWithClassLoaderShouldSetClassLoaderOnContext() {
|
||||
get().withClassLoader(new FilteredClassLoader(Gson.class.getPackage().getName()))
|
||||
.run((context) -> assertThatExceptionOfType(ClassNotFoundException.class)
|
||||
.isThrownBy(() -> ClassUtils.forName(Gson.class.getName(), context.getClassLoader())));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void runWithClassLoaderShouldSetClassLoaderOnConditionContext() {
|
||||
void runWithClassLoaderShouldSetClassLoaderOnConditionContext() {
|
||||
get().withClassLoader(new FilteredClassLoader(Gson.class.getPackage().getName()))
|
||||
.withUserConfiguration(ConditionalConfig.class)
|
||||
.run((context) -> assertThat(context).hasSingleBean(ConditionalConfig.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void thrownRuleWorksWithCheckedException() {
|
||||
void thrownRuleWorksWithCheckedException() {
|
||||
get().run((context) -> assertThatIOException().isThrownBy(() -> throwCheckedException("Expected message"))
|
||||
.withMessageContaining("Expected message"));
|
||||
}
|
||||
|
||||
@@ -30,11 +30,11 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Stephane Nicoll
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class WebApplicationContextRunnerTests extends
|
||||
class WebApplicationContextRunnerTests extends
|
||||
AbstractApplicationContextRunnerTests<WebApplicationContextRunner, ConfigurableWebApplicationContext, AssertableWebApplicationContext> {
|
||||
|
||||
@Test
|
||||
public void contextShouldHaveMockServletContext() {
|
||||
void contextShouldHaveMockServletContext() {
|
||||
get().run((context) -> assertThat(context.getServletContext()).isInstanceOf(MockServletContext.class));
|
||||
}
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public abstract class AbstractJsonMarshalTesterTests {
|
||||
abstract class AbstractJsonMarshalTesterTests {
|
||||
|
||||
private static final String JSON = "{\"name\":\"Spring\",\"age\":123}";
|
||||
|
||||
@@ -58,13 +58,13 @@ public abstract class AbstractJsonMarshalTesterTests {
|
||||
private static final ResolvableType TYPE = ResolvableType.forClass(ExampleObject.class);
|
||||
|
||||
@Test
|
||||
public void writeShouldReturnJsonContent() throws Exception {
|
||||
void writeShouldReturnJsonContent() throws Exception {
|
||||
JsonContent<Object> content = createTester(TYPE).write(OBJECT);
|
||||
assertThat(content).isEqualToJson(JSON);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void writeListShouldReturnJsonContent() throws Exception {
|
||||
void writeListShouldReturnJsonContent() throws Exception {
|
||||
ResolvableType type = ResolvableTypes.get("listOfExampleObject");
|
||||
List<ExampleObject> value = Collections.singletonList(OBJECT);
|
||||
JsonContent<Object> content = createTester(type).write(value);
|
||||
@@ -72,7 +72,7 @@ public abstract class AbstractJsonMarshalTesterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void writeArrayShouldReturnJsonContent() throws Exception {
|
||||
void writeArrayShouldReturnJsonContent() throws Exception {
|
||||
ResolvableType type = ResolvableTypes.get("arrayOfExampleObject");
|
||||
ExampleObject[] value = new ExampleObject[] { OBJECT };
|
||||
JsonContent<Object> content = createTester(type).write(value);
|
||||
@@ -80,7 +80,7 @@ public abstract class AbstractJsonMarshalTesterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void writeMapShouldReturnJsonContent() throws Exception {
|
||||
void writeMapShouldReturnJsonContent() throws Exception {
|
||||
ResolvableType type = ResolvableTypes.get("mapOfExampleObject");
|
||||
Map<String, Object> value = new LinkedHashMap<>();
|
||||
value.put("a", OBJECT);
|
||||
@@ -89,38 +89,38 @@ public abstract class AbstractJsonMarshalTesterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWhenResourceLoadClassIsNullShouldThrowException() {
|
||||
void createWhenResourceLoadClassIsNullShouldThrowException() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> createTester(null, ResolvableType.forClass(ExampleObject.class)))
|
||||
.withMessageContaining("ResourceLoadClass must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWhenTypeIsNullShouldThrowException() {
|
||||
void createWhenTypeIsNullShouldThrowException() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> createTester(getClass(), null))
|
||||
.withMessageContaining("Type must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseBytesShouldReturnObject() throws Exception {
|
||||
void parseBytesShouldReturnObject() throws Exception {
|
||||
AbstractJsonMarshalTester<Object> tester = createTester(TYPE);
|
||||
assertThat(tester.parse(JSON.getBytes())).isEqualTo(OBJECT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseStringShouldReturnObject() throws Exception {
|
||||
void parseStringShouldReturnObject() throws Exception {
|
||||
AbstractJsonMarshalTester<Object> tester = createTester(TYPE);
|
||||
assertThat(tester.parse(JSON)).isEqualTo(OBJECT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readResourcePathShouldReturnObject() throws Exception {
|
||||
void readResourcePathShouldReturnObject() throws Exception {
|
||||
AbstractJsonMarshalTester<Object> tester = createTester(TYPE);
|
||||
assertThat(tester.read("example.json")).isEqualTo(OBJECT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readFileShouldReturnObject(@TempDir Path temp) throws Exception {
|
||||
void readFileShouldReturnObject(@TempDir Path temp) throws Exception {
|
||||
File file = new File(temp.toFile(), "example.json");
|
||||
FileCopyUtils.copy(JSON.getBytes(), file);
|
||||
AbstractJsonMarshalTester<Object> tester = createTester(TYPE);
|
||||
@@ -128,42 +128,42 @@ public abstract class AbstractJsonMarshalTesterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readInputStreamShouldReturnObject() throws Exception {
|
||||
void readInputStreamShouldReturnObject() throws Exception {
|
||||
InputStream stream = new ByteArrayInputStream(JSON.getBytes());
|
||||
AbstractJsonMarshalTester<Object> tester = createTester(TYPE);
|
||||
assertThat(tester.read(stream)).isEqualTo(OBJECT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readResourceShouldReturnObject() throws Exception {
|
||||
void readResourceShouldReturnObject() throws Exception {
|
||||
Resource resource = new ByteArrayResource(JSON.getBytes());
|
||||
AbstractJsonMarshalTester<Object> tester = createTester(TYPE);
|
||||
assertThat(tester.read(resource)).isEqualTo(OBJECT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readReaderShouldReturnObject() throws Exception {
|
||||
void readReaderShouldReturnObject() throws Exception {
|
||||
Reader reader = new StringReader(JSON);
|
||||
AbstractJsonMarshalTester<Object> tester = createTester(TYPE);
|
||||
assertThat(tester.read(reader)).isEqualTo(OBJECT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseListShouldReturnContent() throws Exception {
|
||||
void parseListShouldReturnContent() throws Exception {
|
||||
ResolvableType type = ResolvableTypes.get("listOfExampleObject");
|
||||
AbstractJsonMarshalTester<Object> tester = createTester(type);
|
||||
assertThat(tester.parse(ARRAY_JSON)).asList().containsOnly(OBJECT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseArrayShouldReturnContent() throws Exception {
|
||||
void parseArrayShouldReturnContent() throws Exception {
|
||||
ResolvableType type = ResolvableTypes.get("arrayOfExampleObject");
|
||||
AbstractJsonMarshalTester<Object> tester = createTester(type);
|
||||
assertThat(tester.parse(ARRAY_JSON)).asArray().containsOnly(OBJECT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseMapShouldReturnContent() throws Exception {
|
||||
void parseMapShouldReturnContent() throws Exception {
|
||||
ResolvableType type = ResolvableTypes.get("mapOfExampleObject");
|
||||
AbstractJsonMarshalTester<Object> tester = createTester(type);
|
||||
assertThat(tester.parse(MAP_JSON)).asMap().containsEntry("a", OBJECT);
|
||||
|
||||
@@ -36,53 +36,53 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class BasicJsonTesterTests {
|
||||
class BasicJsonTesterTests {
|
||||
|
||||
private static final String JSON = "{\"spring\":[\"boot\",\"framework\"]}";
|
||||
|
||||
private BasicJsonTester json = new BasicJsonTester(getClass());
|
||||
|
||||
@Test
|
||||
public void createWhenResourceLoadClassIsNullShouldThrowException() {
|
||||
void createWhenResourceLoadClassIsNullShouldThrowException() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new BasicJsonTester(null))
|
||||
.withMessageContaining("ResourceLoadClass must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fromJsonStringShouldReturnJsonContent() {
|
||||
void fromJsonStringShouldReturnJsonContent() {
|
||||
assertThat(this.json.from(JSON)).isEqualToJson("source.json");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fromResourceStringShouldReturnJsonContent() {
|
||||
void fromResourceStringShouldReturnJsonContent() {
|
||||
assertThat(this.json.from("source.json")).isEqualToJson(JSON);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fromResourceStringWithClassShouldReturnJsonContent() {
|
||||
void fromResourceStringWithClassShouldReturnJsonContent() {
|
||||
assertThat(this.json.from("source.json", getClass())).isEqualToJson(JSON);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fromByteArrayShouldReturnJsonContent() {
|
||||
void fromByteArrayShouldReturnJsonContent() {
|
||||
assertThat(this.json.from(JSON.getBytes())).isEqualToJson("source.json");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fromFileShouldReturnJsonContent(@TempDir Path temp) throws Exception {
|
||||
void fromFileShouldReturnJsonContent(@TempDir Path temp) throws Exception {
|
||||
File file = new File(temp.toFile(), "file.json");
|
||||
FileCopyUtils.copy(JSON.getBytes(), file);
|
||||
assertThat(this.json.from(file)).isEqualToJson("source.json");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fromInputStreamShouldReturnJsonContent() {
|
||||
void fromInputStreamShouldReturnJsonContent() {
|
||||
InputStream inputStream = new ByteArrayInputStream(JSON.getBytes());
|
||||
assertThat(this.json.from(inputStream)).isEqualToJson("source.json");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fromResourceShouldReturnJsonContent() {
|
||||
void fromResourceShouldReturnJsonContent() {
|
||||
Resource resource = new ByteArrayResource(JSON.getBytes());
|
||||
assertThat(this.json.from(resource)).isEqualToJson("source.json");
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Andy Wilkinson
|
||||
* @author Diego Berrueta
|
||||
*/
|
||||
public class GsonTesterIntegrationTests {
|
||||
class GsonTesterIntegrationTests {
|
||||
|
||||
private GsonTester<ExampleObject> simpleJson;
|
||||
|
||||
@@ -53,20 +53,20 @@ public class GsonTesterIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void typicalTest() throws Exception {
|
||||
void typicalTest() throws Exception {
|
||||
String example = JSON;
|
||||
assertThat(this.simpleJson.parse(example).getObject().getName()).isEqualTo("Spring");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void typicalListTest() throws Exception {
|
||||
void typicalListTest() throws Exception {
|
||||
String example = "[" + JSON + "]";
|
||||
assertThat(this.listJson.parse(example)).asList().hasSize(1);
|
||||
assertThat(this.listJson.parse(example).getObject().get(0).getName()).isEqualTo("Spring");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void typicalMapTest() throws Exception {
|
||||
void typicalMapTest() throws Exception {
|
||||
Map<String, Integer> map = new LinkedHashMap<>();
|
||||
map.put("a", 1);
|
||||
map.put("b", 2);
|
||||
@@ -74,7 +74,7 @@ public class GsonTesterIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stringLiteral() throws Exception {
|
||||
void stringLiteral() throws Exception {
|
||||
String stringWithSpecialCharacters = "myString";
|
||||
assertThat(this.stringJson.write(stringWithSpecialCharacters)).extractingJsonPathStringValue("@")
|
||||
.isEqualTo(stringWithSpecialCharacters);
|
||||
|
||||
@@ -32,23 +32,23 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class GsonTesterTests extends AbstractJsonMarshalTesterTests {
|
||||
class GsonTesterTests extends AbstractJsonMarshalTesterTests {
|
||||
|
||||
@Test
|
||||
public void initFieldsWhenTestIsNullShouldThrowException() {
|
||||
void initFieldsWhenTestIsNullShouldThrowException() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> GsonTester.initFields(null, new GsonBuilder().create()))
|
||||
.withMessageContaining("TestInstance must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initFieldsWhenMarshallerIsNullShouldThrowException() {
|
||||
void initFieldsWhenMarshallerIsNullShouldThrowException() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> GsonTester.initFields(new InitFieldsTestClass(), (Gson) null))
|
||||
.withMessageContaining("Marshaller must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initFieldsShouldSetNullFields() {
|
||||
void initFieldsShouldSetNullFields() {
|
||||
InitFieldsTestClass test = new InitFieldsTestClass();
|
||||
assertThat(test.test).isNull();
|
||||
assertThat(test.base).isNull();
|
||||
|
||||
@@ -38,7 +38,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Madhura Bhave
|
||||
* @author Diego Berrueta
|
||||
*/
|
||||
public class JacksonTesterIntegrationTests {
|
||||
class JacksonTesterIntegrationTests {
|
||||
|
||||
private JacksonTester<ExampleObject> simpleJson;
|
||||
|
||||
@@ -61,20 +61,20 @@ public class JacksonTesterIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void typicalTest() throws Exception {
|
||||
void typicalTest() throws Exception {
|
||||
String example = JSON;
|
||||
assertThat(this.simpleJson.parse(example).getObject().getName()).isEqualTo("Spring");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void typicalListTest() throws Exception {
|
||||
void typicalListTest() throws Exception {
|
||||
String example = "[" + JSON + "]";
|
||||
assertThat(this.listJson.parse(example)).asList().hasSize(1);
|
||||
assertThat(this.listJson.parse(example).getObject().get(0).getName()).isEqualTo("Spring");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void typicalMapTest() throws Exception {
|
||||
void typicalMapTest() throws Exception {
|
||||
Map<String, Integer> map = new LinkedHashMap<>();
|
||||
map.put("a", 1);
|
||||
map.put("b", 2);
|
||||
@@ -82,14 +82,14 @@ public class JacksonTesterIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stringLiteral() throws Exception {
|
||||
void stringLiteral() throws Exception {
|
||||
String stringWithSpecialCharacters = "myString";
|
||||
assertThat(this.stringJson.write(stringWithSpecialCharacters)).extractingJsonPathStringValue("@")
|
||||
.isEqualTo(stringWithSpecialCharacters);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseSpecialCharactersTest() throws Exception {
|
||||
void parseSpecialCharactersTest() throws Exception {
|
||||
// Confirms that the handling of special characters is symmetrical between
|
||||
// the serialization (via the JacksonTester) and the parsing (via json-path). By
|
||||
// default json-path uses SimpleJson as its parser, which has a slightly different
|
||||
@@ -102,7 +102,7 @@ public class JacksonTesterIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void writeWithView() throws Exception {
|
||||
void writeWithView() throws Exception {
|
||||
this.objectMapper.disable(MapperFeature.DEFAULT_VIEW_INCLUSION);
|
||||
ExampleObjectWithView object = new ExampleObjectWithView();
|
||||
object.setName("Spring");
|
||||
@@ -114,7 +114,7 @@ public class JacksonTesterIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readWithResourceAndView() throws Exception {
|
||||
void readWithResourceAndView() throws Exception {
|
||||
this.objectMapper.disable(MapperFeature.DEFAULT_VIEW_INCLUSION);
|
||||
ByteArrayResource resource = new ByteArrayResource(JSON.getBytes());
|
||||
ObjectContent<ExampleObjectWithView> content = this.jsonWithView.forView(ExampleObjectWithView.TestView.class)
|
||||
@@ -124,7 +124,7 @@ public class JacksonTesterIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readWithReaderAndView() throws Exception {
|
||||
void readWithReaderAndView() throws Exception {
|
||||
this.objectMapper.disable(MapperFeature.DEFAULT_VIEW_INCLUSION);
|
||||
Reader reader = new StringReader(JSON);
|
||||
ObjectContent<ExampleObjectWithView> content = this.jsonWithView.forView(ExampleObjectWithView.TestView.class)
|
||||
|
||||
@@ -31,23 +31,23 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class JacksonTesterTests extends AbstractJsonMarshalTesterTests {
|
||||
class JacksonTesterTests extends AbstractJsonMarshalTesterTests {
|
||||
|
||||
@Test
|
||||
public void initFieldsWhenTestIsNullShouldThrowException() {
|
||||
void initFieldsWhenTestIsNullShouldThrowException() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> JacksonTester.initFields(null, new ObjectMapper()))
|
||||
.withMessageContaining("TestInstance must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initFieldsWhenMarshallerIsNullShouldThrowException() {
|
||||
void initFieldsWhenMarshallerIsNullShouldThrowException() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> JacksonTester.initFields(new InitFieldsTestClass(), (ObjectMapper) null))
|
||||
.withMessageContaining("Marshaller must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initFieldsShouldSetNullFields() {
|
||||
void initFieldsShouldSetNullFields() {
|
||||
InitFieldsTestClass test = new InitFieldsTestClass();
|
||||
assertThat(test.test).isNull();
|
||||
assertThat(test.base).isNull();
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -29,14 +29,14 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class JsonContentTests {
|
||||
class JsonContentTests {
|
||||
|
||||
private static final String JSON = "{\"name\":\"spring\", \"age\":100}";
|
||||
|
||||
private static final ResolvableType TYPE = ResolvableType.forClass(ExampleObject.class);
|
||||
|
||||
@Test
|
||||
public void createWhenResourceLoadClassIsNullShouldThrowException() {
|
||||
void createWhenResourceLoadClassIsNullShouldThrowException() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(
|
||||
() -> new JsonContent<ExampleObject>(null, TYPE, JSON, Configuration.defaultConfiguration()))
|
||||
@@ -44,21 +44,21 @@ public class JsonContentTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWhenJsonIsNullShouldThrowException() {
|
||||
void createWhenJsonIsNullShouldThrowException() {
|
||||
assertThatIllegalArgumentException().isThrownBy(
|
||||
() -> new JsonContent<ExampleObject>(getClass(), TYPE, null, Configuration.defaultConfiguration()))
|
||||
.withMessageContaining("JSON must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWhenConfigurationIsNullShouldThrowException() {
|
||||
void createWhenConfigurationIsNullShouldThrowException() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new JsonContent<ExampleObject>(getClass(), TYPE, JSON, null))
|
||||
.withMessageContaining("Configuration must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWhenTypeIsNullShouldCreateContent() {
|
||||
void createWhenTypeIsNullShouldCreateContent() {
|
||||
JsonContent<ExampleObject> content = new JsonContent<>(getClass(), null, JSON,
|
||||
Configuration.defaultConfiguration());
|
||||
assertThat(content).isNotNull();
|
||||
@@ -66,14 +66,14 @@ public class JsonContentTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void assertThatShouldReturnJsonContentAssert() {
|
||||
void assertThatShouldReturnJsonContentAssert() {
|
||||
JsonContent<ExampleObject> content = new JsonContent<>(getClass(), TYPE, JSON,
|
||||
Configuration.defaultConfiguration());
|
||||
assertThat(content.assertThat()).isInstanceOf(JsonContentAssert.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getJsonShouldReturnJson() {
|
||||
void getJsonShouldReturnJson() {
|
||||
JsonContent<ExampleObject> content = new JsonContent<>(getClass(), TYPE, JSON,
|
||||
Configuration.defaultConfiguration());
|
||||
assertThat(content.getJson()).isEqualTo(JSON);
|
||||
@@ -81,14 +81,14 @@ public class JsonContentTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toStringWhenHasTypeShouldReturnString() {
|
||||
void toStringWhenHasTypeShouldReturnString() {
|
||||
JsonContent<ExampleObject> content = new JsonContent<>(getClass(), TYPE, JSON,
|
||||
Configuration.defaultConfiguration());
|
||||
assertThat(content.toString()).isEqualTo("JsonContent " + JSON + " created from " + TYPE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toStringWhenHasNoTypeShouldReturnString() {
|
||||
void toStringWhenHasNoTypeShouldReturnString() {
|
||||
JsonContent<ExampleObject> content = new JsonContent<>(getClass(), null, JSON,
|
||||
Configuration.defaultConfiguration());
|
||||
assertThat(content.toString()).isEqualTo("JsonContent " + JSON);
|
||||
|
||||
@@ -33,23 +33,23 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
|
||||
*
|
||||
* @author Eddú Meléndez
|
||||
*/
|
||||
public class JsonbTesterTests extends AbstractJsonMarshalTesterTests {
|
||||
class JsonbTesterTests extends AbstractJsonMarshalTesterTests {
|
||||
|
||||
@Test
|
||||
public void initFieldsWhenTestIsNullShouldThrowException() {
|
||||
void initFieldsWhenTestIsNullShouldThrowException() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> JsonbTester.initFields(null, JsonbBuilder.create()))
|
||||
.withMessageContaining("TestInstance must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initFieldsWhenMarshallerIsNullShouldThrowException() {
|
||||
void initFieldsWhenMarshallerIsNullShouldThrowException() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> JsonbTester.initFields(new InitFieldsTestClass(), (Jsonb) null))
|
||||
.withMessageContaining("Marshaller must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initFieldsShouldSetNullFields() {
|
||||
void initFieldsShouldSetNullFields() {
|
||||
InitFieldsTestClass test = new InitFieldsTestClass();
|
||||
assertThat(test.test).isNull();
|
||||
assertThat(test.base).isNull();
|
||||
|
||||
@@ -30,7 +30,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class ObjectContentAssertTests {
|
||||
class ObjectContentAssertTests {
|
||||
|
||||
private static final ExampleObject SOURCE = new ExampleObject();
|
||||
|
||||
@@ -42,35 +42,35 @@ public class ObjectContentAssertTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isEqualToWhenObjectsAreEqualShouldPass() {
|
||||
void isEqualToWhenObjectsAreEqualShouldPass() {
|
||||
assertThat(forObject(SOURCE)).isEqualTo(SOURCE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isEqualToWhenObjectsAreDifferentShouldFail() {
|
||||
void isEqualToWhenObjectsAreDifferentShouldFail() {
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(forObject(SOURCE)).isEqualTo(DIFFERENT));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void asArrayForArrayShouldReturnObjectArrayAssert() {
|
||||
void asArrayForArrayShouldReturnObjectArrayAssert() {
|
||||
ExampleObject[] source = new ExampleObject[] { SOURCE };
|
||||
assertThat(forObject(source)).asArray().containsExactly(SOURCE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void asArrayForNonArrayShouldFail() {
|
||||
void asArrayForNonArrayShouldFail() {
|
||||
assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> assertThat(forObject(SOURCE)).asArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void asMapForMapShouldReturnMapAssert() {
|
||||
void asMapForMapShouldReturnMapAssert() {
|
||||
Map<String, ExampleObject> source = Collections.singletonMap("a", SOURCE);
|
||||
assertThat(forObject(source)).asMap().containsEntry("a", SOURCE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void asMapForNonMapShouldFail() {
|
||||
void asMapForNonMapShouldFail() {
|
||||
assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> assertThat(forObject(SOURCE)).asMap());
|
||||
}
|
||||
|
||||
|
||||
@@ -28,44 +28,44 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class ObjectContentTests {
|
||||
class ObjectContentTests {
|
||||
|
||||
private static final ExampleObject OBJECT = new ExampleObject();
|
||||
|
||||
private static final ResolvableType TYPE = ResolvableType.forClass(ExampleObject.class);
|
||||
|
||||
@Test
|
||||
public void createWhenObjectIsNullShouldThrowException() {
|
||||
void createWhenObjectIsNullShouldThrowException() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new ObjectContent<ExampleObject>(TYPE, null))
|
||||
.withMessageContaining("Object must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWhenTypeIsNullShouldCreateContent() {
|
||||
void createWhenTypeIsNullShouldCreateContent() {
|
||||
ObjectContent<ExampleObject> content = new ObjectContent<>(null, OBJECT);
|
||||
assertThat(content).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void assertThatShouldReturnObjectContentAssert() {
|
||||
void assertThatShouldReturnObjectContentAssert() {
|
||||
ObjectContent<ExampleObject> content = new ObjectContent<>(TYPE, OBJECT);
|
||||
assertThat(content.assertThat()).isInstanceOf(ObjectContentAssert.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getObjectShouldReturnObject() {
|
||||
void getObjectShouldReturnObject() {
|
||||
ObjectContent<ExampleObject> content = new ObjectContent<>(TYPE, OBJECT);
|
||||
assertThat(content.getObject()).isEqualTo(OBJECT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toStringWhenHasTypeShouldReturnString() {
|
||||
void toStringWhenHasTypeShouldReturnString() {
|
||||
ObjectContent<ExampleObject> content = new ObjectContent<>(TYPE, OBJECT);
|
||||
assertThat(content.toString()).isEqualTo("ObjectContent " + OBJECT + " created from " + TYPE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toStringWhenHasNoTypeShouldReturnString() {
|
||||
void toStringWhenHasNoTypeShouldReturnString() {
|
||||
ObjectContent<ExampleObject> content = new ObjectContent<>(null, OBJECT);
|
||||
assertThat(content.toString()).isEqualTo("ObjectContent " + OBJECT);
|
||||
}
|
||||
|
||||
@@ -37,19 +37,19 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class DefinitionsParserTests {
|
||||
class DefinitionsParserTests {
|
||||
|
||||
private DefinitionsParser parser = new DefinitionsParser();
|
||||
|
||||
@Test
|
||||
public void parseSingleMockBean() {
|
||||
void parseSingleMockBean() {
|
||||
this.parser.parse(SingleMockBean.class);
|
||||
assertThat(getDefinitions()).hasSize(1);
|
||||
assertThat(getMockDefinition(0).getTypeToMock().resolve()).isEqualTo(ExampleService.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseRepeatMockBean() {
|
||||
void parseRepeatMockBean() {
|
||||
this.parser.parse(RepeatMockBean.class);
|
||||
assertThat(getDefinitions()).hasSize(2);
|
||||
assertThat(getMockDefinition(0).getTypeToMock().resolve()).isEqualTo(ExampleService.class);
|
||||
@@ -57,7 +57,7 @@ public class DefinitionsParserTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseMockBeanAttributes() {
|
||||
void parseMockBeanAttributes() {
|
||||
this.parser.parse(MockBeanAttributes.class);
|
||||
assertThat(getDefinitions()).hasSize(1);
|
||||
MockDefinition definition = getMockDefinition(0);
|
||||
@@ -71,7 +71,7 @@ public class DefinitionsParserTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseMockBeanOnClassAndField() {
|
||||
void parseMockBeanOnClassAndField() {
|
||||
this.parser.parse(MockBeanOnClassAndField.class);
|
||||
assertThat(getDefinitions()).hasSize(2);
|
||||
MockDefinition classDefinition = getMockDefinition(0);
|
||||
@@ -85,20 +85,20 @@ public class DefinitionsParserTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseMockBeanInferClassToMock() {
|
||||
void parseMockBeanInferClassToMock() {
|
||||
this.parser.parse(MockBeanInferClassToMock.class);
|
||||
assertThat(getDefinitions()).hasSize(1);
|
||||
assertThat(getMockDefinition(0).getTypeToMock().resolve()).isEqualTo(ExampleService.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseMockBeanMissingClassToMock() {
|
||||
void parseMockBeanMissingClassToMock() {
|
||||
assertThatIllegalStateException().isThrownBy(() -> this.parser.parse(MockBeanMissingClassToMock.class))
|
||||
.withMessageContaining("Unable to deduce type to mock");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseMockBeanMultipleClasses() {
|
||||
void parseMockBeanMultipleClasses() {
|
||||
this.parser.parse(MockBeanMultipleClasses.class);
|
||||
assertThat(getDefinitions()).hasSize(2);
|
||||
assertThat(getMockDefinition(0).getTypeToMock().resolve()).isEqualTo(ExampleService.class);
|
||||
@@ -106,20 +106,20 @@ public class DefinitionsParserTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseMockBeanMultipleClassesWithName() {
|
||||
void parseMockBeanMultipleClassesWithName() {
|
||||
assertThatIllegalStateException().isThrownBy(() -> this.parser.parse(MockBeanMultipleClassesWithName.class))
|
||||
.withMessageContaining("The name attribute can only be used when mocking a single class");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseSingleSpyBean() {
|
||||
void parseSingleSpyBean() {
|
||||
this.parser.parse(SingleSpyBean.class);
|
||||
assertThat(getDefinitions()).hasSize(1);
|
||||
assertThat(getSpyDefinition(0).getTypeToSpy().resolve()).isEqualTo(RealExampleService.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseRepeatSpyBean() {
|
||||
void parseRepeatSpyBean() {
|
||||
this.parser.parse(RepeatSpyBean.class);
|
||||
assertThat(getDefinitions()).hasSize(2);
|
||||
assertThat(getSpyDefinition(0).getTypeToSpy().resolve()).isEqualTo(RealExampleService.class);
|
||||
@@ -127,7 +127,7 @@ public class DefinitionsParserTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseSpyBeanAttributes() {
|
||||
void parseSpyBeanAttributes() {
|
||||
this.parser.parse(SpyBeanAttributes.class);
|
||||
assertThat(getDefinitions()).hasSize(1);
|
||||
SpyDefinition definition = getSpyDefinition(0);
|
||||
@@ -138,7 +138,7 @@ public class DefinitionsParserTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseSpyBeanOnClassAndField() {
|
||||
void parseSpyBeanOnClassAndField() {
|
||||
this.parser.parse(SpyBeanOnClassAndField.class);
|
||||
assertThat(getDefinitions()).hasSize(2);
|
||||
SpyDefinition classDefinition = getSpyDefinition(0);
|
||||
@@ -152,20 +152,20 @@ public class DefinitionsParserTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseSpyBeanInferClassToMock() {
|
||||
void parseSpyBeanInferClassToMock() {
|
||||
this.parser.parse(SpyBeanInferClassToMock.class);
|
||||
assertThat(getDefinitions()).hasSize(1);
|
||||
assertThat(getSpyDefinition(0).getTypeToSpy().resolve()).isEqualTo(RealExampleService.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseSpyBeanMissingClassToMock() {
|
||||
void parseSpyBeanMissingClassToMock() {
|
||||
assertThatIllegalStateException().isThrownBy(() -> this.parser.parse(SpyBeanMissingClassToMock.class))
|
||||
.withMessageContaining("Unable to deduce type to spy");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseSpyBeanMultipleClasses() {
|
||||
void parseSpyBeanMultipleClasses() {
|
||||
this.parser.parse(SpyBeanMultipleClasses.class);
|
||||
assertThat(getDefinitions()).hasSize(2);
|
||||
assertThat(getSpyDefinition(0).getTypeToSpy().resolve()).isEqualTo(RealExampleService.class);
|
||||
@@ -173,7 +173,7 @@ public class DefinitionsParserTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseSpyBeanMultipleClassesWithName() {
|
||||
void parseSpyBeanMultipleClassesWithName() {
|
||||
assertThatIllegalStateException().isThrownBy(() -> this.parser.parse(SpyBeanMultipleClassesWithName.class))
|
||||
.withMessageContaining("The name attribute can only be used when spying a single class");
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ import static org.mockito.Mockito.mock;
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
public class MockBeanForBeanFactoryIntegrationTests {
|
||||
class MockBeanForBeanFactoryIntegrationTests {
|
||||
|
||||
// gh-7439
|
||||
|
||||
@@ -48,7 +48,7 @@ public class MockBeanForBeanFactoryIntegrationTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public void testName() {
|
||||
void testName() {
|
||||
TestBean testBean = mock(TestBean.class);
|
||||
given(testBean.hello()).willReturn("amock");
|
||||
given(this.testFactoryBean.getObjectType()).willReturn((Class) TestBean.class);
|
||||
|
||||
@@ -37,13 +37,13 @@ import static org.mockito.BDDMockito.given;
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
public class MockBeanOnConfigurationClassForExistingBeanIntegrationTests {
|
||||
class MockBeanOnConfigurationClassForExistingBeanIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private ExampleServiceCaller caller;
|
||||
|
||||
@Test
|
||||
public void testMocking() {
|
||||
void testMocking() {
|
||||
given(this.caller.getService().greeting()).willReturn("Boot");
|
||||
assertThat(this.caller.sayGreeting()).isEqualTo("I say Boot");
|
||||
}
|
||||
|
||||
@@ -36,13 +36,13 @@ import static org.mockito.BDDMockito.given;
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
public class MockBeanOnConfigurationClassForNewBeanIntegrationTests {
|
||||
class MockBeanOnConfigurationClassForNewBeanIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private ExampleServiceCaller caller;
|
||||
|
||||
@Test
|
||||
public void testMocking() {
|
||||
void testMocking() {
|
||||
given(this.caller.getService().greeting()).willReturn("Boot");
|
||||
assertThat(this.caller.sayGreeting()).isEqualTo("I say Boot");
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ import static org.mockito.BDDMockito.given;
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
public class MockBeanOnConfigurationFieldForExistingBeanIntegrationTests {
|
||||
class MockBeanOnConfigurationFieldForExistingBeanIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private Config config;
|
||||
@@ -46,7 +46,7 @@ public class MockBeanOnConfigurationFieldForExistingBeanIntegrationTests {
|
||||
private ExampleServiceCaller caller;
|
||||
|
||||
@Test
|
||||
public void testMocking() {
|
||||
void testMocking() {
|
||||
given(this.config.exampleService.greeting()).willReturn("Boot");
|
||||
assertThat(this.caller.sayGreeting()).isEqualTo("I say Boot");
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ import static org.mockito.BDDMockito.given;
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
public class MockBeanOnConfigurationFieldForNewBeanIntegrationTests {
|
||||
class MockBeanOnConfigurationFieldForNewBeanIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private Config config;
|
||||
@@ -45,7 +45,7 @@ public class MockBeanOnConfigurationFieldForNewBeanIntegrationTests {
|
||||
private ExampleServiceCaller caller;
|
||||
|
||||
@Test
|
||||
public void testMocking() {
|
||||
void testMocking() {
|
||||
given(this.config.exampleService.greeting()).willReturn("Boot");
|
||||
assertThat(this.caller.sayGreeting()).isEqualTo("I say Boot");
|
||||
}
|
||||
|
||||
@@ -43,13 +43,13 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextHierarchy({ @ContextConfiguration(classes = ParentConfig.class),
|
||||
@ContextConfiguration(classes = ChildConfig.class) })
|
||||
public class MockBeanOnContextHierarchyIntegrationTests {
|
||||
class MockBeanOnContextHierarchyIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private ChildConfig childConfig;
|
||||
|
||||
@Test
|
||||
public void testMocking() {
|
||||
void testMocking() {
|
||||
ApplicationContext context = this.childConfig.getContext();
|
||||
ApplicationContext parentContext = context.getParent();
|
||||
assertThat(parentContext.getBeanNamesForType(ExampleService.class)).hasSize(1);
|
||||
|
||||
@@ -40,7 +40,7 @@ import static org.mockito.BDDMockito.given;
|
||||
* @see <a href="https://github.com/spring-projects/spring-boot/issues/5724">gh-5724</a>
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
public class MockBeanOnScopedProxyTests {
|
||||
class MockBeanOnScopedProxyTests {
|
||||
|
||||
@MockBean
|
||||
private ExampleService exampleService;
|
||||
@@ -49,7 +49,7 @@ public class MockBeanOnScopedProxyTests {
|
||||
private ExampleServiceCaller caller;
|
||||
|
||||
@Test
|
||||
public void testMocking() {
|
||||
void testMocking() {
|
||||
given(this.caller.getService().greeting()).willReturn("Boot");
|
||||
assertThat(this.caller.sayGreeting()).isEqualTo("I say Boot");
|
||||
}
|
||||
|
||||
@@ -37,13 +37,13 @@ import static org.mockito.BDDMockito.given;
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@MockBean(ExampleService.class)
|
||||
public class MockBeanOnTestClassForExistingBeanIntegrationTests {
|
||||
class MockBeanOnTestClassForExistingBeanIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private ExampleServiceCaller caller;
|
||||
|
||||
@Test
|
||||
public void testMocking() {
|
||||
void testMocking() {
|
||||
given(this.caller.getService().greeting()).willReturn("Boot");
|
||||
assertThat(this.caller.sayGreeting()).isEqualTo("I say Boot");
|
||||
}
|
||||
|
||||
@@ -37,13 +37,13 @@ import static org.mockito.BDDMockito.given;
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@MockBean(ExampleService.class)
|
||||
public class MockBeanOnTestClassForNewBeanIntegrationTests {
|
||||
class MockBeanOnTestClassForNewBeanIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private ExampleServiceCaller caller;
|
||||
|
||||
@Test
|
||||
public void testMocking() {
|
||||
void testMocking() {
|
||||
given(this.caller.getService().greeting()).willReturn("Boot");
|
||||
assertThat(this.caller.sayGreeting()).isEqualTo("I say Boot");
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ import static org.mockito.BDDMockito.given;
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration(classes = MockBeanOnTestFieldForExistingBeanConfig.class)
|
||||
public class MockBeanOnTestFieldForExistingBeanCacheIntegrationTests {
|
||||
class MockBeanOnTestFieldForExistingBeanCacheIntegrationTests {
|
||||
|
||||
@MockBean
|
||||
private ExampleService exampleService;
|
||||
@@ -48,7 +48,7 @@ public class MockBeanOnTestFieldForExistingBeanCacheIntegrationTests {
|
||||
private ExampleServiceCaller caller;
|
||||
|
||||
@Test
|
||||
public void testMocking() {
|
||||
void testMocking() {
|
||||
given(this.exampleService.greeting()).willReturn("Boot");
|
||||
assertThat(this.caller.sayGreeting()).isEqualTo("I say Boot");
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ import static org.mockito.BDDMockito.given;
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration(classes = MockBeanOnTestFieldForExistingBeanConfig.class)
|
||||
public class MockBeanOnTestFieldForExistingBeanIntegrationTests {
|
||||
class MockBeanOnTestFieldForExistingBeanIntegrationTests {
|
||||
|
||||
@MockBean
|
||||
private ExampleService exampleService;
|
||||
@@ -46,7 +46,7 @@ public class MockBeanOnTestFieldForExistingBeanIntegrationTests {
|
||||
private ExampleServiceCaller caller;
|
||||
|
||||
@Test
|
||||
public void testMocking() {
|
||||
void testMocking() {
|
||||
given(this.exampleService.greeting()).willReturn("Boot");
|
||||
assertThat(this.caller.sayGreeting()).isEqualTo("I say Boot");
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ import static org.mockito.Mockito.verify;
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
public class MockBeanOnTestFieldForExistingBeanWithQualifierIntegrationTests {
|
||||
class MockBeanOnTestFieldForExistingBeanWithQualifierIntegrationTests {
|
||||
|
||||
@MockBean
|
||||
@CustomQualifier
|
||||
@@ -54,13 +54,13 @@ public class MockBeanOnTestFieldForExistingBeanWithQualifierIntegrationTests {
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@Test
|
||||
public void testMocking() {
|
||||
void testMocking() {
|
||||
this.caller.sayGreeting();
|
||||
verify(this.service).greeting();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onlyQualifiedBeanIsReplaced() {
|
||||
void onlyQualifiedBeanIsReplaced() {
|
||||
assertThat(this.applicationContext.getBean("service")).isSameAs(this.service);
|
||||
ExampleService anotherService = this.applicationContext.getBean("anotherService", ExampleService.class);
|
||||
assertThat(anotherService.greeting()).isEqualTo("Another");
|
||||
|
||||
@@ -36,7 +36,7 @@ import static org.mockito.BDDMockito.given;
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
public class MockBeanOnTestFieldForNewBeanIntegrationTests {
|
||||
class MockBeanOnTestFieldForNewBeanIntegrationTests {
|
||||
|
||||
@MockBean
|
||||
private ExampleService exampleService;
|
||||
@@ -45,7 +45,7 @@ public class MockBeanOnTestFieldForNewBeanIntegrationTests {
|
||||
private ExampleServiceCaller caller;
|
||||
|
||||
@Test
|
||||
public void testMocking() {
|
||||
void testMocking() {
|
||||
given(this.exampleService.greeting()).willReturn("Boot");
|
||||
assertThat(this.caller.sayGreeting()).isEqualTo("I say Boot");
|
||||
}
|
||||
|
||||
@@ -47,13 +47,13 @@ import static org.mockito.Mockito.verify;
|
||||
* @see <a href="https://github.com/spring-projects/spring-boot/issues/5837">5837</a>
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
public class MockBeanWithAopProxyTests {
|
||||
class MockBeanWithAopProxyTests {
|
||||
|
||||
@MockBean
|
||||
private DateService dateService;
|
||||
|
||||
@Test
|
||||
public void verifyShouldUseProxyTarget() {
|
||||
void verifyShouldUseProxyTarget() {
|
||||
given(this.dateService.getDate(false)).willReturn(1L);
|
||||
Long d1 = this.dateService.getDate(false);
|
||||
assertThat(d1).isEqualTo(1L);
|
||||
|
||||
@@ -35,7 +35,7 @@ import static org.mockito.BDDMockito.given;
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
public class MockBeanWithAsyncInterfaceMethodIntegrationTests {
|
||||
class MockBeanWithAsyncInterfaceMethodIntegrationTests {
|
||||
|
||||
@MockBean
|
||||
private Transformer transformer;
|
||||
@@ -44,7 +44,7 @@ public class MockBeanWithAsyncInterfaceMethodIntegrationTests {
|
||||
private MyService service;
|
||||
|
||||
@Test
|
||||
public void mockedMethodsAreNotAsync() {
|
||||
void mockedMethodsAreNotAsync() {
|
||||
given(this.transformer.transform("foo")).willReturn("bar");
|
||||
assertThat(this.service.transform("foo")).isEqualTo("bar");
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ import static org.mockito.BDDMockito.given;
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@DirtiesContext(classMode = ClassMode.BEFORE_EACH_TEST_METHOD)
|
||||
public class MockBeanWithDirtiesContextClassModeBeforeMethodIntegrationTests {
|
||||
class MockBeanWithDirtiesContextClassModeBeforeMethodIntegrationTests {
|
||||
|
||||
@MockBean
|
||||
private ExampleService exampleService;
|
||||
@@ -48,7 +48,7 @@ public class MockBeanWithDirtiesContextClassModeBeforeMethodIntegrationTests {
|
||||
private ExampleServiceCaller caller;
|
||||
|
||||
@Test
|
||||
public void testMocking() throws Exception {
|
||||
void testMocking() throws Exception {
|
||||
given(this.exampleService.greeting()).willReturn("Boot");
|
||||
assertThat(this.caller.sayGreeting()).isEqualTo("I say Boot");
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ import static org.mockito.BDDMockito.given;
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
public class MockBeanWithGenericsOnTestFieldForNewBeanIntegrationTests {
|
||||
class MockBeanWithGenericsOnTestFieldForNewBeanIntegrationTests {
|
||||
|
||||
@MockBean
|
||||
private ExampleGenericService<Integer> exampleIntegerService;
|
||||
@@ -48,7 +48,7 @@ public class MockBeanWithGenericsOnTestFieldForNewBeanIntegrationTests {
|
||||
private ExampleGenericServiceCaller caller;
|
||||
|
||||
@Test
|
||||
public void testMocking() {
|
||||
void testMocking() {
|
||||
given(this.exampleIntegerService.greeting()).willReturn(200);
|
||||
given(this.exampleStringService.greeting()).willReturn("Boot");
|
||||
assertThat(this.caller.sayGreeting()).isEqualTo("I say 200 Boot");
|
||||
|
||||
@@ -33,13 +33,13 @@ import static org.mockito.BDDMockito.given;
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
public class MockBeanWithInjectedFieldIntegrationTests {
|
||||
class MockBeanWithInjectedFieldIntegrationTests {
|
||||
|
||||
@MockBean
|
||||
private MyService myService;
|
||||
|
||||
@Test
|
||||
public void fieldInjectionIntoMyServiceMockIsNotAttempted() {
|
||||
void fieldInjectionIntoMyServiceMockIsNotAttempted() {
|
||||
given(this.myService.getCount()).willReturn(5);
|
||||
assertThat(this.myService.getCount()).isEqualTo(5);
|
||||
}
|
||||
|
||||
@@ -34,19 +34,19 @@ import static org.mockito.Mockito.mock;
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class MockDefinitionTests {
|
||||
class MockDefinitionTests {
|
||||
|
||||
private static final ResolvableType EXAMPLE_SERVICE_TYPE = ResolvableType.forClass(ExampleService.class);
|
||||
|
||||
@Test
|
||||
public void classToMockMustNotBeNull() {
|
||||
void classToMockMustNotBeNull() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new MockDefinition(null, null, null, null, false, null, null))
|
||||
.withMessageContaining("TypeToMock must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWithDefaults() {
|
||||
void createWithDefaults() {
|
||||
MockDefinition definition = new MockDefinition(null, EXAMPLE_SERVICE_TYPE, null, null, false, null, null);
|
||||
assertThat(definition.getName()).isNull();
|
||||
assertThat(definition.getTypeToMock()).isEqualTo(EXAMPLE_SERVICE_TYPE);
|
||||
@@ -58,7 +58,7 @@ public class MockDefinitionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createExplicit() {
|
||||
void createExplicit() {
|
||||
QualifierDefinition qualifier = mock(QualifierDefinition.class);
|
||||
MockDefinition definition = new MockDefinition("name", EXAMPLE_SERVICE_TYPE,
|
||||
new Class<?>[] { ExampleExtraInterface.class }, Answers.RETURNS_SMART_NULLS, true, MockReset.BEFORE,
|
||||
@@ -74,7 +74,7 @@ public class MockDefinitionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createMock() {
|
||||
void createMock() {
|
||||
MockDefinition definition = new MockDefinition("name", EXAMPLE_SERVICE_TYPE,
|
||||
new Class<?>[] { ExampleExtraInterface.class }, Answers.RETURNS_SMART_NULLS, true, MockReset.BEFORE,
|
||||
null);
|
||||
|
||||
@@ -29,40 +29,40 @@ import static org.mockito.Mockito.withSettings;
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class MockResetTests {
|
||||
class MockResetTests {
|
||||
|
||||
@Test
|
||||
public void noneAttachesReset() {
|
||||
void noneAttachesReset() {
|
||||
ExampleService mock = mock(ExampleService.class);
|
||||
assertThat(MockReset.get(mock)).isEqualTo(MockReset.NONE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withSettingsOfNoneAttachesReset() {
|
||||
void withSettingsOfNoneAttachesReset() {
|
||||
ExampleService mock = mock(ExampleService.class, MockReset.withSettings(MockReset.NONE));
|
||||
assertThat(MockReset.get(mock)).isEqualTo(MockReset.NONE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void beforeAttachesReset() {
|
||||
void beforeAttachesReset() {
|
||||
ExampleService mock = mock(ExampleService.class, MockReset.before());
|
||||
assertThat(MockReset.get(mock)).isEqualTo(MockReset.BEFORE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void afterAttachesReset() {
|
||||
void afterAttachesReset() {
|
||||
ExampleService mock = mock(ExampleService.class, MockReset.after());
|
||||
assertThat(MockReset.get(mock)).isEqualTo(MockReset.AFTER);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withSettingsAttachesReset() {
|
||||
void withSettingsAttachesReset() {
|
||||
ExampleService mock = mock(ExampleService.class, MockReset.withSettings(MockReset.BEFORE));
|
||||
assertThat(MockReset.get(mock)).isEqualTo(MockReset.BEFORE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void apply() {
|
||||
void apply() {
|
||||
ExampleService mock = mock(ExampleService.class, MockReset.apply(MockReset.AFTER, withSettings()));
|
||||
assertThat(MockReset.get(mock)).isEqualTo(MockReset.AFTER);
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class MockitoContextCustomizerFactoryTests {
|
||||
class MockitoContextCustomizerFactoryTests {
|
||||
|
||||
private final MockitoContextCustomizerFactory factory = new MockitoContextCustomizerFactory();
|
||||
|
||||
@@ -39,19 +39,19 @@ public class MockitoContextCustomizerFactoryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getContextCustomizerWithoutAnnotationReturnsCustomizer() {
|
||||
void getContextCustomizerWithoutAnnotationReturnsCustomizer() {
|
||||
ContextCustomizer customizer = this.factory.createContextCustomizer(NoMockBeanAnnotation.class, null);
|
||||
assertThat(customizer).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getContextCustomizerWithAnnotationReturnsCustomizer() {
|
||||
void getContextCustomizerWithAnnotationReturnsCustomizer() {
|
||||
ContextCustomizer customizer = this.factory.createContextCustomizer(WithMockBeanAnnotation.class, null);
|
||||
assertThat(customizer).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getContextCustomizerUsesMocksAsCacheKey() {
|
||||
void getContextCustomizerUsesMocksAsCacheKey() {
|
||||
ContextCustomizer customizer = this.factory.createContextCustomizer(WithMockBeanAnnotation.class, null);
|
||||
assertThat(customizer).isNotNull();
|
||||
ContextCustomizer same = this.factory.createContextCustomizer(WithSameMockBeanAnnotation.class, null);
|
||||
|
||||
@@ -34,12 +34,12 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class MockitoContextCustomizerTests {
|
||||
class MockitoContextCustomizerTests {
|
||||
|
||||
private static final Set<MockDefinition> NO_DEFINITIONS = Collections.emptySet();
|
||||
|
||||
@Test
|
||||
public void hashCodeAndEquals() {
|
||||
void hashCodeAndEquals() {
|
||||
MockDefinition d1 = createTestMockDefinition(ExampleService.class);
|
||||
MockDefinition d2 = createTestMockDefinition(ExampleServiceCaller.class);
|
||||
MockitoContextCustomizer c1 = new MockitoContextCustomizer(NO_DEFINITIONS);
|
||||
|
||||
@@ -40,10 +40,10 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
* @author Andy Wilkinson
|
||||
* @author Andreas Neiser
|
||||
*/
|
||||
public class MockitoPostProcessorTests {
|
||||
class MockitoPostProcessorTests {
|
||||
|
||||
@Test
|
||||
public void cannotMockMultipleBeans() {
|
||||
void cannotMockMultipleBeans() {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
MockitoPostProcessor.register(context);
|
||||
context.register(MultipleBeans.class);
|
||||
@@ -53,7 +53,7 @@ public class MockitoPostProcessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cannotMockMultipleQualifiedBeans() {
|
||||
void cannotMockMultipleQualifiedBeans() {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
MockitoPostProcessor.register(context);
|
||||
context.register(MultipleQualifiedBeans.class);
|
||||
@@ -63,7 +63,7 @@ public class MockitoPostProcessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canMockBeanProducedByFactoryBeanWithObjectTypeAttribute() {
|
||||
void canMockBeanProducedByFactoryBeanWithObjectTypeAttribute() {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
MockitoPostProcessor.register(context);
|
||||
RootBeanDefinition factoryBeanDefinition = new RootBeanDefinition(TestFactoryBean.class);
|
||||
@@ -75,7 +75,7 @@ public class MockitoPostProcessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canMockPrimaryBean() {
|
||||
void canMockPrimaryBean() {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
MockitoPostProcessor.register(context);
|
||||
context.register(MockPrimaryBean.class);
|
||||
@@ -88,7 +88,7 @@ public class MockitoPostProcessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canMockQualifiedBeanWithPrimaryBeanPresent() {
|
||||
void canMockQualifiedBeanWithPrimaryBeanPresent() {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
MockitoPostProcessor.register(context);
|
||||
context.register(MockQualifiedBean.class);
|
||||
@@ -100,7 +100,7 @@ public class MockitoPostProcessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canSpyPrimaryBean() {
|
||||
void canSpyPrimaryBean() {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
MockitoPostProcessor.register(context);
|
||||
context.register(SpyPrimaryBean.class);
|
||||
@@ -112,7 +112,7 @@ public class MockitoPostProcessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canSpyQualifiedBeanWithPrimaryBeanPresent() {
|
||||
void canSpyQualifiedBeanWithPrimaryBeanPresent() {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
MockitoPostProcessor.register(context);
|
||||
context.register(SpyQualifiedBean.class);
|
||||
|
||||
@@ -43,7 +43,7 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class MockitoTestExecutionListenerTests {
|
||||
class MockitoTestExecutionListenerTests {
|
||||
|
||||
private MockitoTestExecutionListener listener = new MockitoTestExecutionListener();
|
||||
|
||||
@@ -63,7 +63,7 @@ public class MockitoTestExecutionListenerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void prepareTestInstanceShouldInitMockitoAnnotations() throws Exception {
|
||||
void prepareTestInstanceShouldInitMockitoAnnotations() throws Exception {
|
||||
WithMockitoAnnotations instance = new WithMockitoAnnotations();
|
||||
this.listener.prepareTestInstance(mockTestContext(instance));
|
||||
assertThat(instance.mock).isNotNull();
|
||||
@@ -71,7 +71,7 @@ public class MockitoTestExecutionListenerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void prepareTestInstanceShouldInjectMockBean() throws Exception {
|
||||
void prepareTestInstanceShouldInjectMockBean() throws Exception {
|
||||
WithMockBean instance = new WithMockBean();
|
||||
this.listener.prepareTestInstance(mockTestContext(instance));
|
||||
verify(this.postProcessor).inject(this.fieldCaptor.capture(), eq(instance), any(MockDefinition.class));
|
||||
@@ -79,14 +79,14 @@ public class MockitoTestExecutionListenerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void beforeTestMethodShouldDoNothingWhenDirtiesContextAttributeIsNotSet() throws Exception {
|
||||
void beforeTestMethodShouldDoNothingWhenDirtiesContextAttributeIsNotSet() throws Exception {
|
||||
WithMockBean instance = new WithMockBean();
|
||||
this.listener.beforeTestMethod(mockTestContext(instance));
|
||||
verifyNoMoreInteractions(this.postProcessor);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void beforeTestMethodShouldInjectMockBeanWhenDirtiesContextAttributeIsSet() throws Exception {
|
||||
void beforeTestMethodShouldInjectMockBeanWhenDirtiesContextAttributeIsSet() throws Exception {
|
||||
WithMockBean instance = new WithMockBean();
|
||||
TestContext mockTestContext = mockTestContext(instance);
|
||||
given(mockTestContext.getAttribute(DependencyInjectionTestExecutionListener.REINJECT_DEPENDENCIES_ATTRIBUTE))
|
||||
|
||||
@@ -43,7 +43,7 @@ import static org.mockito.Mockito.verify;
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class QualifierDefinitionTests {
|
||||
class QualifierDefinitionTests {
|
||||
|
||||
@Mock
|
||||
private ConfigurableListableBeanFactory beanFactory;
|
||||
@@ -57,31 +57,31 @@ public class QualifierDefinitionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void forElementFieldIsNullShouldReturnNull() {
|
||||
void forElementFieldIsNullShouldReturnNull() {
|
||||
assertThat(QualifierDefinition.forElement((Field) null)).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void forElementWhenElementIsNotFieldShouldReturnNull() {
|
||||
void forElementWhenElementIsNotFieldShouldReturnNull() {
|
||||
assertThat(QualifierDefinition.forElement(getClass())).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void forElementWhenElementIsFieldWithNoQualifiersShouldReturnNull() {
|
||||
void forElementWhenElementIsFieldWithNoQualifiersShouldReturnNull() {
|
||||
QualifierDefinition definition = QualifierDefinition
|
||||
.forElement(ReflectionUtils.findField(ConfigA.class, "noQualifier"));
|
||||
assertThat(definition).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void forElementWhenElementIsFieldWithQualifierShouldReturnDefinition() {
|
||||
void forElementWhenElementIsFieldWithQualifierShouldReturnDefinition() {
|
||||
QualifierDefinition definition = QualifierDefinition
|
||||
.forElement(ReflectionUtils.findField(ConfigA.class, "directQualifier"));
|
||||
assertThat(definition).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchesShouldCallBeanFactory() {
|
||||
void matchesShouldCallBeanFactory() {
|
||||
Field field = ReflectionUtils.findField(ConfigA.class, "directQualifier");
|
||||
QualifierDefinition qualifierDefinition = QualifierDefinition.forElement(field);
|
||||
qualifierDefinition.matches(this.beanFactory, "bean");
|
||||
@@ -90,7 +90,7 @@ public class QualifierDefinitionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applyToShouldSetQualifierElement() {
|
||||
void applyToShouldSetQualifierElement() {
|
||||
Field field = ReflectionUtils.findField(ConfigA.class, "directQualifier");
|
||||
QualifierDefinition qualifierDefinition = QualifierDefinition.forElement(field);
|
||||
RootBeanDefinition definition = new RootBeanDefinition();
|
||||
@@ -99,7 +99,7 @@ public class QualifierDefinitionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hashCodeAndEqualsShouldWorkOnDifferentClasses() {
|
||||
void hashCodeAndEqualsShouldWorkOnDifferentClasses() {
|
||||
QualifierDefinition directQualifier1 = QualifierDefinition
|
||||
.forElement(ReflectionUtils.findField(ConfigA.class, "directQualifier"));
|
||||
QualifierDefinition directQualifier2 = QualifierDefinition
|
||||
|
||||
@@ -16,10 +16,10 @@
|
||||
|
||||
package org.springframework.boot.test.mock.mockito;
|
||||
|
||||
import org.junit.FixMethodOrder;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.junit.runners.MethodSorters;
|
||||
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -41,21 +41,21 @@ import static org.mockito.Mockito.mock;
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
public class ResetMocksTestExecutionListenerTests {
|
||||
@TestMethodOrder(MethodOrderer.Alphanumeric.class)
|
||||
class ResetMocksTestExecutionListenerTests {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext context;
|
||||
|
||||
@Test
|
||||
public void test001() {
|
||||
void test001() {
|
||||
given(getMock("none").greeting()).willReturn("none");
|
||||
given(getMock("before").greeting()).willReturn("before");
|
||||
given(getMock("after").greeting()).willReturn("after");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test002() {
|
||||
void test002() {
|
||||
assertThat(getMock("none").greeting()).isEqualTo("none");
|
||||
assertThat(getMock("before").greeting()).isNull();
|
||||
assertThat(getMock("after").greeting()).isNull();
|
||||
|
||||
@@ -36,13 +36,13 @@ import static org.mockito.Mockito.verify;
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
public class SpyBeanOnConfigurationClassForExistingBeanIntegrationTests {
|
||||
class SpyBeanOnConfigurationClassForExistingBeanIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private ExampleServiceCaller caller;
|
||||
|
||||
@Test
|
||||
public void testSpying() {
|
||||
void testSpying() {
|
||||
assertThat(this.caller.sayGreeting()).isEqualTo("I say simple");
|
||||
verify(this.caller.getService()).greeting();
|
||||
}
|
||||
|
||||
@@ -36,13 +36,13 @@ import static org.mockito.Mockito.verify;
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
public class SpyBeanOnConfigurationClassForNewBeanIntegrationTests {
|
||||
class SpyBeanOnConfigurationClassForNewBeanIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private ExampleServiceCaller caller;
|
||||
|
||||
@Test
|
||||
public void testSpying() {
|
||||
void testSpying() {
|
||||
assertThat(this.caller.sayGreeting()).isEqualTo("I say simple");
|
||||
verify(this.caller.getService()).greeting();
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ import static org.mockito.Mockito.verify;
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
public class SpyBeanOnConfigurationFieldForExistingBeanIntegrationTests {
|
||||
class SpyBeanOnConfigurationFieldForExistingBeanIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private Config config;
|
||||
@@ -46,7 +46,7 @@ public class SpyBeanOnConfigurationFieldForExistingBeanIntegrationTests {
|
||||
private ExampleServiceCaller caller;
|
||||
|
||||
@Test
|
||||
public void testSpying() {
|
||||
void testSpying() {
|
||||
assertThat(this.caller.sayGreeting()).isEqualTo("I say simple");
|
||||
verify(this.config.exampleService).greeting();
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ import static org.mockito.Mockito.verify;
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
public class SpyBeanOnConfigurationFieldForNewBeanIntegrationTests {
|
||||
class SpyBeanOnConfigurationFieldForNewBeanIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private Config config;
|
||||
@@ -45,7 +45,7 @@ public class SpyBeanOnConfigurationFieldForNewBeanIntegrationTests {
|
||||
private ExampleServiceCaller caller;
|
||||
|
||||
@Test
|
||||
public void testSpying() {
|
||||
void testSpying() {
|
||||
assertThat(this.caller.sayGreeting()).isEqualTo("I say simple");
|
||||
verify(this.config.exampleService).greeting();
|
||||
}
|
||||
|
||||
@@ -44,13 +44,13 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextHierarchy({ @ContextConfiguration(classes = ParentConfig.class),
|
||||
@ContextConfiguration(classes = ChildConfig.class) })
|
||||
public class SpyBeanOnContextHierarchyIntegrationTests {
|
||||
class SpyBeanOnContextHierarchyIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private ChildConfig childConfig;
|
||||
|
||||
@Test
|
||||
public void testSpying() {
|
||||
void testSpying() {
|
||||
ApplicationContext context = this.childConfig.getContext();
|
||||
ApplicationContext parentContext = context.getParent();
|
||||
assertThat(parentContext.getBeanNamesForType(ExampleService.class)).hasSize(1);
|
||||
|
||||
@@ -36,13 +36,13 @@ import static org.mockito.Mockito.verify;
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@SpyBean(SimpleExampleService.class)
|
||||
public class SpyBeanOnTestClassForExistingBeanIntegrationTests {
|
||||
class SpyBeanOnTestClassForExistingBeanIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private ExampleServiceCaller caller;
|
||||
|
||||
@Test
|
||||
public void testSpying() {
|
||||
void testSpying() {
|
||||
assertThat(this.caller.sayGreeting()).isEqualTo("I say simple");
|
||||
verify(this.caller.getService()).greeting();
|
||||
}
|
||||
|
||||
@@ -36,13 +36,13 @@ import static org.mockito.Mockito.verify;
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@SpyBean(SimpleExampleService.class)
|
||||
public class SpyBeanOnTestClassForNewBeanIntegrationTests {
|
||||
class SpyBeanOnTestClassForNewBeanIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private ExampleServiceCaller caller;
|
||||
|
||||
@Test
|
||||
public void testSpying() {
|
||||
void testSpying() {
|
||||
assertThat(this.caller.sayGreeting()).isEqualTo("I say simple");
|
||||
verify(this.caller.getService()).greeting();
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ import static org.mockito.Mockito.verify;
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration(classes = SpyBeanOnTestFieldForExistingBeanConfig.class)
|
||||
public class SpyBeanOnTestFieldForExistingBeanCacheIntegrationTests {
|
||||
class SpyBeanOnTestFieldForExistingBeanCacheIntegrationTests {
|
||||
|
||||
@SpyBean
|
||||
private ExampleService exampleService;
|
||||
@@ -48,7 +48,7 @@ public class SpyBeanOnTestFieldForExistingBeanCacheIntegrationTests {
|
||||
private ExampleServiceCaller caller;
|
||||
|
||||
@Test
|
||||
public void testSpying() {
|
||||
void testSpying() {
|
||||
assertThat(this.caller.sayGreeting()).isEqualTo("I say simple");
|
||||
verify(this.caller.getService()).greeting();
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ import static org.mockito.Mockito.verify;
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration(classes = SpyBeanOnTestFieldForExistingBeanConfig.class)
|
||||
public class SpyBeanOnTestFieldForExistingBeanIntegrationTests {
|
||||
class SpyBeanOnTestFieldForExistingBeanIntegrationTests {
|
||||
|
||||
@SpyBean
|
||||
private ExampleService exampleService;
|
||||
@@ -46,7 +46,7 @@ public class SpyBeanOnTestFieldForExistingBeanIntegrationTests {
|
||||
private ExampleServiceCaller caller;
|
||||
|
||||
@Test
|
||||
public void testSpying() {
|
||||
void testSpying() {
|
||||
assertThat(this.caller.sayGreeting()).isEqualTo("I say simple");
|
||||
verify(this.caller.getService()).greeting();
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ import static org.mockito.Mockito.verify;
|
||||
* @author Andreas Neiser
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
public class SpyBeanOnTestFieldForExistingBeanWithQualifierIntegrationTests {
|
||||
class SpyBeanOnTestFieldForExistingBeanWithQualifierIntegrationTests {
|
||||
|
||||
@SpyBean
|
||||
@CustomQualifier
|
||||
@@ -53,13 +53,13 @@ public class SpyBeanOnTestFieldForExistingBeanWithQualifierIntegrationTests {
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@Test
|
||||
public void testMocking() throws Exception {
|
||||
void testMocking() throws Exception {
|
||||
this.caller.sayGreeting();
|
||||
verify(this.service).greeting();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onlyQualifiedBeanIsReplaced() {
|
||||
void onlyQualifiedBeanIsReplaced() {
|
||||
assertThat(this.applicationContext.getBean("service")).isSameAs(this.service);
|
||||
ExampleService anotherService = this.applicationContext.getBean("anotherService", ExampleService.class);
|
||||
assertThat(anotherService.greeting()).isEqualTo("Another");
|
||||
|
||||
@@ -40,7 +40,7 @@ import static org.mockito.Mockito.verify;
|
||||
* @see SpyBeanOnTestFieldForExistingBeanCacheIntegrationTests
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
public class SpyBeanOnTestFieldForExistingGenericBeanIntegrationTests {
|
||||
class SpyBeanOnTestFieldForExistingGenericBeanIntegrationTests {
|
||||
|
||||
// gh-7625
|
||||
|
||||
@@ -51,7 +51,7 @@ public class SpyBeanOnTestFieldForExistingGenericBeanIntegrationTests {
|
||||
private ExampleGenericServiceCaller caller;
|
||||
|
||||
@Test
|
||||
public void testSpying() {
|
||||
void testSpying() {
|
||||
assertThat(this.caller.sayGreeting()).isEqualTo("I say 123 simple");
|
||||
verify(this.exampleService).greeting();
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user