Migrate Hamcrest assertions to AssertJ
Migrate all existing `assertThat(..., Matcher)` assertions to AssertJ and add checkstyle rules to ensure they don't return. See gh-23022
This commit is contained in:
@@ -64,6 +64,12 @@
|
||||
<suppress files="org[\\/]springframework[\\/]test[\\/]context[\\/]support[\\/]ContextLoaderUtilsContextHierarchyTests" checks="RegexpSinglelineJava" id="expectedExceptionAnnotation" />
|
||||
<suppress files="org[\\/]springframework[\\/]test[\\/]context[\\/]testng[\\/]transaction[\\/]programmatic/ProgrammaticTxMgmtTestNGTests" checks="RegexpSinglelineJava" id="expectedExceptionAnnotation" />
|
||||
<suppress files="org[\\/]springframework[\\/]test[\\/]context[\\/]transaction[\\/]programmatic[\\/]ProgrammaticTxMgmtTests" checks="RegexpSinglelineJava" id="expectedExceptionAnnotation" />
|
||||
<suppress files="JsonPathExpectationsHelper" checks="IllegalImport" id="bannedHamcrestImports" />
|
||||
<suppress files="XpathExpectationsHelper" checks="IllegalImport" id="bannedHamcrestImports" />
|
||||
<suppress files="DefaultWebTestClient" checks="IllegalImport" id="bannedHamcrestImports" />
|
||||
<suppress files="HeaderAssertions" checks="IllegalImport" id="bannedHamcrestImports" />
|
||||
<suppress files="StatusAssertions" checks="IllegalImport" id="bannedHamcrestImports" />
|
||||
<suppress files="JsonPathResultMatchers" checks="IllegalImport" id="bannedHamcrestImports" />
|
||||
|
||||
<!-- spring-web -->
|
||||
<suppress files="SpringHandlerInstantiator" checks="JavadocStyle" />
|
||||
|
||||
@@ -95,10 +95,17 @@
|
||||
<property name="sortStaticImportsAlphabetically" value="true" />
|
||||
</module>
|
||||
<module name="com.puppycrawl.tools.checkstyle.checks.imports.IllegalImportCheck">
|
||||
<property name="id" value="bannedImports"/>
|
||||
<property name="regexp" value="true" />
|
||||
<property name="illegalClasses"
|
||||
value="^reactor\.core\.support\.Assert,^junit\.framework\..+,^org\.junit\.Assert$,^org\.junit\.Assume$,^org\.junit\.Assert\.assertThat,^org\.junit\.Assume\.assumeThat,^org\.junit\.rules\.ExpectedException,^org\.slf4j\.LoggerFactory" />
|
||||
</module>
|
||||
<module name="com.puppycrawl.tools.checkstyle.checks.imports.IllegalImportCheck">
|
||||
<property name="id" value="bannedHamcrestImports"/>
|
||||
<property name="regexp" value="true" />
|
||||
<property name="illegalClasses"
|
||||
value="^org\.hamcrest\.MatcherAssert" />
|
||||
</module>
|
||||
|
||||
<!-- Javadoc Comments -->
|
||||
<module name="com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTypeCheck">
|
||||
|
||||
@@ -27,8 +27,8 @@ import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
/**
|
||||
* @author Costin Leau
|
||||
@@ -55,24 +55,24 @@ public class ComponentBeanDefinitionParserTests {
|
||||
@Test
|
||||
public void testBionicBasic() throws Exception {
|
||||
Component cp = getBionicFamily();
|
||||
assertThat("Bionic-1", equalTo(cp.getName()));
|
||||
assertThat("Bionic-1").isEqualTo(cp.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBionicFirstLevelChildren() throws Exception {
|
||||
Component cp = getBionicFamily();
|
||||
List<Component> components = cp.getComponents();
|
||||
assertThat(2, equalTo(components.size()));
|
||||
assertThat("Mother-1", equalTo(components.get(0).getName()));
|
||||
assertThat("Rock-1", equalTo(components.get(1).getName()));
|
||||
assertThat(2).isEqualTo(components.size());
|
||||
assertThat("Mother-1").isEqualTo(components.get(0).getName());
|
||||
assertThat("Rock-1").isEqualTo(components.get(1).getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBionicSecondLevelChildren() throws Exception {
|
||||
Component cp = getBionicFamily();
|
||||
List<Component> components = cp.getComponents().get(0).getComponents();
|
||||
assertThat(2, equalTo(components.size()));
|
||||
assertThat("Karate-1", equalTo(components.get(0).getName()));
|
||||
assertThat("Sport-1", equalTo(components.get(1).getName()));
|
||||
assertThat(2).isEqualTo(components.size());
|
||||
assertThat("Karate-1").isEqualTo(components.get(0).getName());
|
||||
assertThat("Sport-1").isEqualTo(components.get(1).getName());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,8 +33,7 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
@@ -53,7 +52,7 @@ public class EnableCachingIntegrationTests {
|
||||
ctx.refresh();
|
||||
|
||||
assertCacheProxying(ctx);
|
||||
assertThat(AopUtils.isCglibProxy(ctx.getBean(FooRepository.class)), is(true));
|
||||
assertThat(AopUtils.isCglibProxy(ctx.getBean(FooRepository.class))).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -57,12 +57,8 @@ import org.springframework.web.context.support.StandardServletEnvironment;
|
||||
import org.springframework.web.context.support.StaticWebApplicationContext;
|
||||
import org.springframework.web.context.support.XmlWebApplicationContext;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.lessThan;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.springframework.beans.factory.support.BeanDefinitionBuilder.rootBeanDefinition;
|
||||
import static org.springframework.context.ConfigurableApplicationContext.ENVIRONMENT_BEAN_NAME;
|
||||
import static org.springframework.core.env.EnvironmentSystemIntegrationTests.Constants.DERIVED_DEV_BEAN_NAME;
|
||||
@@ -137,8 +133,8 @@ public class EnvironmentSystemIntegrationTests {
|
||||
ctx.setEnvironment(prodEnv);
|
||||
new XmlBeanDefinitionReader(ctx).loadBeanDefinitions(XML_PATH);
|
||||
ctx.refresh();
|
||||
assertThat(ctx.containsBean(DEV_BEAN_NAME), is(false));
|
||||
assertThat(ctx.containsBean(PROD_BEAN_NAME), is(true));
|
||||
assertThat(ctx.containsBean(DEV_BEAN_NAME)).isFalse();
|
||||
assertThat(ctx.containsBean(PROD_BEAN_NAME)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -147,8 +143,8 @@ public class EnvironmentSystemIntegrationTests {
|
||||
ctx.setEnvironment(prodEnv);
|
||||
new AnnotatedBeanDefinitionReader(ctx).register(Config.class);
|
||||
ctx.refresh();
|
||||
assertThat(ctx.containsBean(DEV_BEAN_NAME), is(false));
|
||||
assertThat(ctx.containsBean(PROD_BEAN_NAME), is(true));
|
||||
assertThat(ctx.containsBean(DEV_BEAN_NAME)).isFalse();
|
||||
assertThat(ctx.containsBean(PROD_BEAN_NAME)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -159,8 +155,8 @@ public class EnvironmentSystemIntegrationTests {
|
||||
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(ctx);
|
||||
scanner.scan("org.springframework.core.env.scan1");
|
||||
ctx.refresh();
|
||||
assertThat(ctx.containsBean(DEV_BEAN_NAME), is(false));
|
||||
assertThat(ctx.containsBean(PROD_BEAN_NAME), is(true));
|
||||
assertThat(ctx.containsBean(DEV_BEAN_NAME)).isFalse();
|
||||
assertThat(ctx.containsBean(PROD_BEAN_NAME)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -170,9 +166,9 @@ public class EnvironmentSystemIntegrationTests {
|
||||
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(ctx);
|
||||
scanner.scan("org.springframework.core.env.scan2");
|
||||
ctx.refresh();
|
||||
assertThat(scanner.getEnvironment(), is((Environment)ctx.getEnvironment()));
|
||||
assertThat(ctx.containsBean(DEV_BEAN_NAME), is(false));
|
||||
assertThat(ctx.containsBean(PROD_BEAN_NAME), is(true));
|
||||
assertThat(scanner.getEnvironment()).isEqualTo((Environment)ctx.getEnvironment());
|
||||
assertThat(ctx.containsBean(DEV_BEAN_NAME)).isFalse();
|
||||
assertThat(ctx.containsBean(PROD_BEAN_NAME)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -186,8 +182,8 @@ public class EnvironmentSystemIntegrationTests {
|
||||
assertHasEnvironment(ctx, prodEnv);
|
||||
assertEnvironmentBeanRegistered(ctx);
|
||||
assertEnvironmentAwareInvoked(ctx, prodEnv);
|
||||
assertThat(ctx.containsBean(DEV_BEAN_NAME), is(false));
|
||||
assertThat(ctx.containsBean(PROD_BEAN_NAME), is(true));
|
||||
assertThat(ctx.containsBean(DEV_BEAN_NAME)).isFalse();
|
||||
assertThat(ctx.containsBean(PROD_BEAN_NAME)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -199,8 +195,8 @@ public class EnvironmentSystemIntegrationTests {
|
||||
assertEnvironmentBeanRegistered(ctx);
|
||||
assertHasEnvironment(ctx, prodEnv);
|
||||
assertEnvironmentAwareInvoked(ctx, ctx.getEnvironment());
|
||||
assertThat(ctx.containsBean(DEV_BEAN_NAME), is(false));
|
||||
assertThat(ctx.containsBean(PROD_BEAN_NAME), is(true));
|
||||
assertThat(ctx.containsBean(DEV_BEAN_NAME)).isFalse();
|
||||
assertThat(ctx.containsBean(PROD_BEAN_NAME)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -217,8 +213,8 @@ public class EnvironmentSystemIntegrationTests {
|
||||
assertEnvironmentBeanRegistered(ctx);
|
||||
assertHasEnvironment(ctx, prodEnv);
|
||||
assertEnvironmentAwareInvoked(ctx, ctx.getEnvironment());
|
||||
assertThat(ctx.containsBean(DEV_BEAN_NAME), is(false));
|
||||
assertThat(ctx.containsBean(PROD_BEAN_NAME), is(true));
|
||||
assertThat(ctx.containsBean(DEV_BEAN_NAME)).isFalse();
|
||||
assertThat(ctx.containsBean(PROD_BEAN_NAME)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -244,7 +240,7 @@ public class EnvironmentSystemIntegrationTests {
|
||||
ctx.register(ProdConfig.class);
|
||||
ctx.refresh();
|
||||
|
||||
assertThat("should have prod bean", ctx.containsBean(PROD_BEAN_NAME), is(true));
|
||||
assertThat(ctx.containsBean(PROD_BEAN_NAME)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -257,8 +253,8 @@ public class EnvironmentSystemIntegrationTests {
|
||||
ctx.register(DevConfig.class);
|
||||
ctx.refresh();
|
||||
|
||||
assertThat("should not have dev bean", ctx.containsBean(DEV_BEAN_NAME), is(false));
|
||||
assertThat("should not have transitive bean", ctx.containsBean(TRANSITIVE_BEAN_NAME), is(false));
|
||||
assertThat(ctx.containsBean(DEV_BEAN_NAME)).isFalse();
|
||||
assertThat(ctx.containsBean(TRANSITIVE_BEAN_NAME)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -271,8 +267,8 @@ public class EnvironmentSystemIntegrationTests {
|
||||
ctx.register(DevConfig.class);
|
||||
ctx.refresh();
|
||||
|
||||
assertThat("should have dev bean", ctx.containsBean(DEV_BEAN_NAME), is(true));
|
||||
assertThat("should have transitive bean", ctx.containsBean(TRANSITIVE_BEAN_NAME), is(true));
|
||||
assertThat(ctx.containsBean(DEV_BEAN_NAME)).isTrue();
|
||||
assertThat(ctx.containsBean(TRANSITIVE_BEAN_NAME)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -286,9 +282,9 @@ public class EnvironmentSystemIntegrationTests {
|
||||
ctx.refresh();
|
||||
|
||||
assertEnvironmentAwareInvoked(ctx, prodEnv);
|
||||
assertThat("should have prod bean", ctx.containsBean(PROD_BEAN_NAME), is(true));
|
||||
assertThat("should not have dev bean", ctx.containsBean(DEV_BEAN_NAME), is(false));
|
||||
assertThat("should not have transitive bean", ctx.containsBean(TRANSITIVE_BEAN_NAME), is(false));
|
||||
assertThat(ctx.containsBean(PROD_BEAN_NAME)).isTrue();
|
||||
assertThat(ctx.containsBean(DEV_BEAN_NAME)).isFalse();
|
||||
assertThat(ctx.containsBean(TRANSITIVE_BEAN_NAME)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -300,9 +296,9 @@ public class EnvironmentSystemIntegrationTests {
|
||||
ctx.register(DerivedDevConfig.class);
|
||||
ctx.refresh();
|
||||
|
||||
assertThat("should have dev bean", ctx.containsBean(DEV_BEAN_NAME), is(true));
|
||||
assertThat("should have derived dev bean", ctx.containsBean(DERIVED_DEV_BEAN_NAME), is(true));
|
||||
assertThat("should have transitive bean", ctx.containsBean(TRANSITIVE_BEAN_NAME), is(true));
|
||||
assertThat(ctx.containsBean(DEV_BEAN_NAME)).isTrue();
|
||||
assertThat(ctx.containsBean(DERIVED_DEV_BEAN_NAME)).isTrue();
|
||||
assertThat(ctx.containsBean(TRANSITIVE_BEAN_NAME)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -312,9 +308,9 @@ public class EnvironmentSystemIntegrationTests {
|
||||
ctx.register(DerivedDevConfig.class);
|
||||
ctx.refresh();
|
||||
|
||||
assertThat("should not have dev bean", ctx.containsBean(DEV_BEAN_NAME), is(false));
|
||||
assertThat("should not have derived dev bean", ctx.containsBean(DERIVED_DEV_BEAN_NAME), is(false));
|
||||
assertThat("should not have transitive bean", ctx.containsBean(TRANSITIVE_BEAN_NAME), is(false));
|
||||
assertThat(ctx.containsBean(DEV_BEAN_NAME)).isFalse();
|
||||
assertThat(ctx.containsBean(DERIVED_DEV_BEAN_NAME)).isFalse();
|
||||
assertThat(ctx.containsBean(TRANSITIVE_BEAN_NAME)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -344,8 +340,7 @@ public class EnvironmentSystemIntegrationTests {
|
||||
ctx.setEnvironment(environment);
|
||||
ctx.register(ProfileExpressionConfig.class);
|
||||
ctx.refresh();
|
||||
assertThat("wrong presence of expression bean",
|
||||
ctx.containsBean("expressionBean"), is(expected));
|
||||
assertThat(ctx.containsBean("expressionBean")).isEqualTo(expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -370,8 +365,8 @@ public class EnvironmentSystemIntegrationTests {
|
||||
assertHasEnvironment(ctx, prodWebEnv);
|
||||
assertEnvironmentBeanRegistered(ctx);
|
||||
assertEnvironmentAwareInvoked(ctx, prodWebEnv);
|
||||
assertThat(ctx.containsBean(DEV_BEAN_NAME), is(false));
|
||||
assertThat(ctx.containsBean(PROD_BEAN_NAME), is(true));
|
||||
assertThat(ctx.containsBean(DEV_BEAN_NAME)).isFalse();
|
||||
assertThat(ctx.containsBean(PROD_BEAN_NAME)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -434,23 +429,23 @@ public class EnvironmentSystemIntegrationTests {
|
||||
ctx.refresh();
|
||||
|
||||
ConfigurableEnvironment environment = ctx.getEnvironment();
|
||||
assertThat(environment, instanceOf(StandardServletEnvironment.class));
|
||||
assertThat(environment).isInstanceOf(StandardServletEnvironment.class);
|
||||
MutablePropertySources propertySources = environment.getPropertySources();
|
||||
assertThat(propertySources.contains(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME), is(true));
|
||||
assertThat(propertySources.contains(StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME), is(true));
|
||||
assertThat(propertySources.contains(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME)).isTrue();
|
||||
assertThat(propertySources.contains(StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME)).isTrue();
|
||||
|
||||
// ServletConfig gets precedence
|
||||
assertThat(environment.getProperty("pCommon"), is("pCommonConfigValue"));
|
||||
assertThat(propertySources.precedenceOf(PropertySource.named(StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME)),
|
||||
lessThan(propertySources.precedenceOf(PropertySource.named(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME))));
|
||||
assertThat(environment.getProperty("pCommon")).isEqualTo("pCommonConfigValue");
|
||||
assertThat(propertySources.precedenceOf(PropertySource.named(StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME)))
|
||||
.isLessThan(propertySources.precedenceOf(PropertySource.named(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME)));
|
||||
|
||||
// but all params are available
|
||||
assertThat(environment.getProperty("pContext1"), is("pContext1Value"));
|
||||
assertThat(environment.getProperty("pConfig1"), is("pConfig1Value"));
|
||||
assertThat(environment.getProperty("pContext1")).isEqualTo("pContext1Value");
|
||||
assertThat(environment.getProperty("pConfig1")).isEqualTo("pConfig1Value");
|
||||
|
||||
// Servlet* PropertySources have precedence over System* PropertySources
|
||||
assertThat(propertySources.precedenceOf(PropertySource.named(StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME)),
|
||||
lessThan(propertySources.precedenceOf(PropertySource.named(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME))));
|
||||
assertThat(propertySources.precedenceOf(PropertySource.named(StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME)))
|
||||
.isLessThan(propertySources.precedenceOf(PropertySource.named(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME)));
|
||||
|
||||
// Replace system properties with a mock property source for convenience
|
||||
MockPropertySource mockSystemProperties = new MockPropertySource(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME);
|
||||
@@ -459,8 +454,8 @@ public class EnvironmentSystemIntegrationTests {
|
||||
propertySources.replace(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME, mockSystemProperties);
|
||||
|
||||
// assert that servletconfig params resolve with higher precedence than sysprops
|
||||
assertThat(environment.getProperty("pCommon"), is("pCommonConfigValue"));
|
||||
assertThat(environment.getProperty("pSysProps1"), is("pSysProps1Value"));
|
||||
assertThat(environment.getProperty("pCommon")).isEqualTo("pCommonConfigValue");
|
||||
assertThat(environment.getProperty("pSysProps1")).isEqualTo("pSysProps1Value");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -474,17 +469,17 @@ public class EnvironmentSystemIntegrationTests {
|
||||
ctx.refresh();
|
||||
|
||||
ConfigurableEnvironment environment = ctx.getEnvironment();
|
||||
assertThat(environment, instanceOf(StandardServletEnvironment.class));
|
||||
assertThat(environment).isInstanceOf(StandardServletEnvironment.class);
|
||||
MutablePropertySources propertySources = environment.getPropertySources();
|
||||
assertThat(propertySources.contains(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME), is(true));
|
||||
assertThat(propertySources.contains(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME)).isTrue();
|
||||
|
||||
// ServletContext params are available
|
||||
assertThat(environment.getProperty("pCommon"), is("pCommonContextValue"));
|
||||
assertThat(environment.getProperty("pContext1"), is("pContext1Value"));
|
||||
assertThat(environment.getProperty("pCommon")).isEqualTo("pCommonContextValue");
|
||||
assertThat(environment.getProperty("pContext1")).isEqualTo("pContext1Value");
|
||||
|
||||
// Servlet* PropertySources have precedence over System* PropertySources
|
||||
assertThat(propertySources.precedenceOf(PropertySource.named(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME)),
|
||||
lessThan(propertySources.precedenceOf(PropertySource.named(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME))));
|
||||
assertThat(propertySources.precedenceOf(PropertySource.named(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME)))
|
||||
.isLessThan(propertySources.precedenceOf(PropertySource.named(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME)));
|
||||
|
||||
// Replace system properties with a mock property source for convenience
|
||||
MockPropertySource mockSystemProperties = new MockPropertySource(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME);
|
||||
@@ -493,8 +488,8 @@ public class EnvironmentSystemIntegrationTests {
|
||||
propertySources.replace(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME, mockSystemProperties);
|
||||
|
||||
// assert that servletcontext init params resolve with higher precedence than sysprops
|
||||
assertThat(environment.getProperty("pCommon"), is("pCommonContextValue"));
|
||||
assertThat(environment.getProperty("pSysProps1"), is("pSysProps1Value"));
|
||||
assertThat(environment.getProperty("pCommon")).isEqualTo("pCommonContextValue");
|
||||
assertThat(environment.getProperty("pSysProps1")).isEqualTo("pSysProps1Value");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -513,21 +508,21 @@ public class EnvironmentSystemIntegrationTests {
|
||||
|
||||
ConfigurableEnvironment environment = ctx.getEnvironment();
|
||||
MutablePropertySources propertySources = environment.getPropertySources();
|
||||
assertThat(propertySources.contains(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME), is(true));
|
||||
assertThat(propertySources.contains(StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME), is(true));
|
||||
assertThat(propertySources.contains(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME)).isTrue();
|
||||
assertThat(propertySources.contains(StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME)).isTrue();
|
||||
|
||||
// ServletConfig gets precedence
|
||||
assertThat(environment.getProperty("pCommon"), is("pCommonConfigValue"));
|
||||
assertThat(propertySources.precedenceOf(PropertySource.named(StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME)),
|
||||
lessThan(propertySources.precedenceOf(PropertySource.named(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME))));
|
||||
assertThat(environment.getProperty("pCommon")).isEqualTo("pCommonConfigValue");
|
||||
assertThat(propertySources.precedenceOf(PropertySource.named(StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME)))
|
||||
.isLessThan(propertySources.precedenceOf(PropertySource.named(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME)));
|
||||
|
||||
// but all params are available
|
||||
assertThat(environment.getProperty("pContext1"), is("pContext1Value"));
|
||||
assertThat(environment.getProperty("pConfig1"), is("pConfig1Value"));
|
||||
assertThat(environment.getProperty("pContext1")).isEqualTo("pContext1Value");
|
||||
assertThat(environment.getProperty("pConfig1")).isEqualTo("pConfig1Value");
|
||||
|
||||
// Servlet* PropertySources have precedence over System* PropertySources
|
||||
assertThat(propertySources.precedenceOf(PropertySource.named(StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME)),
|
||||
lessThan(propertySources.precedenceOf(PropertySource.named(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME))));
|
||||
assertThat(propertySources.precedenceOf(PropertySource.named(StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME)))
|
||||
.isLessThan(propertySources.precedenceOf(PropertySource.named(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME)));
|
||||
|
||||
// Replace system properties with a mock property source for convenience
|
||||
MockPropertySource mockSystemProperties = new MockPropertySource(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME);
|
||||
@@ -536,8 +531,8 @@ public class EnvironmentSystemIntegrationTests {
|
||||
propertySources.replace(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME, mockSystemProperties);
|
||||
|
||||
// assert that servletconfig params resolve with higher precedence than sysprops
|
||||
assertThat(environment.getProperty("pCommon"), is("pCommonConfigValue"));
|
||||
assertThat(environment.getProperty("pSysProps1"), is("pSysProps1Value"));
|
||||
assertThat(environment.getProperty("pCommon")).isEqualTo("pCommonConfigValue");
|
||||
assertThat(environment.getProperty("pSysProps1")).isEqualTo("pSysProps1Value");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -593,33 +588,33 @@ public class EnvironmentSystemIntegrationTests {
|
||||
private void assertEnvironmentBeanRegistered(
|
||||
ConfigurableApplicationContext ctx) {
|
||||
// ensure environment is registered as a bean
|
||||
assertThat(ctx.containsBean(ENVIRONMENT_BEAN_NAME), is(true));
|
||||
assertThat(ctx.containsBean(ENVIRONMENT_BEAN_NAME)).isTrue();
|
||||
}
|
||||
|
||||
private void assertHasStandardEnvironment(ApplicationContext ctx) {
|
||||
Environment defaultEnv = ctx.getEnvironment();
|
||||
assertThat(defaultEnv, notNullValue());
|
||||
assertThat(defaultEnv, instanceOf(StandardEnvironment.class));
|
||||
assertThat(defaultEnv).isNotNull();
|
||||
assertThat(defaultEnv).isInstanceOf(StandardEnvironment.class);
|
||||
}
|
||||
|
||||
private void assertHasStandardServletEnvironment(WebApplicationContext ctx) {
|
||||
// ensure a default servlet environment exists
|
||||
Environment defaultEnv = ctx.getEnvironment();
|
||||
assertThat(defaultEnv, notNullValue());
|
||||
assertThat(defaultEnv, instanceOf(StandardServletEnvironment.class));
|
||||
assertThat(defaultEnv).isNotNull();
|
||||
assertThat(defaultEnv).isInstanceOf(StandardServletEnvironment.class);
|
||||
}
|
||||
|
||||
private void assertHasEnvironment(ApplicationContext ctx, Environment expectedEnv) {
|
||||
// ensure the custom environment took
|
||||
Environment actualEnv = ctx.getEnvironment();
|
||||
assertThat(actualEnv, notNullValue());
|
||||
assertThat(actualEnv, is(expectedEnv));
|
||||
assertThat(actualEnv).isNotNull();
|
||||
assertThat(actualEnv).isEqualTo(expectedEnv);
|
||||
// ensure environment is registered as a bean
|
||||
assertThat(ctx.containsBean(ENVIRONMENT_BEAN_NAME), is(true));
|
||||
assertThat(ctx.containsBean(ENVIRONMENT_BEAN_NAME)).isTrue();
|
||||
}
|
||||
|
||||
private void assertEnvironmentAwareInvoked(ConfigurableApplicationContext ctx, Environment expectedEnv) {
|
||||
assertThat(ctx.getBean(EnvironmentAwareBean.class).environment, is(expectedEnv));
|
||||
assertThat(ctx.getBean(EnvironmentAwareBean.class).environment).isEqualTo(expectedEnv);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -41,10 +41,6 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
@@ -85,9 +81,9 @@ public class ScheduledAndTransactionalAnnotationIntegrationTests {
|
||||
|
||||
MyRepository repository = ctx.getBean(MyRepository.class);
|
||||
CallCountingTransactionManager txManager = ctx.getBean(CallCountingTransactionManager.class);
|
||||
assertThat("repository is not a proxy", AopUtils.isCglibProxy(repository), equalTo(true));
|
||||
assertThat("@Scheduled method never called", repository.getInvocationCount(), greaterThan(0));
|
||||
assertThat("no transactions were committed", txManager.commits, greaterThan(0));
|
||||
assertThat(AopUtils.isCglibProxy(repository)).isEqualTo(true);
|
||||
assertThat(repository.getInvocationCount()).isGreaterThan(0);
|
||||
assertThat(txManager.commits).isGreaterThan(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -100,9 +96,9 @@ public class ScheduledAndTransactionalAnnotationIntegrationTests {
|
||||
|
||||
MyRepositoryWithScheduledMethod repository = ctx.getBean(MyRepositoryWithScheduledMethod.class);
|
||||
CallCountingTransactionManager txManager = ctx.getBean(CallCountingTransactionManager.class);
|
||||
assertThat("repository is not a proxy", AopUtils.isJdkDynamicProxy(repository), is(true));
|
||||
assertThat("@Scheduled method never called", repository.getInvocationCount(), greaterThan(0));
|
||||
assertThat("no transactions were committed", txManager.commits, greaterThan(0));
|
||||
assertThat(AopUtils.isJdkDynamicProxy(repository)).isTrue();
|
||||
assertThat(repository.getInvocationCount()).isGreaterThan(0);
|
||||
assertThat(txManager.commits).isGreaterThan(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -114,8 +110,8 @@ public class ScheduledAndTransactionalAnnotationIntegrationTests {
|
||||
Thread.sleep(100); // allow @Scheduled method to be called several times
|
||||
|
||||
MyRepositoryWithScheduledMethod repository = ctx.getBean(MyRepositoryWithScheduledMethod.class);
|
||||
assertThat("repository is not a proxy", AopUtils.isCglibProxy(repository), is(true));
|
||||
assertThat("@Scheduled method never called", repository.getInvocationCount(), greaterThan(0));
|
||||
assertThat(AopUtils.isCglibProxy(repository)).isTrue();
|
||||
assertThat(repository.getInvocationCount()).isGreaterThan(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -44,9 +44,6 @@ import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.interceptor.BeanFactoryTransactionAttributeSourceAdvisor;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
@@ -97,7 +94,7 @@ public class EnableTransactionManagementIntegrationTests {
|
||||
ctx.refresh();
|
||||
|
||||
assertTxProxying(ctx);
|
||||
assertThat(AopUtils.isCglibProxy(ctx.getBean(FooRepository.class)), is(true));
|
||||
assertThat(AopUtils.isCglibProxy(ctx.getBean(FooRepository.class))).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -125,9 +122,9 @@ public class EnableTransactionManagementIntegrationTests {
|
||||
fooRepository.findAll();
|
||||
|
||||
CallCountingTransactionManager txManager = ctx.getBean(CallCountingTransactionManager.class);
|
||||
assertThat(txManager.begun, equalTo(1));
|
||||
assertThat(txManager.commits, equalTo(1));
|
||||
assertThat(txManager.rollbacks, equalTo(0));
|
||||
assertThat(txManager.begun).isEqualTo(1);
|
||||
assertThat(txManager.commits).isEqualTo(1);
|
||||
assertThat(txManager.rollbacks).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -140,14 +137,14 @@ public class EnableTransactionManagementIntegrationTests {
|
||||
fooRepository.findAll();
|
||||
|
||||
CallCountingTransactionManager txManager1 = ctx.getBean("txManager1", CallCountingTransactionManager.class);
|
||||
assertThat(txManager1.begun, equalTo(1));
|
||||
assertThat(txManager1.commits, equalTo(1));
|
||||
assertThat(txManager1.rollbacks, equalTo(0));
|
||||
assertThat(txManager1.begun).isEqualTo(1);
|
||||
assertThat(txManager1.commits).isEqualTo(1);
|
||||
assertThat(txManager1.rollbacks).isEqualTo(0);
|
||||
|
||||
CallCountingTransactionManager txManager2 = ctx.getBean("txManager2", CallCountingTransactionManager.class);
|
||||
assertThat(txManager2.begun, equalTo(0));
|
||||
assertThat(txManager2.commits, equalTo(0));
|
||||
assertThat(txManager2.rollbacks, equalTo(0));
|
||||
assertThat(txManager2.begun).isEqualTo(0);
|
||||
assertThat(txManager2.commits).isEqualTo(0);
|
||||
assertThat(txManager2.rollbacks).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -22,9 +22,7 @@ import org.springframework.aop.support.AopUtils;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.hamcrest.CoreMatchers.not;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
@@ -47,7 +45,7 @@ public class ProxyAnnotationDiscoveryTests {
|
||||
ctx.refresh();
|
||||
AnnotatedServiceWithoutInterface s = ctx.getBean(AnnotatedServiceWithoutInterface.class);
|
||||
assertTrue("expected a subclass proxy", AopUtils.isCglibProxy(s));
|
||||
assertThat(s, instanceOf(AnnotatedServiceWithoutInterface.class));
|
||||
assertThat(s).isInstanceOf(AnnotatedServiceWithoutInterface.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -57,7 +55,7 @@ public class ProxyAnnotationDiscoveryTests {
|
||||
ctx.refresh();
|
||||
AnnotatedServiceWithoutInterface s = ctx.getBean(AnnotatedServiceWithoutInterface.class);
|
||||
assertTrue("expected a subclass proxy", AopUtils.isCglibProxy(s));
|
||||
assertThat(s, instanceOf(AnnotatedServiceWithoutInterface.class));
|
||||
assertThat(s).isInstanceOf(AnnotatedServiceWithoutInterface.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -67,7 +65,7 @@ public class ProxyAnnotationDiscoveryTests {
|
||||
ctx.refresh();
|
||||
NonAnnotatedService s = ctx.getBean(NonAnnotatedService.class);
|
||||
assertTrue("expected a subclass proxy", AopUtils.isCglibProxy(s));
|
||||
assertThat(s, instanceOf(AnnotatedServiceImpl.class));
|
||||
assertThat(s).isInstanceOf(AnnotatedServiceImpl.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -77,7 +75,7 @@ public class ProxyAnnotationDiscoveryTests {
|
||||
ctx.refresh();
|
||||
NonAnnotatedService s = ctx.getBean(NonAnnotatedService.class);
|
||||
assertTrue("expected a jdk proxy", AopUtils.isJdkDynamicProxy(s));
|
||||
assertThat(s, not(instanceOf(AnnotatedServiceImpl.class)));
|
||||
assertThat(s).isNotInstanceOf(AnnotatedServiceImpl.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -87,7 +85,7 @@ public class ProxyAnnotationDiscoveryTests {
|
||||
ctx.refresh();
|
||||
AnnotatedService s = ctx.getBean(AnnotatedService.class);
|
||||
assertTrue("expected a subclass proxy", AopUtils.isCglibProxy(s));
|
||||
assertThat(s, instanceOf(NonAnnotatedServiceImpl.class));
|
||||
assertThat(s).isInstanceOf(NonAnnotatedServiceImpl.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -97,7 +95,7 @@ public class ProxyAnnotationDiscoveryTests {
|
||||
ctx.refresh();
|
||||
AnnotatedService s = ctx.getBean(AnnotatedService.class);
|
||||
assertTrue("expected a jdk proxy", AopUtils.isJdkDynamicProxy(s));
|
||||
assertThat(s, not(instanceOf(NonAnnotatedServiceImpl.class)));
|
||||
assertThat(s).isNotInstanceOf(NonAnnotatedServiceImpl.class);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user