forked from junit-team/junit4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
David Saff
committed
Jul 20, 2009
1 parent
017ce04
commit 4e2455b
Showing
34 changed files
with
175 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 28 additions & 8 deletions
36
src/main/java/org/junit/internal/matchers/CombinableMatcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,34 @@ | ||
package org.junit.internal.matchers; | ||
|
||
import static org.hamcrest.CoreMatchers.allOf; | ||
import static org.hamcrest.CoreMatchers.anyOf; | ||
import org.hamcrest.BaseMatcher; | ||
import org.hamcrest.Description; | ||
import org.hamcrest.Matcher; | ||
|
||
/** | ||
* @deprectated Use org.hamcrest.core.CombinableMatcher directly | ||
*/ | ||
@Deprecated | ||
public class CombinableMatcher<T> extends org.hamcrest.core.CombinableMatcher<T> { | ||
// should only be using static factories | ||
private CombinableMatcher(Matcher<? super T> matcher) { | ||
super(matcher); | ||
public class CombinableMatcher<T> extends BaseMatcher<T> { | ||
|
||
private final Matcher<? extends T> fMatcher; | ||
|
||
public CombinableMatcher(Matcher<? extends T> matcher) { | ||
fMatcher= matcher; | ||
} | ||
|
||
public boolean matches(Object item) { | ||
return fMatcher.matches(item); | ||
} | ||
|
||
public void describeTo(Description description) { | ||
description.appendDescriptionOf(fMatcher); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public CombinableMatcher<T> and(Matcher<? extends T> matcher) { | ||
return new CombinableMatcher<T>(allOf(matcher, fMatcher)); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public CombinableMatcher<T> or(Matcher<? extends T> matcher) { | ||
return new CombinableMatcher<T>(anyOf(matcher, fMatcher)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,24 @@ | ||
package org.junit.internal.matchers; | ||
|
||
import static org.hamcrest.CoreMatchers.not; | ||
import static org.junit.internal.matchers.IsCollectionContaining.hasItem; | ||
import org.hamcrest.BaseMatcher; | ||
import org.hamcrest.Description; | ||
import org.hamcrest.Matcher; | ||
import org.hamcrest.core.Every; | ||
|
||
|
||
/** | ||
* @deprecated use org.hamcrest.core.Every | ||
*/ | ||
@Deprecated | ||
public class Each { | ||
public static <T> Matcher<Iterable<T>> each(final Matcher<T> individual) { | ||
return Every.everyItem(individual); | ||
final Matcher<Iterable<T>> allItemsAre = not(hasItem(not(individual))); | ||
|
||
return new BaseMatcher<Iterable<T>>() { | ||
public boolean matches(Object item) { | ||
return allItemsAre.matches(item); | ||
} | ||
|
||
public void describeTo(Description description) { | ||
description.appendText("each "); | ||
individual.describeTo(description); | ||
} | ||
}; | ||
} | ||
} |
70 changes: 61 additions & 9 deletions
70
src/main/java/org/junit/internal/matchers/IsCollectionContaining.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,67 @@ | ||
package org.junit.internal.matchers; | ||
|
||
import static org.hamcrest.core.AllOf.allOf; | ||
import static org.hamcrest.core.IsEqual.equalTo; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
|
||
import org.hamcrest.Description; | ||
import org.hamcrest.Factory; | ||
import org.hamcrest.Matcher; | ||
|
||
// Copied (hopefully temporarily) from hamcrest-library | ||
/** | ||
* @deprecated use org.hamcrest.core.IsCollectionContaining directly | ||
*/ | ||
@Deprecated | ||
public class IsCollectionContaining<T> extends org.hamcrest.core.IsCollectionContaining<T> { | ||
// Client code should just use static factories, so this should be OK | ||
private IsCollectionContaining(Matcher<? super T> elementMatcher) { | ||
super(elementMatcher); | ||
} | ||
public class IsCollectionContaining<T> extends TypeSafeMatcher<Iterable<T>> { | ||
private final Matcher<? extends T> elementMatcher; | ||
|
||
public IsCollectionContaining(Matcher<? extends T> elementMatcher) { | ||
this.elementMatcher = elementMatcher; | ||
} | ||
|
||
@Override | ||
public boolean matchesSafely(Iterable<T> collection) { | ||
for (T item : collection) { | ||
if (elementMatcher.matches(item)){ | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
public void describeTo(Description description) { | ||
description | ||
.appendText("a collection containing ") | ||
.appendDescriptionOf(elementMatcher); | ||
} | ||
|
||
@Factory | ||
public static <T> Matcher<Iterable<T>> hasItem(Matcher<? extends T> elementMatcher) { | ||
return new IsCollectionContaining<T>(elementMatcher); | ||
} | ||
|
||
@Factory | ||
public static <T> Matcher<Iterable<T>> hasItem(T element) { | ||
return hasItem(equalTo(element)); | ||
} | ||
|
||
@Factory | ||
public static <T> Matcher<Iterable<T>> hasItems(Matcher<? extends T>... elementMatchers) { | ||
Collection<Matcher<? extends Iterable<T>>> all | ||
= new ArrayList<Matcher<? extends Iterable<T>>>(elementMatchers.length); | ||
for (Matcher<? extends T> elementMatcher : elementMatchers) { | ||
all.add(hasItem(elementMatcher)); | ||
} | ||
return allOf(all); | ||
} | ||
|
||
@Factory | ||
public static <T> Matcher<Iterable<T>> hasItems(T... elements) { | ||
Collection<Matcher<? extends Iterable<T>>> all | ||
= new ArrayList<Matcher<? extends Iterable<T>>>(elements.length); | ||
for (T element : elements) { | ||
all.add(hasItem(element)); | ||
} | ||
return allOf(all); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.