Changeset 10691 in josm for trunk/test
- Timestamp:
- 2016-07-31T17:58:31+02:00 (8 years ago)
- Location:
- trunk/test/unit/org
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/CustomMatchers.java
r9246 r10691 4 4 import java.awt.geom.Point2D; 5 5 import java.util.Collection; 6 import java.util.function.Predicate; 6 7 7 8 import org.hamcrest.CustomTypeSafeMatcher; … … 12 13 import org.openstreetmap.josm.data.coor.EastNorth; 13 14 import org.openstreetmap.josm.data.coor.LatLon; 14 import org.openstreetmap.josm.tools.Predicate;15 15 16 16 /** … … 35 35 @Override 36 36 protected boolean matchesSafely(T item) { 37 return predicate. evaluate(item);37 return predicate.test(item); 38 38 } 39 39 -
trunk/test/unit/org/openstreetmap/josm/tools/PredicatesTest.java
r10553 r10691 9 9 import java.util.List; 10 10 import java.util.Properties; 11 import java.util.function.Predicate; 11 12 import java.util.regex.Pattern; 12 13 … … 38 39 public void testAlwaysTrue() { 39 40 Predicate<Object> alwaysTrue = Predicates.alwaysTrue(); 40 assertTrue(alwaysTrue. evaluate(new Object()));41 assertTrue(alwaysTrue. evaluate(Boolean.TRUE));41 assertTrue(alwaysTrue.test(new Object())); 42 assertTrue(alwaysTrue.test(Boolean.TRUE)); 42 43 } 43 44 … … 48 49 public void testAlwaysFalse() { 49 50 Predicate<Object> alwaysFalse = Predicates.alwaysFalse(); 50 assertFalse(alwaysFalse.evaluate(new Object())); 51 assertFalse(alwaysFalse.evaluate(Boolean.TRUE)); 52 } 53 54 /** 55 * Test {@link Predicates#not(Predicate)} 56 */ 57 @Test 58 public void testNot() { 59 Predicate<Boolean> not = Predicates.not(new Predicate<Boolean>() { 60 @Override 61 public boolean evaluate(Boolean object) { 62 return object; 63 } 64 }); 65 assertFalse(not.evaluate(Boolean.TRUE)); 66 assertTrue(not.evaluate(Boolean.FALSE)); 51 assertFalse(alwaysFalse.test(new Object())); 52 assertFalse(alwaysFalse.test(Boolean.TRUE)); 67 53 } 68 54 … … 74 60 Integer testObject = Integer.valueOf(1); 75 61 Predicate<Integer> equalTo = Predicates.equalTo(testObject); 76 assertTrue(equalTo. evaluate(testObject));77 assertTrue(equalTo. evaluate(Integer.valueOf(1)));62 assertTrue(equalTo.test(testObject)); 63 assertTrue(equalTo.test(Integer.valueOf(1))); 78 64 79 assertFalse(equalTo. evaluate(Integer.valueOf(2)));80 assertFalse(equalTo. evaluate(null));65 assertFalse(equalTo.test(Integer.valueOf(2))); 66 assertFalse(equalTo.test(null)); 81 67 } 82 68 … … 87 73 public void testIsOfClass() { 88 74 Predicate<Object> isOfClass = Predicates.<Object>isOfClass(Hashtable.class); 89 assertFalse(isOfClass. evaluate(null));90 assertFalse(isOfClass. evaluate(new Object()));91 assertFalse(isOfClass. evaluate(new Properties()));92 assertTrue(isOfClass. evaluate(new Hashtable<>()));75 assertFalse(isOfClass.test(null)); 76 assertFalse(isOfClass.test(new Object())); 77 assertFalse(isOfClass.test(new Properties())); 78 assertTrue(isOfClass.test(new Hashtable<>())); 93 79 } 94 80 … … 99 85 public void testIsInstanceOf() { 100 86 Predicate<Object> isInstanceOf = Predicates.<Object>isInstanceOf(Hashtable.class); 101 assertFalse(isInstanceOf. evaluate(null));102 assertFalse(isInstanceOf. evaluate(new Object()));103 assertTrue(isInstanceOf. evaluate(new Properties()));104 assertTrue(isInstanceOf. evaluate(new Hashtable<>()));87 assertFalse(isInstanceOf.test(null)); 88 assertFalse(isInstanceOf.test(new Object())); 89 assertTrue(isInstanceOf.test(new Properties())); 90 assertTrue(isInstanceOf.test(new Hashtable<>())); 105 91 } 106 92 … … 112 98 Pattern p = Pattern.compile("ab?c"); 113 99 Predicate<String> stringMatchesPattern = Predicates.stringMatchesPattern(p); 114 assertFalse(stringMatchesPattern. evaluate(""));115 assertFalse(stringMatchesPattern. evaluate("a"));116 assertFalse(stringMatchesPattern. evaluate("xabcx"));117 assertTrue(stringMatchesPattern. evaluate("ac"));118 assertTrue(stringMatchesPattern. evaluate("abc"));100 assertFalse(stringMatchesPattern.test("")); 101 assertFalse(stringMatchesPattern.test("a")); 102 assertFalse(stringMatchesPattern.test("xabcx")); 103 assertTrue(stringMatchesPattern.test("ac")); 104 assertTrue(stringMatchesPattern.test("abc")); 119 105 } 120 106 … … 126 112 Pattern p = Pattern.compile("ab?c"); 127 113 Predicate<String> stringContainsPattern = Predicates.stringContainsPattern(p); 128 assertFalse(stringContainsPattern. evaluate(""));129 assertFalse(stringContainsPattern. evaluate("a"));130 assertTrue(stringContainsPattern. evaluate("xabcx"));131 assertTrue(stringContainsPattern. evaluate("ac"));132 assertTrue(stringContainsPattern. evaluate("abc"));133 assertTrue(stringContainsPattern. evaluate("xx\nabc\nx"));114 assertFalse(stringContainsPattern.test("")); 115 assertFalse(stringContainsPattern.test("a")); 116 assertTrue(stringContainsPattern.test("xabcx")); 117 assertTrue(stringContainsPattern.test("ac")); 118 assertTrue(stringContainsPattern.test("abc")); 119 assertTrue(stringContainsPattern.test("xx\nabc\nx")); 134 120 } 135 121 … … 140 126 public void testStringContains() { 141 127 Predicate<String> stringContains = Predicates.stringContains("abc"); 142 assertFalse(stringContains. evaluate(""));143 assertFalse(stringContains. evaluate("a"));144 assertTrue(stringContains. evaluate("xabcx"));145 assertFalse(stringContains. evaluate("ac"));146 assertTrue(stringContains. evaluate("abc"));128 assertFalse(stringContains.test("")); 129 assertFalse(stringContains.test("a")); 130 assertTrue(stringContains.test("xabcx")); 131 assertFalse(stringContains.test("ac")); 132 assertTrue(stringContains.test("abc")); 147 133 } 148 134 … … 154 140 Predicate<OsmPrimitive> hasTag = Predicates.hasTag("key", "value"); 155 141 Node n1 = new Node(); 156 assertFalse(hasTag. evaluate(n1));142 assertFalse(hasTag.test(n1)); 157 143 n1.put("Key", "x"); 158 assertFalse(hasTag. evaluate(n1));144 assertFalse(hasTag.test(n1)); 159 145 n1.put("key", "x"); 160 assertFalse(hasTag. evaluate(n1));146 assertFalse(hasTag.test(n1)); 161 147 n1.put("key", "value"); 162 assertTrue(hasTag. evaluate(n1));148 assertTrue(hasTag.test(n1)); 163 149 } 164 150 … … 170 156 Predicate<OsmPrimitive> hasKey = Predicates.hasKey("key"); 171 157 Node n1 = new Node(); 172 assertFalse(hasKey. evaluate(n1));158 assertFalse(hasKey.test(n1)); 173 159 n1.put("Key", "x"); 174 assertFalse(hasKey. evaluate(n1));160 assertFalse(hasKey.test(n1)); 175 161 n1.put("key", "x"); 176 assertTrue(hasKey. evaluate(n1));162 assertTrue(hasKey.test(n1)); 177 163 } 178 164 … … 184 170 List<String> list = Arrays.asList("a", "b", "c"); 185 171 Predicate<String> inCollection = Predicates.inCollection(list); 186 assertTrue(inCollection. evaluate("a"));187 assertTrue(inCollection. evaluate("c"));188 assertFalse(inCollection. evaluate("d"));189 assertFalse(inCollection. evaluate(null));172 assertTrue(inCollection.test("a")); 173 assertTrue(inCollection.test("c")); 174 assertFalse(inCollection.test("d")); 175 assertFalse(inCollection.test(null)); 190 176 191 177 List<String> list2 = Arrays.asList("a", "b", "c", null); 192 178 Predicate<String> inCollection2 = Predicates.inCollection(list2); 193 assertTrue(inCollection2. evaluate("a"));194 assertTrue(inCollection2. evaluate("c"));195 assertFalse(inCollection2. evaluate("d"));196 assertTrue(inCollection2. evaluate(null));179 assertTrue(inCollection2.test("a")); 180 assertTrue(inCollection2.test("c")); 181 assertFalse(inCollection2.test("d")); 182 assertTrue(inCollection2.test(null)); 197 183 } 198 184 … … 203 189 public void testIsNull() { 204 190 Predicate<Object> isNull = Predicates.isNull(); 205 assertTrue(isNull. evaluate(null));206 assertFalse(isNull. evaluate(Integer.valueOf(2)));191 assertTrue(isNull.test(null)); 192 assertFalse(isNull.test(Integer.valueOf(2))); 207 193 } 208 194 }
Note:
See TracChangeset
for help on using the changeset viewer.