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

Last change on this file since 8570 was 8514, checked in by Don-vip, 9 years ago

checkstyle: various checks

  • Property svn:eol-style set to native
File size: 1.8 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org;
3
4import java.util.Collection;
5
6import org.hamcrest.Description;
7import org.hamcrest.Matcher;
8import org.hamcrest.TypeSafeMatcher;
9import org.junit.Ignore;
10import org.openstreetmap.josm.tools.Predicate;
11
12@Ignore("no test")
13public final class CustomMatchers {
14
15 private CustomMatchers() {
16 // Hide constructor for utility classes
17 }
18
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}
Note: See TracBrowser for help on using the repository browser.