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

Last change on this file since 7109 was 6543, checked in by simon04, 11 years ago

fix #9480 - ignore org.CustomMatchers from test

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