提交 dfe05305 编写于 作者: C Chris Beams

Upgrade to JUnit 4.11 snapshot in support of JDK7

Class#getDeclaredMembers returns arbitrary results under JDK7. This
results in non-deterministic execution of JUnit test methods, often
revealing unintended dependencies between methods that rely on a
specific order to succeed.

JUnit 4.11 contains support for predictable test ordering [1], but at
the time of this commit, JUnit 4.11 has not yet been released.
Therefore we are testing against a snapshot version [2], which has been
uploaded to repo.springsource.org [3] for easy access. Note that this
artifact may be removed when JUnit 4.11 goes GA.

 - Care has been taken to ensure that spring-test's compile-time
   dependency on JUnit remains at 4.10. This means that the spring-test
   pom.xml will continue to have an optional <dependency> on JUnit
   4.10, instead of the 4.11 snapshot.

 - For reasons not fully understood, the upgrade to the 4.11 snapshot
   of junit-dep caused NoSuchMethodErrors around certain Hamcrest
   types, particularly CoreMatchers and Matchers. import statements
   have been updated accordingly throughout affected test cases.

 - Runtime errors also occurred around uses of JUnit @Rule and
   ExpectedException. These have been reverted to use simpler
   mechanisms like @test(expected) in the meantime.

 - Some test methods with order-based dependencies on one another have
   been renamed in order to fall in line with JUnit 4.11's new method
   ordering (as opposed to actually fixing the inter-test
   dependencies). In other areas, the fix was as simple as adding a
   tearDown method and cleaning up state.

 - For no apparent reason, the timeout in AspectJAutoProxyCreatorTests'
   testAspectsAndAdvisorNotAppliedToPrototypeIsFastEnough method begins
   to be exceeded. Prior to this commit the timeout value was 3000 ms;
   on the CI server under Linux/JDK6 and JDK7, the test begins taking
   anywhere from 3500-5500 ms with this commit. It is presumed that
   this is an incidental artifact of the upgrade to JUnit 4.11. In any
   case, there are no changes to src/main in this commit, so this
   should not actually represent a performance risk for Spring
   Framework users. The timeout has been increased to 6000 ms to
   accommodate this situation.

[1]: https://github.com/KentBeck/junit/pull/293
[2]: https://github.com/downloads/KentBeck/junit/junit-dep-4.11-SNAPSHOT-20120805-1225.jar
[3]: https://repo.springsource.org/simple/ext-release-local/junit/junit-dep/4.11.20120805.1225

Issue: SPR-9783
上级 a9a90cab
......@@ -19,7 +19,8 @@ configure(allprojects) {
ext.aspectjVersion = '1.6.12'
ext.hsqldbVersion='1.8.0.10'
ext.junitVersion = '4.10'
ext.junitVersion = '4.11.20120805.1225' // temporary use of snapshot; spring-test
// still builds against on 4.10
[compileJava, compileTestJava]*.options*.compilerArgs = ['-Xlint:none']
......@@ -33,9 +34,6 @@ configure(allprojects) {
}
dependencies {
testCompile ("junit:junit-dep:${junitVersion}") {
exclude group: 'org.hamcrest', module: 'hamcrest-core'
}
testCompile "org.hamcrest:hamcrest-all:1.1"
testCompile "org.easymock:easymock:2.5.1"
}
......@@ -48,6 +46,14 @@ configure(allprojects) {
}
}
configure(subprojects - project(":spring-test")) {
dependencies {
testCompile ("junit:junit-dep:${junitVersion}") {
exclude group: 'org.hamcrest', module: 'hamcrest-core'
}
}
}
configure(subprojects) { subproject ->
apply from: "${rootProject.projectDir}/publish-maven.gradle"
......@@ -521,7 +527,7 @@ project('spring-test') {
compile(project(":spring-web"), optional)
compile(project(":spring-webmvc"), optional)
compile(project(":spring-webmvc-portlet"), optional)
compile("junit:junit-dep:${junitVersion}") { dep ->
compile("junit:junit-dep:4.10") { dep ->
optional dep
// We already have hamcrest-all as a global testCompile dependency.
exclude group: 'org.hamcrest', module: 'hamcrest-core'
......
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2012 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.
......@@ -40,9 +40,7 @@ import org.aspectj.lang.annotation.DeclarePrecedence;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.aop.Advisor;
import org.springframework.aop.aspectj.annotation.ReflectiveAspectJAdvisorFactory.SyntheticInstantiationAdvisor;
......@@ -73,9 +71,6 @@ import test.beans.TestBean;
*/
public abstract class AbstractAspectJAdvisorFactoryTests {
@Rule
public ExpectedException thrown = ExpectedException.none();
/**
* To be overridden by concrete test subclasses.
* @return the fixture
......@@ -586,11 +581,9 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
itb.getAge();
}
@Test
@Test(expected=IllegalArgumentException.class)
public void testDeclarePrecedenceNotSupported() {
TestBean target = new TestBean();
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("DeclarePrecendence not presently supported in Spring AOP");
MetadataAwareAspectInstanceFactory aspectInstanceFactory = new SingletonMetadataAwareAspectInstanceFactory(
new DeclarePrecedenceShouldSucceed(), "someBean");
createProxy(target, getFixture().getAdvisors(aspectInstanceFactory),
......
......@@ -151,7 +151,7 @@ public final class AspectJAutoProxyCreatorTests {
// What's a reasonable expectation for _any_ server or developer machine load?
// 3 seconds?
assertStopWatchTimeLimit(sw, 3000);
assertStopWatchTimeLimit(sw, 6000);
}
@Test
......
......@@ -16,14 +16,9 @@
package org.springframework.context.annotation;
import static java.lang.String.format;
import java.util.Map;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import org.junit.Test;
import static org.junit.matchers.JUnitMatchers.*;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -31,6 +26,10 @@ import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.annotation6.ComponentForScanning;
import org.springframework.context.annotation6.ConfigForScanning;
import org.springframework.context.annotation6.Jsr330NamedForScanning;
import static java.lang.String.*;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.springframework.util.StringUtils.*;
/**
......@@ -229,13 +228,13 @@ public class AnnotationConfigApplicationContextTests {
}
}
static class UntypedFactoryBean implements FactoryBean {
static class UntypedFactoryBean implements FactoryBean<Object> {
public Object getObject() {
return null;
}
public Class getObjectType() {
public Class<?> getObjectType() {
return null;
}
......
......@@ -16,14 +16,13 @@
package org.springframework.context.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import java.util.Calendar;
import java.util.Date;
import java.util.Map;
import org.junit.After;
import org.junit.Test;
import org.springframework.beans.factory.config.PlaceholderConfigurerSupport;
import org.springframework.beans.factory.config.PropertyOverrideConfigurer;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
......@@ -33,6 +32,8 @@ import org.springframework.context.support.GenericXmlApplicationContext;
import org.springframework.core.io.ClassPathResource;
import org.springframework.mock.env.MockEnvironment;
import static org.junit.Assert.*;
/**
* @author Arjen Poutsma
* @author Dave Syer
......@@ -41,6 +42,11 @@ import org.springframework.mock.env.MockEnvironment;
*/
public class ContextNamespaceHandlerTests {
@After
public void tearDown() {
System.getProperties().remove("foo");
}
@Test
public void propertyPlaceholder() throws Exception {
ApplicationContext applicationContext = new ClassPathXmlApplicationContext(
......
......@@ -16,8 +16,6 @@
package org.springframework.core.convert.converter;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
......@@ -25,15 +23,15 @@ import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.converter.Converter;
import org.springframework.core.convert.converter.ConvertingComparator;
import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.util.comparator.ComparableComparator;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
/**
* Tests for {@link ConvertingComparator}.
*
......@@ -41,40 +39,29 @@ import org.springframework.util.comparator.ComparableComparator;
*/
public class ConvertingComparatorTests {
@Rule
public ExpectedException thown = ExpectedException.none();
private final StringToInteger converter = new StringToInteger();
private final ConversionService conversionService = new DefaultConversionService();
private final TestComparator comparator = new TestComparator();
@Test
@Test(expected=IllegalArgumentException.class)
public void shouldThrowOnNullComparator() throws Exception {
thown.expect(IllegalArgumentException.class);
thown.expectMessage("Comparator must not be null");
new ConvertingComparator<String, Integer>(null, this.converter);
}
@Test
@Test(expected=IllegalArgumentException.class)
public void shouldThrowOnNullConverter() throws Exception {
thown.expect(IllegalArgumentException.class);
thown.expectMessage("Converter must not be null");
new ConvertingComparator<String, Integer>(this.comparator, null);
}
@Test
@Test(expected=IllegalArgumentException.class)
public void shouldThrowOnNullConversionService() throws Exception {
thown.expect(IllegalArgumentException.class);
thown.expectMessage("ConversionService must not be null");
new ConvertingComparator<String, Integer>(this.comparator, null, Integer.class);
}
@Test
@Test(expected=IllegalArgumentException.class)
public void shouldThrowOnNullType() throws Exception {
thown.expect(IllegalArgumentException.class);
thown.expectMessage("TargetType must not be null");
new ConvertingComparator<String, Integer>(this.comparator,
this.conversionService, null);
}
......@@ -145,8 +132,8 @@ public class ConvertingComparatorTests {
private boolean called;
public int compare(Integer o1, Integer o2) {
assertThat(o1, is(Integer.class));
assertThat(o2, is(Integer.class));
assertThat(o1, instanceOf(Integer.class));
assertThat(o2, instanceOf(Integer.class));
this.called = true;
return super.compare(o1, o2);
};
......
......@@ -20,14 +20,15 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import org.hamcrest.Matchers;
import org.hamcrest.CoreMatchers;
import org.junit.Before;
import org.junit.Test;
import org.springframework.core.convert.ConversionException;
import org.springframework.mock.env.MockPropertySource;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
/**
......@@ -371,7 +372,7 @@ public class PropertySourcesPropertyResolverTests {
try {
pr.getProperty("p5");
} catch (IllegalArgumentException ex) {
assertThat(ex.getMessage(), Matchers.containsString(
assertThat(ex.getMessage(), containsString(
"Could not resolve placeholder 'bogus' in string value [${p1}:${p2}:${bogus}]"));
}
assertThat(pr.getProperty("p6"), equalTo("v1:v2:def"));
......
......@@ -26,16 +26,12 @@ import java.util.Collections;
import java.util.Map;
import org.junit.Test;
import org.springframework.mock.env.MockPropertySource;
import static java.lang.String.*;
import static org.hamcrest.CoreMatchers.*;
import static java.lang.String.*;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.junit.matchers.JUnitMatchers.*;
import static org.springframework.core.env.AbstractEnvironment.*;
/**
......
......@@ -16,20 +16,21 @@
package org.springframework.core.io;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.internal.matchers.StringContains.containsString;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.junit.Test;
import static org.hamcrest.Matchers.*;
/**
* Unit tests that serve as regression tests for the bugs described in SPR-6888
* and SPR-9413.
......
......@@ -16,7 +16,7 @@
package org.springframework.util.comparator;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.*;
import java.util.Comparator;
......
......@@ -16,7 +16,7 @@
package org.springframework.util.comparator;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.*;
import java.util.Comparator;
......
......@@ -16,14 +16,12 @@
package org.springframework.util.comparator;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import java.util.Comparator;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
/**
* Tests for {@link InvertibleComparator}.
......@@ -35,22 +33,15 @@ import org.junit.rules.ExpectedException;
public class InvertibleComparatorTests {
@Rule
public ExpectedException thrown = ExpectedException.none();
private Comparator<Integer> comparator = new ComparableComparator<Integer>();
@Test
@Test(expected=IllegalArgumentException.class)
public void shouldNeedComparator() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Comparator must not be null");
new InvertibleComparator<Object>(null);
}
@Test
@Test(expected=IllegalArgumentException.class)
public void shouldNeedComparatorWithAscending() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Comparator must not be null");
new InvertibleComparator<Object>(null, true);
}
......
......@@ -16,20 +16,18 @@
package org.springframework.test.context;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.*;
/**
* JUnit 4 based unit test which verifies correct {@link ContextCache
* application context caching} in conjunction with the
......@@ -108,7 +106,7 @@ public class SpringRunnerContextCacheTests {
}
@Test
public void verifyContextWasDirtied() {
public void verifyContextDirty() {
assertContextCacheStatistics("verifyContextWasDirtied()", 1, 0, 2);
assertNotNull("The application context should have been autowired.", this.applicationContext);
assertNotSame("The application context should have been 'dirtied'.",
......@@ -117,7 +115,7 @@ public class SpringRunnerContextCacheTests {
}
@Test
public void verifyContextWasNotDirtied() {
public void verifyContextNotDirty() {
assertContextCacheStatistics("verifyContextWasNotDirtied()", 1, 1, 2);
assertNotNull("The application context should have been autowired.", this.applicationContext);
assertSame("The application context should NOT have been 'dirtied'.",
......
/*
* Copyright 2002-2007 the original author or authors.
* Copyright 2002-2012 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.
......@@ -281,7 +281,7 @@ public class JaxRpcSupportTests extends TestCase {
}
}
public void testJaxRpcPortProxyFactoryBeanWithDynamicCallsAndRemoteException() throws Exception {
public void testJaxRpcPortProxyFactoryBeanWithDynamicCallsAndRemoteException_() throws Exception {
ExceptionCallMockServiceFactory serviceFactory = new ExceptionCallMockServiceFactory();
JaxRpcPortProxyFactoryBean factory = new JaxRpcPortProxyFactoryBean();
......
......@@ -16,29 +16,12 @@
package org.springframework.core.env;
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.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import static org.springframework.beans.factory.support.BeanDefinitionBuilder.rootBeanDefinition;
import static org.springframework.context.ConfigurableApplicationContext.ENVIRONMENT_BEAN_NAME;
import static org.springframework.core.env.EnvironmentIntegrationTests.Constants.DERIVED_DEV_BEAN_NAME;
import static org.springframework.core.env.EnvironmentIntegrationTests.Constants.DERIVED_DEV_ENV_NAME;
import static org.springframework.core.env.EnvironmentIntegrationTests.Constants.DEV_BEAN_NAME;
import static org.springframework.core.env.EnvironmentIntegrationTests.Constants.DEV_ENV_NAME;
import static org.springframework.core.env.EnvironmentIntegrationTests.Constants.ENVIRONMENT_AWARE_BEAN_NAME;
import static org.springframework.core.env.EnvironmentIntegrationTests.Constants.PROD_BEAN_NAME;
import static org.springframework.core.env.EnvironmentIntegrationTests.Constants.PROD_ENV_NAME;
import static org.springframework.core.env.EnvironmentIntegrationTests.Constants.TRANSITIVE_BEAN_NAME;
import static org.springframework.core.env.EnvironmentIntegrationTests.Constants.XML_PATH;
import java.io.File;
import java.io.IOException;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
......@@ -69,8 +52,8 @@ import org.springframework.util.FileCopyUtils;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.AbstractRefreshableWebApplicationContext;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.context.support.StandardServletEnvironment;
import org.springframework.web.context.support.GenericWebApplicationContext;
import org.springframework.web.context.support.StandardServletEnvironment;
import org.springframework.web.context.support.StaticWebApplicationContext;
import org.springframework.web.context.support.XmlWebApplicationContext;
import org.springframework.web.portlet.context.AbstractRefreshablePortletApplicationContext;
......@@ -78,6 +61,12 @@ import org.springframework.web.portlet.context.StandardPortletEnvironment;
import org.springframework.web.portlet.context.StaticPortletApplicationContext;
import org.springframework.web.portlet.context.XmlPortletApplicationContext;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.springframework.beans.factory.support.BeanDefinitionBuilder.*;
import static org.springframework.context.ConfigurableApplicationContext.*;
import static org.springframework.core.env.EnvironmentIntegrationTests.Constants.*;
/**
* Integration tests for container support of {@link Environment}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册