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
This commit is contained in:
@@ -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 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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user