source: josm/trunk/test/unit/org/CustomMatchers.java@ 6533

Last change on this file since 6533 was 6533, checked in by simon04, 12 years ago

see #9462 - prettify valid opening_hours values as OTHER test error fixes

File size: 1.6 KB
Line 
1package org;
2
3import org.hamcrest.Description;
4import org.hamcrest.Matcher;
5import org.hamcrest.TypeSafeMatcher;
6import org.openstreetmap.josm.tools.Predicate;
7
8import java.util.Collection;
9
10public class CustomMatchers {
11
12 public static <T> Matcher<? extends T> forPredicate(final Predicate<T> predicate) {
13 return new TypeSafeMatcher<T>() {
14
15 @Override
16 protected boolean matchesSafely(T item) {
17 return predicate.evaluate(item);
18 }
19
20 @Override
21 public void describeTo(Description description) {
22 description.appendValue(predicate);
23 }
24 };
25 }
26
27 public static Matcher<Collection<?>> hasSize(final int size) {
28 return new TypeSafeMatcher<Collection<?>>() {
29 @Override
30 protected boolean matchesSafely(Collection<?> collection) {
31 return collection != null && collection.size() == size;
32 }
33
34 @Override
35 public void describeTo(Description description) {
36 description.appendText("hasSize(").appendValue(size).appendText(")");
37 }
38 };
39 }
40
41 public static Matcher<Collection<?>> isEmpty() {
42 return new TypeSafeMatcher<Collection<?>>() {
43 @Override
44 protected boolean matchesSafely(Collection<?> collection) {
45 return collection != null && collection.isEmpty();
46 }
47
48 @Override
49 public void describeTo(Description description) {
50 description.appendText("isEmpty()");
51 }
52 };
53 }
54
55}
Note: See TracBrowser for help on using the repository browser.