forked from mrwilson/java-8-matchers
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJava8MatchersTest.java
More file actions
57 lines (45 loc) · 1.88 KB
/
Java8MatchersTest.java
File metadata and controls
57 lines (45 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package uk.co.probablyfine.matchers;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
public class Java8MatchersTest {
final A entity = new A();
@Test
public void propertiesWhichAreTrue() {
assertThat(entity, Java8Matchers.where(A::isCool));
assertThat(entity, Java8Matchers.where(a -> a.isCool()));
}
@Test
public void propertiesWhichAreFalse() {
assertThat(entity, Java8Matchers.whereNot(A::isBoring));
assertThat(entity, Java8Matchers.whereNot(a -> a.isBoring()));
}
@Test
public void matchProperties() {
assertThat(entity, Java8Matchers.where(A::name, is("A")));
assertThat(entity, Java8Matchers.where(a -> a.name(), is("A")));
}
@Test
public void failMatchingProperties() {
Helper.testFailingMatcher(entity, Java8Matchers.where(A::name, is("X")), "with a name (a String) which is \"X\"", "had the name (a String) \"A\"");
Helper.testFailingMatcher(entity, Java8Matchers.where(a -> a.name(), is("X")), "with a String which is \"X\"", "had the String \"A\"");
Helper.testFailingMatcher(entity, Java8Matchers.where(A::age, not(is(42))), "with an age (an int) which not is <42>", "had the age (an int) <42>");
Helper.testFailingMatcher(entity, Java8Matchers.where(a -> a.age(), is(1337)), "with an Integer which is <1337>", "had the Integer <42>");
Helper.testFailingMatcher(entity, Java8Matchers.where("age", a -> a.age(), is(1337)), "with an age which is <1337>", "had the age <42>");
}
static class A {
boolean isCool() {
return true;
}
boolean isBoring() {
return false;
}
String name() {
return "A";
}
int age() {
return 42;
}
}
}