Skip to content

Commit d27f200

Browse files
author
nat.pryce
committed
fixing array null problem
making it compile again (damn you Java generics... damn you to HELL!)
1 parent a2c9338 commit d27f200

File tree

19 files changed

+410
-249
lines changed

19 files changed

+410
-249
lines changed

.idea/workspace.xml

Lines changed: 288 additions & 131 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hamcrest-core/src/main/java/org/hamcrest/core/AllOf.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package org.hamcrest.core;
22

3-
import java.util.ArrayList;
4-
import java.util.Arrays;
5-
import java.util.List;
6-
73
import org.hamcrest.Description;
84
import org.hamcrest.DiagnosingMatcher;
95
import org.hamcrest.Factory;
106
import org.hamcrest.Matcher;
117

8+
import java.util.ArrayList;
9+
import java.util.Arrays;
10+
import java.util.List;
11+
1212
/**
1313
* Calculates the logical conjunction of multiple matchers. Evaluation is shortcut, so
1414
* subsequent matchers are not called if an earlier matcher returns <code>false</code>.
@@ -57,7 +57,7 @@ public static <T> Matcher<T> allOf(Matcher<? super T>... matchers) {
5757
* Evaluates to true only if ALL of the passed in matchers evaluate to true.
5858
*/
5959
@Factory
60-
public static <T> Matcher<T> allOf(Matcher<T> first, Matcher<? super T> second) {
60+
public static <T> Matcher<T> allOf(Matcher<? super T> first, Matcher<? super T> second) {
6161
List<Matcher<? super T>> matchers = new ArrayList<Matcher<? super T>>(2);
6262
matchers.add(first);
6363
matchers.add(second);
@@ -68,7 +68,7 @@ public static <T> Matcher<T> allOf(Matcher<T> first, Matcher<? super T> second)
6868
* Evaluates to true only if ALL of the passed in matchers evaluate to true.
6969
*/
7070
@Factory
71-
public static <T> Matcher<T> allOf(Matcher<T> first, Matcher<? super T> second, Matcher<? super T> third) {
71+
public static <T> Matcher<T> allOf(Matcher<? super T> first, Matcher<? super T> second, Matcher<? super T> third) {
7272
List<Matcher<? super T>> matchers = new ArrayList<Matcher<? super T>>(3);
7373
matchers.add(first);
7474
matchers.add(second);
@@ -80,7 +80,7 @@ public static <T> Matcher<T> allOf(Matcher<T> first, Matcher<? super T> second,
8080
* Evaluates to true only if ALL of the passed in matchers evaluate to true.
8181
*/
8282
@Factory
83-
public static <T> Matcher<T> allOf(Matcher<T> first, Matcher<? super T> second, Matcher<? super T> third, Matcher<? super T> fourth) {
83+
public static <T> Matcher<T> allOf(Matcher<? super T> first, Matcher<? super T> second, Matcher<? super T> third, Matcher<? super T> fourth) {
8484
List<Matcher<? super T>> matchers = new ArrayList<Matcher<? super T>>(4);
8585
matchers.add(first);
8686
matchers.add(second);
@@ -93,7 +93,7 @@ public static <T> Matcher<T> allOf(Matcher<T> first, Matcher<? super T> second,
9393
* Evaluates to true only if ALL of the passed in matchers evaluate to true.
9494
*/
9595
@Factory
96-
public static <T> Matcher<T> allOf(Matcher<T> first, Matcher<? super T> second, Matcher<? super T> third, Matcher<? super T> fourth, Matcher<? super T> fifth) {
96+
public static <T> Matcher<T> allOf(Matcher<? super T> first, Matcher<? super T> second, Matcher<? super T> third, Matcher<? super T> fourth, Matcher<? super T> fifth) {
9797
List<Matcher<? super T>> matchers = new ArrayList<Matcher<? super T>>(5);
9898
matchers.add(first);
9999
matchers.add(second);
@@ -107,7 +107,7 @@ public static <T> Matcher<T> allOf(Matcher<T> first, Matcher<? super T> second,
107107
* Evaluates to true only if ALL of the passed in matchers evaluate to true.
108108
*/
109109
@Factory
110-
public static <T> Matcher<T> allOf(Matcher<T> first, Matcher<? super T> second, Matcher<? super T> third, Matcher<? super T> fourth, Matcher<? super T> fifth, Matcher<? super T> sixth) {
110+
public static <T> Matcher<T> allOf(Matcher<? super T> first, Matcher<? super T> second, Matcher<? super T> third, Matcher<? super T> fourth, Matcher<? super T> fifth, Matcher<? super T> sixth) {
111111
List<Matcher<? super T>> matchers = new ArrayList<Matcher<? super T>>(6);
112112
matchers.add(first);
113113
matchers.add(second);

hamcrest-core/src/main/java/org/hamcrest/core/IsEqual.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
*/
33
package org.hamcrest.core;
44

5-
import java.lang.reflect.Array;
6-
75
import org.hamcrest.BaseMatcher;
86
import org.hamcrest.Description;
97
import org.hamcrest.Factory;
108
import org.hamcrest.Matcher;
119

10+
import java.lang.reflect.Array;
11+
1212

1313
/**
1414
* Is the value equal to another value, as tested by the
@@ -32,7 +32,7 @@ public void describeTo(Description description) {
3232
private static boolean areEqual(Object o1, Object o2) {
3333
if (o1 == null) {
3434
return o2 == null;
35-
} else if (isArray(o1)) {
35+
} else if (o2 != null && isArray(o1)) {
3636
return isArray(o2) && areArraysEqual(o1, o2);
3737
} else {
3838
return o1.equals(o2);

hamcrest-library/src/main/java/org/hamcrest/beans/HasProperty.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public boolean matchesSafely(T obj) {
3838
@Override
3939
public void describeMismatchSafely(T item, Description mismatchDescription) {
4040
mismatchDescription.appendText("no ").appendValue(propertyName).appendText(" in ").appendValue(item);
41-
};
41+
}
4242

4343
public void describeTo(Description description) {
4444
description.appendText("hasProperty(").appendValue(propertyName).appendText(")");

hamcrest-library/src/main/java/org/hamcrest/collection/IsArrayContainingInOrder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414

1515
public class IsArrayContainingInOrder<E> extends TypeSafeMatcher<E[]> {
1616
private final Collection<Matcher<? super E>> matchers;
17-
private final IsIterableContainingInOrder<E,Iterable<E>> iterableMatcher;
17+
private final IsIterableContainingInOrder<E> iterableMatcher;
1818

1919
public IsArrayContainingInOrder(List<Matcher<? super E>> matchers) {
20-
this.iterableMatcher = new IsIterableContainingInOrder<E,Iterable<E>>(matchers);
20+
this.iterableMatcher = new IsIterableContainingInOrder<E>(matchers);
2121
this.matchers = matchers;
2222
}
2323

hamcrest-library/src/main/java/org/hamcrest/collection/IsIterableContainingInOrder.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111

1212
import static org.hamcrest.core.IsEqual.equalTo;
1313

14-
public class IsIterableContainingInOrder<E, C extends Iterable<? extends E>> extends TypeSafeDiagnosingMatcher<C> {
14+
public class IsIterableContainingInOrder<E> extends TypeSafeDiagnosingMatcher<Iterable<? extends E>> {
1515
private final List<Matcher<? super E>> matchers;
1616

1717
public IsIterableContainingInOrder(List<Matcher<? super E>> matchers) {
1818
this.matchers = matchers;
1919
}
2020

2121
@Override
22-
protected boolean matchesSafely(C iterable, Description mismatchDescription) {
22+
protected boolean matchesSafely(Iterable<? extends E> iterable, Description mismatchDescription) {
2323
MatchSeries<E> matchSeries = new MatchSeries<E>(matchers, mismatchDescription);
2424
for (E item : iterable) {
2525
if (!matchSeries.matches(item)) {
@@ -89,21 +89,23 @@ public static <E> Matcher<Iterable<? extends E>> contains(E... items) {
8989
for (E item : items) {
9090
matchers.add(equalTo(item));
9191
}
92+
9293
return contains(matchers);
9394
}
9495

9596
@Factory
96-
public static <E, C extends Iterable<? extends E>> Matcher<C> contains(final Matcher<E> item) {
97+
public static <E> Matcher<Iterable<? extends E>> contains(final Matcher<? super E> item) {
9798
return contains(new ArrayList<Matcher<? super E>>(Arrays.asList(item)));
9899
}
99100

100101
@Factory
101-
public static <E, C extends Iterable<? extends E>> Matcher<C> contains(Matcher<? super E>... items) {
102-
return contains(Arrays.asList(items));
102+
public static <E> Matcher<Iterable<? extends E>> contains(Matcher<? super E>... matchers) {
103+
List<Matcher<? super E>> matcherList = Arrays.asList(matchers);
104+
return contains(matcherList);
103105
}
104106

105107
@Factory
106-
public static <E, C extends Iterable<? extends E>> Matcher<C> contains(List<Matcher<? super E>> contents) {
107-
return new IsIterableContainingInOrder<E, C>(contents);
108+
public static <E> Matcher<Iterable<? extends E>> contains(List<Matcher<? super E>> contents) {
109+
return new IsIterableContainingInOrder<E>(contents);
108110
}
109111
}

hamcrest-library/src/main/java/org/hamcrest/number/OrderingComparison.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ public class OrderingComparison<T extends Comparable<T>> extends TypeSafeMatcher
1515
private final int minCompare, maxCompare;
1616

1717
private static final String[] comparisonDescriptions = {
18-
"less than",
19-
"equal to",
20-
"greater than"
18+
"less than",
19+
"equal to",
20+
"greater than"
2121
};
2222

2323
private OrderingComparison(T expected, int minCompare, int maxCompare) {
@@ -34,60 +34,60 @@ public boolean matchesSafely(T actual) {
3434

3535
@Override
3636
public void describeMismatchSafely(T actual, Description mismatchDescription) {
37-
mismatchDescription.appendValue(actual) .appendText(" was ")
38-
.appendText(asText(actual.compareTo(expected)))
39-
.appendText(" ").appendValue(expected);
37+
mismatchDescription.appendValue(actual).appendText(" was ")
38+
.appendText(asText(actual.compareTo(expected)))
39+
.appendText(" ").appendValue(expected);
4040
}
41-
41+
4242
public void describeTo(Description description) {
4343
description.appendText("a value ").appendText(asText(minCompare));
4444
if (minCompare != maxCompare) {
4545
description.appendText(" or ").appendText(asText(maxCompare));
4646
}
4747
description.appendText(" ").appendValue(expected);
4848
}
49-
49+
5050
private String asText(int comparison) {
51-
return comparisonDescriptions[comparison+1];
51+
return comparisonDescriptions[comparison + 1];
5252
}
5353

5454
/**
55-
* Is value = expected?
55+
* @return Is value = expected?
5656
*/
5757
@Factory
58-
public static <T extends Comparable<T>> Matcher<? super T> comparesEqualTo(T value) {
58+
public static <T extends Comparable<T>> Matcher<T> comparesEqualTo(T value) {
5959
return new OrderingComparison<T>(value, EQUAL, EQUAL);
6060
}
6161

6262
/**
6363
* Is value > expected?
6464
*/
6565
@Factory
66-
public static <T extends Comparable<T>> Matcher<? super T> greaterThan(T value) {
66+
public static <T extends Comparable<T>> Matcher<T> greaterThan(T value) {
6767
return new OrderingComparison<T>(value, GREATER_THAN, GREATER_THAN);
6868
}
6969

7070
/**
7171
* Is value >= expected?
7272
*/
7373
@Factory
74-
public static <T extends Comparable<T>> Matcher<? super T> greaterThanOrEqualTo(T value) {
74+
public static <T extends Comparable<T>> Matcher<T> greaterThanOrEqualTo(T value) {
7575
return new OrderingComparison<T>(value, EQUAL, GREATER_THAN);
7676
}
7777

7878
/**
7979
* Is value < expected?
8080
*/
8181
@Factory
82-
public static <T extends Comparable<T>> Matcher<? super T> lessThan(T value) {
82+
public static <T extends Comparable<T>> Matcher<T> lessThan(T value) {
8383
return new OrderingComparison<T>(value, LESS_THAN, LESS_THAN);
8484
}
8585

8686
/**
8787
* Is value <= expected?
8888
*/
8989
@Factory
90-
public static <T extends Comparable<T>> Matcher<? super T> lessThanOrEqualTo(T value) {
90+
public static <T extends Comparable<T>> Matcher<T> lessThanOrEqualTo(T value) {
9191
return new OrderingComparison<T>(value, LESS_THAN, EQUAL);
9292
}
93-
}
93+
}

hamcrest-library/src/main/java/org/hamcrest/object/HasToString.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package org.hamcrest.object;
22

3-
import static org.hamcrest.core.IsEqual.equalTo;
4-
53
import org.hamcrest.Factory;
64
import org.hamcrest.FeatureMatcher;
75
import org.hamcrest.Matcher;
86

7+
import static org.hamcrest.core.IsEqual.equalTo;
8+
99
public class HasToString<T> extends FeatureMatcher<T, String> {
1010
public HasToString(Matcher<? super String> toStringMatcher) {
1111
super(toStringMatcher, "with toString()", "toString()");
@@ -14,7 +14,7 @@ public HasToString(Matcher<? super String> toStringMatcher) {
1414
@Override
1515
protected String featureValueOf(T actual) {
1616
return actual.toString();
17-
};
17+
}
1818

1919
/**
2020
* Evaluates whether item.toString() satisfies a given matcher.

hamcrest-unit-test/src/main/hamcrest-unit-tests.iml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
<orderEntry type="inheritedJdk" />
99
<orderEntry type="sourceFolder" forTests="false" />
1010
<orderEntry type="module" module-name="hamcrest-core" />
11+
<orderEntry type="module" module-name="hamcrest-library" />
12+
<orderEntry type="module" module-name="hamcrest-generator" />
13+
<orderEntry type="module" module-name="hamcrest-integration" />
1114
<orderEntry type="library" name="integration" level="project" />
12-
<orderEntry type="library" name="ant-output" level="project" />
1315
</component>
1416
</module>
1517

hamcrest-unit-test/src/main/java/org/hamcrest/MatcherAssertTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package org.hamcrest;
22

3-
import static org.hamcrest.MatcherAssert.assertThat;
4-
import static org.hamcrest.Matchers.equalTo;
53
import junit.framework.TestCase;
64

5+
import static org.hamcrest.MatcherAssert.assertThat;
6+
import static org.hamcrest.core.IsEqual.equalTo;
7+
78
public class MatcherAssertTest extends TestCase {
89

910
public void testIncludesDescriptionOfTestedValueInErrorMessage() {

hamcrest-unit-test/src/main/java/org/hamcrest/collection/IsEmptyCollectionTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package org.hamcrest.collection;
22

3-
import static org.hamcrest.Matchers.is;
4-
import static org.hamcrest.collection.IsEmptyCollection.empty;
3+
import org.hamcrest.AbstractMatcherTest;
4+
import org.hamcrest.Matcher;
55

66
import java.util.ArrayList;
77
import java.util.Arrays;
88
import java.util.Collection;
99

10-
import org.hamcrest.AbstractMatcherTest;
11-
import org.hamcrest.Matcher;
10+
import static org.hamcrest.collection.IsEmptyCollection.empty;
11+
import static org.hamcrest.core.Is.is;
1212

1313
public class IsEmptyCollectionTest extends AbstractMatcherTest {
1414

hamcrest-unit-test/src/main/java/org/hamcrest/collection/IsIterableContainingInOrderTest.java

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,63 +5,66 @@
55
import org.hamcrest.Matcher;
66

77
import java.util.ArrayList;
8+
import java.util.List;
89

910
import static java.util.Arrays.asList;
10-
import static org.hamcrest.Matchers.equalTo;
1111
import static org.hamcrest.collection.IsIterableContainingInOrder.contains;
12+
import static org.hamcrest.core.IsEqual.equalTo;
1213

1314
@SuppressWarnings("unchecked")
1415
public class IsIterableContainingInOrderTest extends AbstractMatcherTest {
16+
// temporary hack until the Java type system works
1517
private final Matcher<Iterable<? extends WithValue>> contains123 = contains(value(1), value(2), value(3));
16-
18+
1719
@Override
1820
protected Matcher<?> createMatcher() {
1921
return contains(1, 2);
2022
}
21-
23+
2224
public void testMatchingSingleItemIterable() throws Exception {
2325
assertMatches("Single item iterable", contains(1), asList(1));
2426
}
25-
27+
2628
public void testMatchingMultipleItemIterable() throws Exception {
2729
assertMatches("Multiple item iterable", contains(1, 2, 3), asList(1, 2, 3));
2830
}
29-
31+
3032
public void testDoesNotMatchWithMoreElementsThanExpected() throws Exception {
3133
assertMismatchDescription("Not matched: <4>", contains(1, 2, 3), asList(1, 2, 3, 4));
3234
}
33-
35+
3436
public void testDoesNotMatchWithFewerElementsThanExpected() throws Exception {
35-
assertMismatchDescription("No item matched: value with <3>", contains123, asList(make(1), make(2)));
37+
List<WithValue> valueList = asList(make(1), make(2));
38+
assertMismatchDescription("No item matched: value with <3>", contains123, valueList);
3639
}
37-
40+
3841
public void testDoesNotMatchIfSingleItemMismatches() throws Exception {
39-
assertMismatchDescription("item 0: value was <3>", contains(value(4)), asList(make(3)));
42+
assertMismatchDescription("item 0: value was <3>", contains(value(4)), asList(make(3)));
4043
}
4144

4245
public void testDoesNotMatchIfOneOfMultipleItemsMismatch() throws Exception {
4346
assertMismatchDescription("item 2: value was <4>", contains123, asList(make(1), make(2), make(4)));
4447
}
4548

4649
public void testDoesNotMatchEmptyIterable() throws Exception {
47-
assertMismatchDescription("No item matched: value with <4>", contains(value(4)), new ArrayList<WithValue>());
50+
assertMismatchDescription("No item matched: value with <4>", contains(value(4)), new ArrayList<WithValue>());
4851
}
4952

5053
public void testHasAReadableDescription() {
5154
assertDescription("iterable containing [<1>, <2>]", contains(1, 2));
5255
}
53-
56+
5457
public static class WithValue {
5558
private final int value;
5659
public WithValue(int value) { this.value = value; }
5760
public int getValue() { return value; }
5861
@Override public String toString() { return "WithValue " + value; }
5962
}
60-
63+
6164
public static WithValue make(int value) {
6265
return new WithValue(value);
6366
}
64-
67+
6568
public static Matcher<WithValue> value(int value) {
6669
return new FeatureMatcher<WithValue, Integer>(equalTo(value), "value with", "value") {
6770
@Override protected Integer featureValueOf(WithValue actual) { return actual.getValue(); }

0 commit comments

Comments
 (0)