提交 3fa4d638 编写于 作者: S Sam Brannen

Polish tests in integration-tests

上级 998f6af2
......@@ -16,23 +16,20 @@
package org.springframework.aop.config;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.aop.framework.Advised;
import org.springframework.aop.support.AopUtils;
import org.springframework.context.ApplicationContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpSession;
import org.springframework.test.context.junit.jupiter.web.SpringJUnitWebConfig;
import org.springframework.tests.sample.beans.ITestBean;
import org.springframework.tests.sample.beans.TestBean;
import org.springframework.util.ClassUtils;
import org.springframework.util.SerializationTestUtils;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.context.support.XmlWebApplicationContext;
import static java.lang.String.format;
import static org.assertj.core.api.Assertions.assertThat;
/**
......@@ -44,51 +41,50 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Chris Beams
* @see org.springframework.aop.config.AopNamespaceHandlerTests
*/
public class AopNamespaceHandlerScopeIntegrationTests {
@SpringJUnitWebConfig
class AopNamespaceHandlerScopeIntegrationTests {
private static final String CONTEXT = format("classpath:%s-context.xml",
ClassUtils.convertClassNameToResourcePath(AopNamespaceHandlerScopeIntegrationTests.class.getName()));
@Autowired
ITestBean singletonScoped;
private ApplicationContext context;
@Autowired
ITestBean requestScoped;
@Autowired
ITestBean sessionScoped;
@BeforeEach
public void setUp() {
XmlWebApplicationContext wac = new XmlWebApplicationContext();
wac.setConfigLocations(CONTEXT);
wac.refresh();
this.context = wac;
}
@Autowired
ITestBean sessionScopedAlias;
@Autowired
ITestBean testBean;
@Test
public void testSingletonScoping() throws Exception {
ITestBean scoped = (ITestBean) this.context.getBean("singletonScoped");
assertThat(AopUtils.isAopProxy(scoped)).as("Should be AOP proxy").isTrue();
boolean condition = scoped instanceof TestBean;
void testSingletonScoping() throws Exception {
assertThat(AopUtils.isAopProxy(singletonScoped)).as("Should be AOP proxy").isTrue();
boolean condition = singletonScoped instanceof TestBean;
assertThat(condition).as("Should be target class proxy").isTrue();
String rob = "Rob Harrop";
String bram = "Bram Smeets";
assertThat(scoped.getName()).isEqualTo(rob);
scoped.setName(bram);
assertThat(scoped.getName()).isEqualTo(bram);
ITestBean deserialized = (ITestBean) SerializationTestUtils.serializeAndDeserialize(scoped);
assertThat(singletonScoped.getName()).isEqualTo(rob);
singletonScoped.setName(bram);
assertThat(singletonScoped.getName()).isEqualTo(bram);
ITestBean deserialized = (ITestBean) SerializationTestUtils.serializeAndDeserialize(singletonScoped);
assertThat(deserialized.getName()).isEqualTo(bram);
}
@Test
public void testRequestScoping() throws Exception {
void testRequestScoping() throws Exception {
MockHttpServletRequest oldRequest = new MockHttpServletRequest();
MockHttpServletRequest newRequest = new MockHttpServletRequest();
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(oldRequest));
ITestBean scoped = (ITestBean) this.context.getBean("requestScoped");
assertThat(AopUtils.isAopProxy(scoped)).as("Should be AOP proxy").isTrue();
boolean condition = scoped instanceof TestBean;
assertThat(AopUtils.isAopProxy(requestScoped)).as("Should be AOP proxy").isTrue();
boolean condition = requestScoped instanceof TestBean;
assertThat(condition).as("Should be target class proxy").isTrue();
ITestBean testBean = (ITestBean) this.context.getBean("testBean");
assertThat(AopUtils.isAopProxy(testBean)).as("Should be AOP proxy").isTrue();
boolean condition1 = testBean instanceof TestBean;
assertThat(condition1).as("Regular bean should be JDK proxy").isFalse();
......@@ -96,18 +92,18 @@ public class AopNamespaceHandlerScopeIntegrationTests {
String rob = "Rob Harrop";
String bram = "Bram Smeets";
assertThat(scoped.getName()).isEqualTo(rob);
scoped.setName(bram);
assertThat(requestScoped.getName()).isEqualTo(rob);
requestScoped.setName(bram);
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(newRequest));
assertThat(scoped.getName()).isEqualTo(rob);
assertThat(requestScoped.getName()).isEqualTo(rob);
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(oldRequest));
assertThat(scoped.getName()).isEqualTo(bram);
assertThat(requestScoped.getName()).isEqualTo(bram);
assertThat(((Advised) scoped).getAdvisors().length > 0).as("Should have advisors").isTrue();
assertThat(((Advised) requestScoped).getAdvisors().length > 0).as("Should have advisors").isTrue();
}
@Test
public void testSessionScoping() throws Exception {
void testSessionScoping() throws Exception {
MockHttpSession oldSession = new MockHttpSession();
MockHttpSession newSession = new MockHttpSession();
......@@ -115,15 +111,12 @@ public class AopNamespaceHandlerScopeIntegrationTests {
request.setSession(oldSession);
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request));
ITestBean scoped = (ITestBean) this.context.getBean("sessionScoped");
assertThat(AopUtils.isAopProxy(scoped)).as("Should be AOP proxy").isTrue();
boolean condition1 = scoped instanceof TestBean;
assertThat(AopUtils.isAopProxy(sessionScoped)).as("Should be AOP proxy").isTrue();
boolean condition1 = sessionScoped instanceof TestBean;
assertThat(condition1).as("Should not be target class proxy").isFalse();
ITestBean scopedAlias = (ITestBean) this.context.getBean("sessionScopedAlias");
assertThat(scopedAlias).isSameAs(scoped);
assertThat(sessionScopedAlias).isSameAs(sessionScoped);
ITestBean testBean = (ITestBean) this.context.getBean("testBean");
assertThat(AopUtils.isAopProxy(testBean)).as("Should be AOP proxy").isTrue();
boolean condition = testBean instanceof TestBean;
assertThat(condition).as("Regular bean should be JDK proxy").isFalse();
......@@ -131,14 +124,14 @@ public class AopNamespaceHandlerScopeIntegrationTests {
String rob = "Rob Harrop";
String bram = "Bram Smeets";
assertThat(scoped.getName()).isEqualTo(rob);
scoped.setName(bram);
assertThat(sessionScoped.getName()).isEqualTo(rob);
sessionScoped.setName(bram);
request.setSession(newSession);
assertThat(scoped.getName()).isEqualTo(rob);
assertThat(sessionScoped.getName()).isEqualTo(rob);
request.setSession(oldSession);
assertThat(scoped.getName()).isEqualTo(bram);
assertThat(sessionScoped.getName()).isEqualTo(bram);
assertThat(((Advised) scoped).getAdvisors().length > 0).as("Should have advisors").isTrue();
assertThat(((Advised) sessionScoped).getAdvisors().length > 0).as("Should have advisors").isTrue();
}
}
......@@ -48,7 +48,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Rod Johnson
* @author Chris Beams
*/
public class AdvisorAutoProxyCreatorIntegrationTests {
class AdvisorAutoProxyCreatorIntegrationTests {
private static final Class<?> CLASS = AdvisorAutoProxyCreatorIntegrationTests.class;
private static final String CLASSNAME = CLASS.getSimpleName();
......@@ -66,7 +66,7 @@ public class AdvisorAutoProxyCreatorIntegrationTests {
}
@Test
public void testDefaultExclusionPrefix() throws Exception {
void testDefaultExclusionPrefix() throws Exception {
DefaultAdvisorAutoProxyCreator aapc = (DefaultAdvisorAutoProxyCreator) getBeanFactory().getBean(ADVISOR_APC_BEAN_NAME);
assertThat(aapc.getAdvisorBeanNamePrefix()).isEqualTo((ADVISOR_APC_BEAN_NAME + DefaultAdvisorAutoProxyCreator.SEPARATOR));
assertThat(aapc.isUsePrefix()).isFalse();
......@@ -76,21 +76,21 @@ public class AdvisorAutoProxyCreatorIntegrationTests {
* If no pointcuts match (no attrs) there should be proxying.
*/
@Test
public void testNoProxy() throws Exception {
void testNoProxy() throws Exception {
BeanFactory bf = getBeanFactory();
Object o = bf.getBean("noSetters");
assertThat(AopUtils.isAopProxy(o)).isFalse();
}
@Test
public void testTxIsProxied() throws Exception {
void testTxIsProxied() throws Exception {
BeanFactory bf = getBeanFactory();
ITestBean test = (ITestBean) bf.getBean("test");
assertThat(AopUtils.isAopProxy(test)).isTrue();
}
@Test
public void testRegexpApplied() throws Exception {
void testRegexpApplied() throws Exception {
BeanFactory bf = getBeanFactory();
ITestBean test = (ITestBean) bf.getBean("test");
MethodCounter counter = (MethodCounter) bf.getBean("countingAdvice");
......@@ -100,7 +100,7 @@ public class AdvisorAutoProxyCreatorIntegrationTests {
}
@Test
public void testTransactionAttributeOnMethod() throws Exception {
void testTransactionAttributeOnMethod() throws Exception {
BeanFactory bf = getBeanFactory();
ITestBean test = (ITestBean) bf.getBean("test");
......@@ -122,7 +122,7 @@ public class AdvisorAutoProxyCreatorIntegrationTests {
* Should not roll back on servlet exception.
*/
@Test
public void testRollbackRulesOnMethodCauseRollback() throws Exception {
void testRollbackRulesOnMethodCauseRollback() throws Exception {
BeanFactory bf = getBeanFactory();
Rollback rb = (Rollback) bf.getBean("rollback");
......@@ -148,7 +148,7 @@ public class AdvisorAutoProxyCreatorIntegrationTests {
}
@Test
public void testRollbackRulesOnMethodPreventRollback() throws Exception {
void testRollbackRulesOnMethodPreventRollback() throws Exception {
BeanFactory bf = getBeanFactory();
Rollback rb = (Rollback) bf.getBean("rollback");
......@@ -166,7 +166,7 @@ public class AdvisorAutoProxyCreatorIntegrationTests {
}
@Test
public void testProgrammaticRollback() throws Exception {
void testProgrammaticRollback() throws Exception {
BeanFactory bf = getBeanFactory();
Object bean = bf.getBean(TXMANAGER_BEAN_NAME);
......
......@@ -43,10 +43,10 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
* @since 3.1
*/
@SuppressWarnings("resource")
public class EnableCachingIntegrationTests {
class EnableCachingIntegrationTests {
@Test
public void repositoryIsClassBasedCacheProxy() {
void repositoryIsClassBasedCacheProxy() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(Config.class, ProxyTargetClassCachingConfig.class);
ctx.refresh();
......@@ -56,7 +56,7 @@ public class EnableCachingIntegrationTests {
}
@Test
public void repositoryUsesAspectJAdviceMode() {
void repositoryUsesAspectJAdviceMode() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(Config.class, AspectJCacheConfig.class);
// this test is a bit fragile, but gets the job done, proving that an
......
......@@ -48,7 +48,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Juergen Hoeller
* @author Chris Beams
*/
public class ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests {
class ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests {
private static final String DEFAULT_NAME = "default";
......@@ -64,7 +64,7 @@ public class ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests {
@BeforeEach
public void setUp() {
void setUp() {
this.oldRequestAttributes = new ServletRequestAttributes(new MockHttpServletRequest());
this.newRequestAttributes = new ServletRequestAttributes(new MockHttpServletRequest());
......@@ -78,13 +78,13 @@ public class ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests {
}
@AfterEach
public void tearDown() throws Exception {
void tearDown() throws Exception {
RequestContextHolder.setRequestAttributes(null);
}
@Test
public void testPrototype() {
void testPrototype() {
ApplicationContext context = createContext(ScopedProxyMode.NO);
ScopedTestBean bean = (ScopedTestBean) context.getBean("prototype");
assertThat(bean).isNotNull();
......@@ -93,7 +93,7 @@ public class ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests {
}
@Test
public void testSingletonScopeWithNoProxy() {
void testSingletonScopeWithNoProxy() {
RequestContextHolder.setRequestAttributes(oldRequestAttributes);
ApplicationContext context = createContext(ScopedProxyMode.NO);
ScopedTestBean bean = (ScopedTestBean) context.getBean("singleton");
......@@ -116,7 +116,7 @@ public class ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests {
}
@Test
public void testSingletonScopeIgnoresProxyInterfaces() {
void testSingletonScopeIgnoresProxyInterfaces() {
RequestContextHolder.setRequestAttributes(oldRequestAttributes);
ApplicationContext context = createContext(ScopedProxyMode.INTERFACES);
ScopedTestBean bean = (ScopedTestBean) context.getBean("singleton");
......@@ -137,7 +137,7 @@ public class ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests {
}
@Test
public void testSingletonScopeIgnoresProxyTargetClass() {
void testSingletonScopeIgnoresProxyTargetClass() {
RequestContextHolder.setRequestAttributes(oldRequestAttributes);
ApplicationContext context = createContext(ScopedProxyMode.TARGET_CLASS);
ScopedTestBean bean = (ScopedTestBean) context.getBean("singleton");
......@@ -158,7 +158,7 @@ public class ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests {
}
@Test
public void testRequestScopeWithNoProxy() {
void testRequestScopeWithNoProxy() {
RequestContextHolder.setRequestAttributes(oldRequestAttributes);
ApplicationContext context = createContext(ScopedProxyMode.NO);
ScopedTestBean bean = (ScopedTestBean) context.getBean("request");
......@@ -179,7 +179,7 @@ public class ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests {
}
@Test
public void testRequestScopeWithProxiedInterfaces() {
void testRequestScopeWithProxiedInterfaces() {
RequestContextHolder.setRequestAttributes(oldRequestAttributes);
ApplicationContext context = createContext(ScopedProxyMode.INTERFACES);
IScopedTestBean bean = (IScopedTestBean) context.getBean("request");
......@@ -201,7 +201,7 @@ public class ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests {
}
@Test
public void testRequestScopeWithProxiedTargetClass() {
void testRequestScopeWithProxiedTargetClass() {
RequestContextHolder.setRequestAttributes(oldRequestAttributes);
ApplicationContext context = createContext(ScopedProxyMode.TARGET_CLASS);
IScopedTestBean bean = (IScopedTestBean) context.getBean("request");
......@@ -223,7 +223,7 @@ public class ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests {
}
@Test
public void testSessionScopeWithNoProxy() {
void testSessionScopeWithNoProxy() {
RequestContextHolder.setRequestAttributes(oldRequestAttributesWithSession);
ApplicationContext context = createContext(ScopedProxyMode.NO);
ScopedTestBean bean = (ScopedTestBean) context.getBean("session");
......@@ -244,7 +244,7 @@ public class ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests {
}
@Test
public void testSessionScopeWithProxiedInterfaces() {
void testSessionScopeWithProxiedInterfaces() {
RequestContextHolder.setRequestAttributes(oldRequestAttributesWithSession);
ApplicationContext context = createContext(ScopedProxyMode.INTERFACES);
IScopedTestBean bean = (IScopedTestBean) context.getBean("session");
......@@ -272,7 +272,7 @@ public class ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests {
}
@Test
public void testSessionScopeWithProxiedTargetClass() {
void testSessionScopeWithProxiedTargetClass() {
RequestContextHolder.setRequestAttributes(oldRequestAttributesWithSession);
ApplicationContext context = createContext(ScopedProxyMode.TARGET_CLASS);
IScopedTestBean bean = (IScopedTestBean) context.getBean("session");
......@@ -341,7 +341,7 @@ public class ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests {
}
public static interface IScopedTestBean {
public interface IScopedTestBean {
String getName();
......@@ -372,7 +372,7 @@ public class ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests {
}
public static interface AnotherScopeTestInterface {
public interface AnotherScopeTestInterface {
}
......@@ -391,14 +391,14 @@ public class ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests {
@Target({ElementType.FIELD, ElementType.PARAMETER, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@javax.inject.Scope
public static @interface RequestScoped {
public @interface RequestScoped {
}
@Target({ElementType.FIELD, ElementType.PARAMETER, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@javax.inject.Scope
public static @interface SessionScoped {
public @interface SessionScoped {
}
}
......@@ -45,7 +45,7 @@ import static org.springframework.context.annotation.ScopedProxyMode.TARGET_CLAS
* @author Chris Beams
* @author Sam Brannen
*/
public class ClassPathBeanDefinitionScannerScopeIntegrationTests {
class ClassPathBeanDefinitionScannerScopeIntegrationTests {
private static final String DEFAULT_NAME = "default";
private static final String MODIFIED_NAME = "modified";
......@@ -58,7 +58,7 @@ public class ClassPathBeanDefinitionScannerScopeIntegrationTests {
@BeforeEach
public void setUp() {
void setUp() {
MockHttpServletRequest oldRequestWithSession = new MockHttpServletRequest();
oldRequestWithSession.setSession(new MockHttpSession());
this.oldRequestAttributesWithSession = new ServletRequestAttributes(oldRequestWithSession);
......@@ -69,13 +69,13 @@ public class ClassPathBeanDefinitionScannerScopeIntegrationTests {
}
@AfterEach
public void tearDown() throws Exception {
void tearDown() throws Exception {
RequestContextHolder.resetRequestAttributes();
}
@Test
public void singletonScopeWithNoProxy() {
void singletonScopeWithNoProxy() {
RequestContextHolder.setRequestAttributes(oldRequestAttributes);
ApplicationContext context = createContext(NO);
ScopedTestBean bean = (ScopedTestBean) context.getBean("singleton");
......@@ -96,7 +96,7 @@ public class ClassPathBeanDefinitionScannerScopeIntegrationTests {
}
@Test
public void singletonScopeIgnoresProxyInterfaces() {
void singletonScopeIgnoresProxyInterfaces() {
RequestContextHolder.setRequestAttributes(oldRequestAttributes);
ApplicationContext context = createContext(INTERFACES);
ScopedTestBean bean = (ScopedTestBean) context.getBean("singleton");
......@@ -117,7 +117,7 @@ public class ClassPathBeanDefinitionScannerScopeIntegrationTests {
}
@Test
public void singletonScopeIgnoresProxyTargetClass() {
void singletonScopeIgnoresProxyTargetClass() {
RequestContextHolder.setRequestAttributes(oldRequestAttributes);
ApplicationContext context = createContext(TARGET_CLASS);
ScopedTestBean bean = (ScopedTestBean) context.getBean("singleton");
......@@ -138,7 +138,7 @@ public class ClassPathBeanDefinitionScannerScopeIntegrationTests {
}
@Test
public void requestScopeWithNoProxy() {
void requestScopeWithNoProxy() {
RequestContextHolder.setRequestAttributes(oldRequestAttributes);
ApplicationContext context = createContext(NO);
ScopedTestBean bean = (ScopedTestBean) context.getBean("request");
......@@ -159,7 +159,7 @@ public class ClassPathBeanDefinitionScannerScopeIntegrationTests {
}
@Test
public void requestScopeWithProxiedInterfaces() {
void requestScopeWithProxiedInterfaces() {
RequestContextHolder.setRequestAttributes(oldRequestAttributes);
ApplicationContext context = createContext(INTERFACES);
IScopedTestBean bean = (IScopedTestBean) context.getBean("request");
......@@ -181,7 +181,7 @@ public class ClassPathBeanDefinitionScannerScopeIntegrationTests {
}
@Test
public void requestScopeWithProxiedTargetClass() {
void requestScopeWithProxiedTargetClass() {
RequestContextHolder.setRequestAttributes(oldRequestAttributes);
ApplicationContext context = createContext(TARGET_CLASS);
IScopedTestBean bean = (IScopedTestBean) context.getBean("request");
......@@ -203,7 +203,7 @@ public class ClassPathBeanDefinitionScannerScopeIntegrationTests {
}
@Test
public void sessionScopeWithNoProxy() {
void sessionScopeWithNoProxy() {
RequestContextHolder.setRequestAttributes(oldRequestAttributesWithSession);
ApplicationContext context = createContext(NO);
ScopedTestBean bean = (ScopedTestBean) context.getBean("session");
......@@ -224,7 +224,7 @@ public class ClassPathBeanDefinitionScannerScopeIntegrationTests {
}
@Test
public void sessionScopeWithProxiedInterfaces() {
void sessionScopeWithProxiedInterfaces() {
RequestContextHolder.setRequestAttributes(oldRequestAttributesWithSession);
ApplicationContext context = createContext(INTERFACES);
IScopedTestBean bean = (IScopedTestBean) context.getBean("session");
......@@ -252,7 +252,7 @@ public class ClassPathBeanDefinitionScannerScopeIntegrationTests {
}
@Test
public void sessionScopeWithProxiedTargetClass() {
void sessionScopeWithProxiedTargetClass() {
RequestContextHolder.setRequestAttributes(oldRequestAttributesWithSession);
ApplicationContext context = createContext(TARGET_CLASS);
IScopedTestBean bean = (IScopedTestBean) context.getBean("session");
......@@ -298,7 +298,7 @@ public class ClassPathBeanDefinitionScannerScopeIntegrationTests {
}
static interface IScopedTestBean {
interface IScopedTestBean {
String getName();
......@@ -323,7 +323,7 @@ public class ClassPathBeanDefinitionScannerScopeIntegrationTests {
}
static interface AnotherScopeTestInterface {
interface AnotherScopeTestInterface {
}
......
......@@ -100,14 +100,14 @@ public class EnvironmentSystemIntegrationTests {
private final ConfigurableEnvironment prodWebEnv = new StandardServletEnvironment();
@BeforeEach
public void setUp() {
void setUp() {
prodEnv.setActiveProfiles(PROD_ENV_NAME);
devEnv.setActiveProfiles(DEV_ENV_NAME);
prodWebEnv.setActiveProfiles(PROD_ENV_NAME);
}
@Test
public void genericApplicationContext_standardEnv() {
void genericApplicationContext_standardEnv() {
ConfigurableApplicationContext ctx = new GenericApplicationContext(newBeanFactoryWithEnvironmentAwareBean());
ctx.refresh();
......@@ -117,7 +117,7 @@ public class EnvironmentSystemIntegrationTests {
}
@Test
public void genericApplicationContext_customEnv() {
void genericApplicationContext_customEnv() {
GenericApplicationContext ctx = new GenericApplicationContext(newBeanFactoryWithEnvironmentAwareBean());
ctx.setEnvironment(prodEnv);
ctx.refresh();
......@@ -128,7 +128,7 @@ public class EnvironmentSystemIntegrationTests {
}
@Test
public void xmlBeanDefinitionReader_inheritsEnvironmentFromEnvironmentCapableBDR() {
void xmlBeanDefinitionReader_inheritsEnvironmentFromEnvironmentCapableBDR() {
GenericApplicationContext ctx = new GenericApplicationContext();
ctx.setEnvironment(prodEnv);
new XmlBeanDefinitionReader(ctx).loadBeanDefinitions(XML_PATH);
......@@ -138,7 +138,7 @@ public class EnvironmentSystemIntegrationTests {
}
@Test
public void annotatedBeanDefinitionReader_inheritsEnvironmentFromEnvironmentCapableBDR() {
void annotatedBeanDefinitionReader_inheritsEnvironmentFromEnvironmentCapableBDR() {
GenericApplicationContext ctx = new GenericApplicationContext();
ctx.setEnvironment(prodEnv);
new AnnotatedBeanDefinitionReader(ctx).register(Config.class);
......@@ -148,7 +148,7 @@ public class EnvironmentSystemIntegrationTests {
}
@Test
public void classPathBeanDefinitionScanner_inheritsEnvironmentFromEnvironmentCapableBDR_scanProfileAnnotatedConfigClasses() {
void classPathBeanDefinitionScanner_inheritsEnvironmentFromEnvironmentCapableBDR_scanProfileAnnotatedConfigClasses() {
// it's actually ConfigurationClassPostProcessor's Environment that gets the job done here.
GenericApplicationContext ctx = new GenericApplicationContext();
ctx.setEnvironment(prodEnv);
......@@ -160,7 +160,7 @@ public class EnvironmentSystemIntegrationTests {
}
@Test
public void classPathBeanDefinitionScanner_inheritsEnvironmentFromEnvironmentCapableBDR_scanProfileAnnotatedComponents() {
void classPathBeanDefinitionScanner_inheritsEnvironmentFromEnvironmentCapableBDR_scanProfileAnnotatedComponents() {
GenericApplicationContext ctx = new GenericApplicationContext();
ctx.setEnvironment(prodEnv);
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(ctx);
......@@ -172,7 +172,7 @@ public class EnvironmentSystemIntegrationTests {
}
@Test
public void genericXmlApplicationContext() {
void genericXmlApplicationContext() {
GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
assertHasStandardEnvironment(ctx);
ctx.setEnvironment(prodEnv);
......@@ -187,7 +187,7 @@ public class EnvironmentSystemIntegrationTests {
}
@Test
public void classPathXmlApplicationContext() {
void classPathXmlApplicationContext() {
ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext(XML_PATH);
ctx.setEnvironment(prodEnv);
ctx.refresh();
......@@ -200,7 +200,7 @@ public class EnvironmentSystemIntegrationTests {
}
@Test
public void fileSystemXmlApplicationContext() throws IOException {
void fileSystemXmlApplicationContext() throws IOException {
ClassPathResource xml = new ClassPathResource(XML_PATH);
File tmpFile = File.createTempFile("test", "xml");
FileCopyUtils.copy(xml.getFile(), tmpFile);
......@@ -218,7 +218,7 @@ public class EnvironmentSystemIntegrationTests {
}
@Test
public void annotationConfigApplicationContext_withPojos() {
void annotationConfigApplicationContext_withPojos() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
assertHasStandardEnvironment(ctx);
......@@ -231,7 +231,7 @@ public class EnvironmentSystemIntegrationTests {
}
@Test
public void annotationConfigApplicationContext_withProdEnvAndProdConfigClass() {
void annotationConfigApplicationContext_withProdEnvAndProdConfigClass() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
assertHasStandardEnvironment(ctx);
......@@ -244,7 +244,7 @@ public class EnvironmentSystemIntegrationTests {
}
@Test
public void annotationConfigApplicationContext_withProdEnvAndDevConfigClass() {
void annotationConfigApplicationContext_withProdEnvAndDevConfigClass() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
assertHasStandardEnvironment(ctx);
......@@ -258,7 +258,7 @@ public class EnvironmentSystemIntegrationTests {
}
@Test
public void annotationConfigApplicationContext_withDevEnvAndDevConfigClass() {
void annotationConfigApplicationContext_withDevEnvAndDevConfigClass() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
assertHasStandardEnvironment(ctx);
......@@ -272,7 +272,7 @@ public class EnvironmentSystemIntegrationTests {
}
@Test
public void annotationConfigApplicationContext_withImportedConfigClasses() {
void annotationConfigApplicationContext_withImportedConfigClasses() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
assertHasStandardEnvironment(ctx);
......@@ -288,7 +288,7 @@ public class EnvironmentSystemIntegrationTests {
}
@Test
public void mostSpecificDerivedClassDrivesEnvironment_withDerivedDevEnvAndDerivedDevConfigClass() {
void mostSpecificDerivedClassDrivesEnvironment_withDerivedDevEnvAndDerivedDevConfigClass() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
StandardEnvironment derivedDevEnv = new StandardEnvironment();
derivedDevEnv.setActiveProfiles(DERIVED_DEV_ENV_NAME);
......@@ -302,7 +302,7 @@ public class EnvironmentSystemIntegrationTests {
}
@Test
public void mostSpecificDerivedClassDrivesEnvironment_withDevEnvAndDerivedDevConfigClass() {
void mostSpecificDerivedClassDrivesEnvironment_withDevEnvAndDerivedDevConfigClass() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.setEnvironment(devEnv);
ctx.register(DerivedDevConfig.class);
......@@ -314,22 +314,22 @@ public class EnvironmentSystemIntegrationTests {
}
@Test
public void annotationConfigApplicationContext_withProfileExpressionMatchOr() {
void annotationConfigApplicationContext_withProfileExpressionMatchOr() {
testProfileExpression(true, "p3");
}
@Test
public void annotationConfigApplicationContext_withProfileExpressionMatchAnd() {
void annotationConfigApplicationContext_withProfileExpressionMatchAnd() {
testProfileExpression(true, "p1", "p2");
}
@Test
public void annotationConfigApplicationContext_withProfileExpressionNoMatchAnd() {
void annotationConfigApplicationContext_withProfileExpressionNoMatchAnd() {
testProfileExpression(false, "p1");
}
@Test
public void annotationConfigApplicationContext_withProfileExpressionNoMatchNone() {
void annotationConfigApplicationContext_withProfileExpressionNoMatchNone() {
testProfileExpression(false, "p4");
}
......@@ -344,7 +344,7 @@ public class EnvironmentSystemIntegrationTests {
}
@Test
public void webApplicationContext() {
void webApplicationContext() {
GenericWebApplicationContext ctx = new GenericWebApplicationContext(newBeanFactoryWithEnvironmentAwareBean());
assertHasStandardServletEnvironment(ctx);
ctx.setEnvironment(prodWebEnv);
......@@ -356,7 +356,7 @@ public class EnvironmentSystemIntegrationTests {
}
@Test
public void xmlWebApplicationContext() {
void xmlWebApplicationContext() {
AbstractRefreshableWebApplicationContext ctx = new XmlWebApplicationContext();
ctx.setConfigLocation("classpath:" + XML_PATH);
ctx.setEnvironment(prodWebEnv);
......@@ -370,7 +370,7 @@ public class EnvironmentSystemIntegrationTests {
}
@Test
public void staticApplicationContext() {
void staticApplicationContext() {
StaticApplicationContext ctx = new StaticApplicationContext();
assertHasStandardEnvironment(ctx);
......@@ -386,7 +386,7 @@ public class EnvironmentSystemIntegrationTests {
}
@Test
public void staticWebApplicationContext() {
void staticWebApplicationContext() {
StaticWebApplicationContext ctx = new StaticWebApplicationContext();
assertHasStandardServletEnvironment(ctx);
......@@ -402,7 +402,7 @@ public class EnvironmentSystemIntegrationTests {
}
@Test
public void annotationConfigWebApplicationContext() {
void annotationConfigWebApplicationContext() {
AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
ctx.setEnvironment(prodWebEnv);
ctx.setConfigLocation(EnvironmentAwareBean.class.getName());
......@@ -414,7 +414,7 @@ public class EnvironmentSystemIntegrationTests {
}
@Test
public void registerServletParamPropertySources_AbstractRefreshableWebApplicationContext() {
void registerServletParamPropertySources_AbstractRefreshableWebApplicationContext() {
MockServletContext servletContext = new MockServletContext();
servletContext.addInitParameter("pCommon", "pCommonContextValue");
servletContext.addInitParameter("pContext1", "pContext1Value");
......@@ -459,7 +459,7 @@ public class EnvironmentSystemIntegrationTests {
}
@Test
public void registerServletParamPropertySources_GenericWebApplicationContext() {
void registerServletParamPropertySources_GenericWebApplicationContext() {
MockServletContext servletContext = new MockServletContext();
servletContext.addInitParameter("pCommon", "pCommonContextValue");
servletContext.addInitParameter("pContext1", "pContext1Value");
......@@ -493,7 +493,7 @@ public class EnvironmentSystemIntegrationTests {
}
@Test
public void registerServletParamPropertySources_StaticWebApplicationContext() {
void registerServletParamPropertySources_StaticWebApplicationContext() {
MockServletContext servletContext = new MockServletContext();
servletContext.addInitParameter("pCommon", "pCommonContextValue");
servletContext.addInitParameter("pContext1", "pContext1Value");
......@@ -536,7 +536,7 @@ public class EnvironmentSystemIntegrationTests {
}
@Test
public void resourceAdapterApplicationContext() {
void resourceAdapterApplicationContext() {
ResourceAdapterApplicationContext ctx = new ResourceAdapterApplicationContext(new SimpleBootstrapContext(new SimpleTaskWorkManager()));
assertHasStandardEnvironment(ctx);
......@@ -552,7 +552,7 @@ public class EnvironmentSystemIntegrationTests {
}
@Test
public void abstractApplicationContextValidatesRequiredPropertiesOnRefresh() {
void abstractApplicationContextValidatesRequiredPropertiesOnRefresh() {
{
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.refresh();
......
......@@ -22,11 +22,11 @@ import org.springframework.context.support.GenericApplicationContext;
import static org.springframework.beans.factory.support.BeanDefinitionBuilder.rootBeanDefinition;
public class PropertyPlaceholderConfigurerEnvironmentIntegrationTests {
class PropertyPlaceholderConfigurerEnvironmentIntegrationTests {
@Test
@SuppressWarnings("deprecation")
public void test() {
void test() {
GenericApplicationContext ctx = new GenericApplicationContext();
ctx.registerBeanDefinition("ppc",
rootBeanDefinition(org.springframework.beans.factory.config.PropertyPlaceholderConfigurer.class)
......
......@@ -18,29 +18,26 @@ package org.springframework.expression.spel.support;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.core.MethodParameter;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.expression.MethodExecutor;
public class Spr7538Tests {
class Spr7538Tests {
@Disabled @Test
public void repro() throws Exception {
@Test
void repro() throws Exception {
AlwaysTrueReleaseStrategy target = new AlwaysTrueReleaseStrategy();
BeanFactoryTypeConverter converter = new BeanFactoryTypeConverter();
StandardEvaluationContext context = new StandardEvaluationContext();
context.setTypeConverter(converter);
List<Foo> arguments = new ArrayList<>();
// !!!! With the below line commented you'll get NPE. Uncomment and everything is OK!
//arguments.add(new Foo());
List<Foo> arguments = Collections.emptyList();
List<TypeDescriptor> paramDescriptors = new ArrayList<>();
Method method = AlwaysTrueReleaseStrategy.class.getMethod("checkCompleteness", List.class);
......@@ -56,11 +53,11 @@ public class Spr7538Tests {
System.out.println("Result: " + result);
}
public static class AlwaysTrueReleaseStrategy {
static class AlwaysTrueReleaseStrategy {
public boolean checkCompleteness(List<Foo> messages) {
return true;
}
}
public static class Foo{}
static class Foo{}
}
......@@ -54,66 +54,57 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
* @since 3.1
*/
@SuppressWarnings("resource")
public class EnableTransactionManagementIntegrationTests {
class EnableTransactionManagementIntegrationTests {
@Test
public void repositoryIsNotTxProxy() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(Config.class);
ctx.refresh();
void repositoryIsNotTxProxy() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(Config.class);
assertThat(isTxProxy(ctx.getBean(FooRepository.class))).isFalse();
}
@Test
public void repositoryIsTxProxy_withDefaultTxManagerName() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(Config.class, DefaultTxManagerNameConfig.class);
ctx.refresh();
void repositoryIsTxProxy_withDefaultTxManagerName() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(Config.class, DefaultTxManagerNameConfig.class);
assertTxProxying(ctx);
}
@Test
public void repositoryIsTxProxy_withCustomTxManagerName() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(Config.class, CustomTxManagerNameConfig.class);
ctx.refresh();
void repositoryIsTxProxy_withCustomTxManagerName() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(Config.class, CustomTxManagerNameConfig.class);
assertTxProxying(ctx);
}
@Test
public void repositoryIsTxProxy_withNonConventionalTxManagerName_fallsBackToByTypeLookup() {
void repositoryIsTxProxy_withNonConventionalTxManagerName_fallsBackToByTypeLookup() {
assertTxProxying(new AnnotationConfigApplicationContext(Config.class, NonConventionalTxManagerNameConfig.class));
}
@Test
public void repositoryIsClassBasedTxProxy() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(Config.class, ProxyTargetClassTxConfig.class);
ctx.refresh();
void repositoryIsClassBasedTxProxy() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(Config.class, ProxyTargetClassTxConfig.class);
assertTxProxying(ctx);
assertThat(AopUtils.isCglibProxy(ctx.getBean(FooRepository.class))).isTrue();
}
@Test
public void repositoryUsesAspectJAdviceMode() {
void repositoryUsesAspectJAdviceMode() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(Config.class, AspectJTxConfig.class);
// this test is a bit fragile, but gets the job done, proving that an
// attempt was made to look up the AJ aspect. It's due to classpath issues
// in .integration-tests that it's not found.
assertThatExceptionOfType(Exception.class).isThrownBy(
ctx::refresh)
assertThatExceptionOfType(Exception.class)
.isThrownBy(ctx::refresh)
.withMessageContaining("AspectJJtaTransactionManagementConfiguration");
}
@Test
public void implicitTxManager() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(ImplicitTxManagerConfig.class);
ctx.refresh();
void implicitTxManager() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ImplicitTxManagerConfig.class);
FooRepository fooRepository = ctx.getBean(FooRepository.class);
fooRepository.findAll();
......@@ -125,10 +116,8 @@ public class EnableTransactionManagementIntegrationTests {
}
@Test
public void explicitTxManager() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(ExplicitTxManagerConfig.class);
ctx.refresh();
void explicitTxManager() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ExplicitTxManagerConfig.class);
FooRepository fooRepository = ctx.getBean(FooRepository.class);
fooRepository.findAll();
......@@ -145,10 +134,8 @@ public class EnableTransactionManagementIntegrationTests {
}
@Test
public void apcEscalation() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(EnableTxAndCachingConfig.class);
ctx.refresh();
void apcEscalation() {
new AnnotationConfigApplicationContext(EnableTxAndCachingConfig.class);
}
......
......@@ -35,10 +35,10 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Chris Beams
*/
@SuppressWarnings("resource")
public class ProxyAnnotationDiscoveryTests {
class ProxyAnnotationDiscoveryTests {
@Test
public void annotatedServiceWithoutInterface_PTC_true() {
void annotatedServiceWithoutInterface_PTC_true() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(PTCTrue.class, AnnotatedServiceWithoutInterface.class);
ctx.refresh();
......@@ -48,7 +48,7 @@ public class ProxyAnnotationDiscoveryTests {
}
@Test
public void annotatedServiceWithoutInterface_PTC_false() {
void annotatedServiceWithoutInterface_PTC_false() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(PTCFalse.class, AnnotatedServiceWithoutInterface.class);
ctx.refresh();
......@@ -58,7 +58,7 @@ public class ProxyAnnotationDiscoveryTests {
}
@Test
public void nonAnnotatedService_PTC_true() {
void nonAnnotatedService_PTC_true() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(PTCTrue.class, AnnotatedServiceImpl.class);
ctx.refresh();
......@@ -68,7 +68,7 @@ public class ProxyAnnotationDiscoveryTests {
}
@Test
public void nonAnnotatedService_PTC_false() {
void nonAnnotatedService_PTC_false() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(PTCFalse.class, AnnotatedServiceImpl.class);
ctx.refresh();
......@@ -78,7 +78,7 @@ public class ProxyAnnotationDiscoveryTests {
}
@Test
public void annotatedService_PTC_true() {
void annotatedService_PTC_true() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(PTCTrue.class, NonAnnotatedServiceImpl.class);
ctx.refresh();
......@@ -88,7 +88,7 @@ public class ProxyAnnotationDiscoveryTests {
}
@Test
public void annotatedService_PTC_false() {
void annotatedService_PTC_false() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(PTCFalse.class, NonAnnotatedServiceImpl.class);
ctx.refresh();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册