Skip to content

Commit 08f500d

Browse files
committed
get the tests working in openjdk7
1 parent 72520cb commit 08f500d

3 files changed

Lines changed: 43 additions & 28 deletions

File tree

‎.travis.yml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ language: java
22

33
jdk:
44
- openjdk6
5+
- openjdk7
6+
- oraclejdk7
57

68
script:
79
- ant unit-test

‎build.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@
284284
<attribute name="Built-Date" value="${build.timestamp}"/>
285285
</manifest>
286286
<mkdir dir="build/temp/@{modulename}-${version}.jar.contents"/>
287-
<javac srcdir="@{srcdir}" destdir="build/temp/@{modulename}-${version}.jar.contents" debug="${debug}" target="1.5" includeantruntime="false">
287+
<javac srcdir="@{srcdir}" destdir="build/temp/@{modulename}-${version}.jar.contents" debug="${debug}" source="1.5" target="1.5" includeantruntime="false">
288288
<classpath>
289289
<fileset dir="lib/integration">
290290
<include name="*.jar"/>

‎hamcrest-unit-test/src/main/java/org/hamcrest/generator/ReflectiveFactoryReaderTest.java‎

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
import org.hamcrest.Matcher;
77

88
import java.io.IOException;
9+
import java.util.ArrayList;
910
import java.util.Collection;
11+
import java.util.Collections;
1012
import java.util.Comparator;
1113
import java.util.Iterator;
1214
import java.util.List;
@@ -31,20 +33,18 @@ public static Matcher<String> secondMethod() {
3133
}
3234

3335
public void testIteratesOverFactoryMethods() {
34-
Iterable<FactoryMethod> reader = new ReflectiveFactoryReader(SimpleSetOfMatchers.class);
35-
Iterator<FactoryMethod> methods = reader.iterator();
36-
37-
assertTrue("Expected first method", methods.hasNext());
38-
FactoryMethod firstMethod = methods.next();
39-
assertEquals("firstMethod", firstMethod.getName());
40-
assertEquals(SimpleSetOfMatchers.class.getName().replace('$', '.'), firstMethod.getMatcherClass());
41-
42-
assertTrue("Expected second method", methods.hasNext());
43-
FactoryMethod secondMethod = methods.next();
44-
assertEquals("secondMethod", secondMethod.getName());
45-
assertEquals(SimpleSetOfMatchers.class.getName().replace('$', '.'), secondMethod.getMatcherClass());
46-
47-
assertFalse("Expected no more methods", methods.hasNext());
36+
final ReflectiveFactoryReader reader = new ReflectiveFactoryReader(SimpleSetOfMatchers.class);
37+
final List<FactoryMethod> methods = methodsReadBy(reader);
38+
39+
assertEquals(2, methods.size());
40+
41+
final String expectedClass = SimpleSetOfMatchers.class.getName().replace('$', '.');
42+
43+
assertEquals("firstMethod", methods.get(0).getName());
44+
assertEquals(expectedClass, methods.get(0).getMatcherClass());
45+
46+
assertEquals("secondMethod", methods.get(1).getName());
47+
assertEquals(expectedClass, methods.get(1).getMatcherClass());
4848
}
4949

5050
public static class MatchersWithDodgySignatures {
@@ -80,16 +80,12 @@ public static void wrongReturnType() {
8080
}
8181

8282
public void testOnlyReadsPublicStaticAnnotatedMethodsThatReturnNonVoid() {
83-
Iterable<FactoryMethod> reader = new ReflectiveFactoryReader(MatchersWithDodgySignatures.class);
84-
Iterator<FactoryMethod> methods = reader.iterator();
83+
final ReflectiveFactoryReader reader = new ReflectiveFactoryReader(MatchersWithDodgySignatures.class);
84+
final List<FactoryMethod> methods = methodsReadBy(reader);
8585

86-
assertTrue("Expected first method", methods.hasNext());
87-
assertEquals("goodMethod", methods.next().getName());
88-
89-
assertTrue("Expected second method", methods.hasNext());
90-
assertEquals("anotherGoodMethod", methods.next().getName());
91-
92-
assertFalse("Expected no more methods", methods.hasNext());
86+
assertEquals(2, methods.size());
87+
assertEquals("anotherGoodMethod", methods.get(0).getName());
88+
assertEquals("goodMethod", methods.get(1).getName());
9389
}
9490

9591
public static class GenerifiedMatchers {
@@ -173,10 +169,15 @@ public void testReadsArrayAndVarArgParameterTypes() {
173169

174170
public void testReadsGenerifiedParameterTypes() {
175171
FactoryMethod method = readMethod(ParameterizedMatchers.class, "withGenerifiedParam");
172+
176173
assertEquals("java.util.Collection<? extends java.lang.Comparable<java.lang.String>>",
177-
method.getParameters().get(0).getType());
178-
assertEquals("java.util.Set<java.lang.String[]>[]",
179-
method.getParameters().get(1).getType());
174+
method.getParameters().get(0).getType());
175+
176+
String expected = System.getProperty("java.version").startsWith("1.7.")
177+
? "java.util.Set<[Ljava.lang.String;>[]"
178+
: "java.util.Set<java.lang.String[]>[]";
179+
180+
assertEquals(expected, method.getParameters().get(1).getType());
180181
}
181182

182183
public void testCannotReadParameterNamesSoMakesThemUpInstead() {
@@ -257,6 +258,19 @@ public void testCatchesSubclasses() {
257258
assertNotNull(readMethod(SubclassOfMatcher.class, "subclassMethod"));
258259
}
259260

261+
private static List<FactoryMethod> methodsReadBy(final ReflectiveFactoryReader reader) {
262+
final List<FactoryMethod> extractedMethods = new ArrayList<FactoryMethod>();
263+
for (FactoryMethod factoryMethod : reader) {
264+
extractedMethods.add(factoryMethod);
265+
}
266+
Collections.sort(extractedMethods, new Comparator<FactoryMethod>() {
267+
@Override public int compare(FactoryMethod o1, FactoryMethod o2) {
268+
return o1.getName().compareTo(o2.getName());
269+
}
270+
});
271+
return extractedMethods;
272+
}
273+
260274
private static FactoryMethod readMethod(Class<?> cls, String methodName) {
261275
for (FactoryMethod method : new ReflectiveFactoryReader(cls)) {
262276
if (method.getName().equals(methodName)) {
@@ -265,5 +279,4 @@ private static FactoryMethod readMethod(Class<?> cls, String methodName) {
265279
}
266280
return null;
267281
}
268-
269282
}

0 commit comments

Comments
 (0)