1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.collections4.functors;
18
19 import static org.junit.jupiter.api.Assertions.assertFalse;
20 import static org.junit.jupiter.api.Assertions.assertTrue;
21
22 import java.util.Collection;
23 import java.util.Collections;
24
25 import org.apache.commons.collections4.Predicate;
26 import org.junit.jupiter.api.Test;
27
28
29
30
31 @SuppressWarnings("boxing")
32 public class AllPredicateTest extends AbstractAnyAllOnePredicateTest<Integer> {
33
34
35
36
37 public AllPredicateTest() {
38 super(42);
39 }
40
41
42
43
44 @Override
45 protected final Predicate<Integer> getPredicateInstance(final Collection<Predicate<Integer>> predicates) {
46 return AllPredicate.allPredicate(predicates);
47 }
48
49
50
51
52 @Override
53 protected final Predicate<Integer> getPredicateInstance(final Predicate<? super Integer>... predicates) {
54 return AllPredicate.allPredicate(predicates);
55 }
56
57
58
59
60 @Test
61 public void testAllTrue() {
62 assertTrue(getPredicateInstance(true, true).evaluate(getTestValue()),
63 "multiple true predicates evaluated to false");
64 assertTrue(getPredicateInstance(true, true, true).evaluate(getTestValue()),
65 "multiple true predicates evaluated to false");
66 }
67
68
69
70
71 @SuppressWarnings({"unchecked"})
72 @Test
73 public void testEmptyArrayToGetInstance() {
74 assertTrue(getPredicateInstance(new Predicate[] {}).evaluate(null), "empty array not true");
75 }
76
77
78
79
80 @Test
81 public void testEmptyCollectionToGetInstance() {
82 final Predicate<Integer> allPredicate = getPredicateInstance(Collections.<Predicate<Integer>>emptyList());
83 assertTrue(allPredicate.evaluate(getTestValue()), "empty collection not true");
84 }
85
86
87
88
89 @SuppressWarnings("unchecked")
90 @Test
91 public void testOneFalsePredicate() {
92
93
94 final Predicate<Integer> predicate = createMockPredicate(false);
95 assertFalse(AllPredicate.allPredicate(predicate).test(getTestValue()), "single false predicate evaluated to true");
96 }
97
98
99
100
101 @SuppressWarnings("unchecked")
102 @Test
103 public void testOneTruePredicate() {
104
105
106 final Predicate<Integer> predicate = createMockPredicate(true);
107 assertTrue(AllPredicate.allPredicate(predicate).test(getTestValue()), "single true predicate evaluated to false");
108 }
109
110
111
112
113
114 @Test
115 public void testTrueAndFalseCombined() {
116 assertFalse(getPredicateInstance(false, null).evaluate(getTestValue()),
117 "false predicate evaluated to true");
118 assertFalse(getPredicateInstance(false, null, null).evaluate(getTestValue()),
119 "false predicate evaluated to true");
120 assertFalse(getPredicateInstance(true, false, null).evaluate(getTestValue()),
121 "false predicate evaluated to true");
122 assertFalse(getPredicateInstance(true, true, false).evaluate(getTestValue()),
123 "false predicate evaluated to true");
124 assertFalse(getPredicateInstance(true, true, false, null).evaluate(getTestValue()),
125 "false predicate evaluated to true");
126 }
127 }