Ranides Atterwim пре 10 година
родитељ
комит
c1242e69c2

+ 1 - 0
assira/src/test/java/net/ranides/assira/collection/lookups/LazyLookupTest.java

@@ -39,6 +39,7 @@ public class LazyLookupTest {
     
     @Test
     public void testIfPresent() {
+        // tak skonfigurowany lookup łamie częściowo kontrakt (związany z default)
         ToIntFunction<String> sup2 = (Serializable & ToIntFunction<String>) (v) -> null == v ? -2 : Integer.valueOf(v);
         LazyLookup<String> map = new LazyLookup<>(new HashLookup<>(), sup2);
         

+ 1 - 18
assira/src/test/java/net/ranides/assira/collection/maps/IntLazyMapTest.java

@@ -39,24 +39,7 @@ public class IntLazyMapTest {
 			.param("map.default!", 1)
 			.supplier(() -> new IntLazyMap<>(new IntAVLTreeMap<>($map.comparator()), sup2))
 			.run();
+        assertTrue(true);
     }
     
-    @Test
-    public void testIfPresent() {
-        IntLazyMap<String> map = new IntLazyMap<>(new IntHashMap<>(), v -> "#"+v);
-        
-        map.put(14, "He");
-        
-        assertEquals("He", map.getIfPresent(14));
-        assertEquals("He", map.getIfPresent((Number)14));
-        assertEquals("He", map.get(14));
-        assertEquals("He", map.get((Number)14));
-        
-
-        assertEquals(null, map.getIfPresent(15));
-        
-        assertEquals("#16", map.get(16));
-    }
-	
-    
 }

+ 0 - 14
assira/src/test/java/net/ranides/assira/collection/maps/LazyMapTest.java

@@ -39,18 +39,4 @@ public class LazyMapTest {
 			.run();
     }
     
-    @Test
-    public void testIfPresent() {
-        LazyMap<String, String> map = new LazyMap<>(new HashMap<>(), v -> "#"+v);
-        
-        map.put("14", "He");
-        
-        assertEquals("He", map.getIfPresent("14"));
-        assertEquals("He", map.get("14"));
-
-        assertEquals(null, map.getIfPresent("15"));
-        
-        assertEquals("#16", map.get("16"));
-    }
-    
 }

+ 41 - 0
assira/src/test/java/net/ranides/assira/collection/suite/maps/IntLazyMapTester.java

@@ -0,0 +1,41 @@
+/*
+ * @author Ranides Atterwim <ranides@gmail.com>
+ * @copyright Ranides Atterwim
+ * @license WTFPL
+ * @url http://ranides.net/projects/assira
+ */
+package net.ranides.assira.collection.suite.maps;
+
+import javax.annotation.Resource;
+import net.ranides.assira.collection.maps.IntLazyMap;
+import net.ranides.assira.test.TMap;
+import static net.ranides.assira.junit.NewAssert.*;
+import net.ranides.assira.junit.TestContract;
+
+/**
+ *
+ * @author Ranides Atterwim <ranides@gmail.com>
+ */
+@SuppressWarnings("element-type-mismatch")
+public final class IntLazyMapTester<K,V> {
+        
+    @Resource(name = "map!")
+    private TMap<Integer,V> $var;
+    
+    @Resource(name = "map.default!")
+    private V $default = null;
+    
+    @TestContract
+    public void basicIfPresent(IntLazyMap<V> target) {
+        
+        $var.item(14).into(target);
+        
+        assertEquals($var.item(14).value(), target.getIfPresent($var.item(14).keyInt()));
+        assertEquals($var.item(14).value(), target.get($var.item(14).keyInt()));
+
+        assertEquals(null, target.getIfPresent($var.item(15).keyInt()));
+        
+        assertEquals($default, target.get($var.item(16).keyInt()));
+    }
+        
+}

+ 41 - 0
assira/src/test/java/net/ranides/assira/collection/suite/maps/LazyMapTester.java

@@ -0,0 +1,41 @@
+/*
+ * @author Ranides Atterwim <ranides@gmail.com>
+ * @copyright Ranides Atterwim
+ * @license WTFPL
+ * @url http://ranides.net/projects/assira
+ */
+package net.ranides.assira.collection.suite.maps;
+
+import javax.annotation.Resource;
+import net.ranides.assira.collection.maps.LazyMap;
+import net.ranides.assira.test.TMap;
+import static net.ranides.assira.junit.NewAssert.*;
+import net.ranides.assira.junit.TestContract;
+
+/**
+ *
+ * @author Ranides Atterwim <ranides@gmail.com>
+ */
+@SuppressWarnings("element-type-mismatch")
+public final class LazyMapTester<K,V> {
+        
+    @Resource(name = "map!")
+    private TMap<K,V> $var;
+    
+    @Resource(name = "map.default!")
+    private V $default = null;
+    
+    @TestContract
+    public void basicIfPresent(LazyMap<K, V> target) {
+        
+        $var.item(14).into(target);
+        
+        assertEquals($var.item(14).value(), target.getIfPresent($var.item(14).key()));
+        assertEquals($var.item(14).value(), target.get($var.item(14).key()));
+
+        assertEquals(null, target.getIfPresent($var.item(15).key()));
+        
+        assertEquals($default, target.get($var.item(16).key()));
+    }
+        
+}