[6543] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
[6533] | 2 | package org;
|
---|
| 3 |
|
---|
[8514] | 4 | import java.util.Collection;
|
---|
| 5 |
|
---|
[6533] | 6 | import org.hamcrest.Description;
|
---|
| 7 | import org.hamcrest.Matcher;
|
---|
| 8 | import org.hamcrest.TypeSafeMatcher;
|
---|
[6543] | 9 | import org.junit.Ignore;
|
---|
[6533] | 10 | import org.openstreetmap.josm.tools.Predicate;
|
---|
| 11 |
|
---|
[6543] | 12 | @Ignore("no test")
|
---|
[8514] | 13 | public final class CustomMatchers {
|
---|
[6533] | 14 |
|
---|
[8514] | 15 | private CustomMatchers() {
|
---|
| 16 | // Hide constructor for utility classes
|
---|
| 17 | }
|
---|
| 18 |
|
---|
[6533] | 19 | public static <T> Matcher<? extends T> forPredicate(final Predicate<T> predicate) {
|
---|
| 20 | return new TypeSafeMatcher<T>() {
|
---|
| 21 |
|
---|
| 22 | @Override
|
---|
| 23 | protected boolean matchesSafely(T item) {
|
---|
| 24 | return predicate.evaluate(item);
|
---|
| 25 | }
|
---|
| 26 |
|
---|
| 27 | @Override
|
---|
| 28 | public void describeTo(Description description) {
|
---|
| 29 | description.appendValue(predicate);
|
---|
| 30 | }
|
---|
| 31 | };
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | public static Matcher<Collection<?>> hasSize(final int size) {
|
---|
| 35 | return new TypeSafeMatcher<Collection<?>>() {
|
---|
| 36 | @Override
|
---|
| 37 | protected boolean matchesSafely(Collection<?> collection) {
|
---|
| 38 | return collection != null && collection.size() == size;
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | @Override
|
---|
| 42 | public void describeTo(Description description) {
|
---|
| 43 | description.appendText("hasSize(").appendValue(size).appendText(")");
|
---|
| 44 | }
|
---|
| 45 | };
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | public static Matcher<Collection<?>> isEmpty() {
|
---|
| 49 | return new TypeSafeMatcher<Collection<?>>() {
|
---|
| 50 | @Override
|
---|
| 51 | protected boolean matchesSafely(Collection<?> collection) {
|
---|
| 52 | return collection != null && collection.isEmpty();
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | @Override
|
---|
| 56 | public void describeTo(Description description) {
|
---|
| 57 | description.appendText("isEmpty()");
|
---|
| 58 | }
|
---|
| 59 | };
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | }
|
---|