17
17
package io .github .alexengrig .lambdax .function ;
18
18
19
19
import io .github .alexengrig .lambdax .example .Box ;
20
+ import io .github .alexengrig .lambdax .example .Holder ;
20
21
import io .github .alexengrig .lambdax .example .Item ;
22
+ import io .github .alexengrig .lambdax .example .Pack ;
21
23
import org .junit .Test ;
22
24
23
25
import java .util .function .Predicate ;
@@ -29,48 +31,66 @@ public class PredicateXTest {
29
31
@ Test
30
32
public void checkChecker () {
31
33
String value = "Coca-Cola" ;
32
- Box box = new Box (new Item (value ));
33
- Predicate <Box > isEmptyItemName = PredicateX .of (Box ::getItem ).map (Item ::getName ).check (String ::isEmpty );
34
- assertFalse (isEmptyItemName .test (box ));
34
+ Holder <Box > boxHolder = new Holder <>(new Box (new Pack (new Item (value ))));
35
+ Predicate <Holder <Box >> isEmptyItemName = PredicateX .of (Holder <Box >::get )
36
+ .map (Box ::getPack )
37
+ .map (Pack ::getItem )
38
+ .map (Item ::getName )
39
+ .check (String ::isEmpty );
40
+ assertFalse (isEmptyItemName .test (boxHolder ));
35
41
}
36
42
37
43
@ Test
38
44
public void checkEqual () {
39
45
String value = "Coca-Cola" ;
40
- Box box = new Box (new Item (value ));
41
- Predicate <Box > equalsCocaCola = PredicateX .of (Box ::getItem ).map (Item ::getName ).equal (value );
42
- assertTrue (equalsCocaCola .test (box ));
46
+ Pack pack = new Pack (new Item (value ));
47
+ Predicate <Pack > equalsCocaCola = PredicateX .of (Pack ::getItem )
48
+ .map (Item ::getName )
49
+ .equal (value );
50
+ assertTrue (equalsCocaCola .test (pack ));
43
51
}
44
52
45
53
@ Test
46
54
public void checkLess () {
47
55
String value = "Coca-Cola" ;
48
- Box box = new Box (new Item (value ));
49
- Predicate <Box > lessPepsi = PredicateX .of (Box ::getItem ).map (Item ::getName ).less ("Pepsi" );
56
+ Box box = new Box (new Pack (new Item (value )));
57
+ Predicate <Box > lessPepsi = PredicateX .of (Box ::getPack )
58
+ .map (Pack ::getItem )
59
+ .map (Item ::getName )
60
+ .less ("Pepsi" );
50
61
assertTrue (lessPepsi .test (box ));
51
62
}
52
63
53
64
@ Test
54
65
public void checkGreater () {
55
66
String value = "Schweppes" ;
56
- Box box = new Box (new Item (value ));
57
- Predicate <Box > greaterCocaCola = PredicateX .of (Box ::getItem ).map (Item ::getName ).greater ("Dr Pepper" );
67
+ Box box = new Box (new Pack (new Item (value )));
68
+ Predicate <Box > greaterCocaCola = PredicateX .of (Box ::getPack )
69
+ .map (Pack ::getItem )
70
+ .map (Item ::getName )
71
+ .greater ("Dr Pepper" );
58
72
assertTrue (greaterCocaCola .test (box ));
59
73
}
60
74
61
75
@ Test
62
76
public void checkLessOrEqual () {
63
77
String value = "Fanta" ;
64
- Box box = new Box (new Item (value ));
65
- Predicate <Box > lessPepsi = PredicateX .of (Box ::getItem ).map (Item ::getName ).lessOrEqual ("Mirinda" );
78
+ Box box = new Box (new Pack (new Item (value )));
79
+ Predicate <Box > lessPepsi = PredicateX .of (Box ::getPack )
80
+ .map (Pack ::getItem )
81
+ .map (Item ::getName )
82
+ .lessOrEqual ("Mirinda" );
66
83
assertTrue (lessPepsi .test (box ));
67
84
}
68
85
69
86
@ Test
70
87
public void checkGreaterOrEqual () {
71
88
String value = "Sprite" ;
72
- Box box = new Box (new Item (value ));
73
- Predicate <Box > greaterCocaCola = PredicateX .of (Box ::getItem ).map (Item ::getName ).greaterOrEqual ("7 Up" );
89
+ Box box = new Box (new Pack (new Item (value )));
90
+ Predicate <Box > greaterCocaCola = PredicateX .of (Box ::getPack )
91
+ .map (Pack ::getItem )
92
+ .map (Item ::getName )
93
+ .greaterOrEqual ("7 Up" );
74
94
assertTrue (greaterCocaCola .test (box ));
75
95
}
76
96
}
0 commit comments