diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/FactoryCacheTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/FactoryCacheTest.java index 89692154a..66a17eff3 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/FactoryCacheTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/vintage/FactoryCacheTest.java @@ -8,6 +8,7 @@ public class FactoryCacheTest { + private static final String SOME_LABEL = "label"; private static final Class STRING_CLASS = String.class; private static final PrefabValueFactory STRING_FACTORY = new SimpleFactory<>( "red", @@ -27,6 +28,14 @@ public class FactoryCacheTest { public void putAndGetTuple() { cache.put(STRING_CLASS, STRING_FACTORY); assertEquals(STRING_FACTORY, cache.get(STRING_CLASS)); + assertNull(cache.get(STRING_CLASS, SOME_LABEL)); + } + + @Test + public void putAndGetTupleWithLabel() { + cache.put(STRING_CLASS, SOME_LABEL, STRING_FACTORY); + assertEquals(STRING_FACTORY, cache.get(STRING_CLASS, SOME_LABEL)); + assertNull(cache.get(STRING_CLASS)); } @Test @@ -38,23 +47,64 @@ public void putTwiceAndGetBoth() { assertEquals(STRING_FACTORY, cache.get(STRING_CLASS)); } + @Test + public void putTwiceAndGetBothWithLabel() { + cache.put(STRING_CLASS, SOME_LABEL, STRING_FACTORY); + cache.put(INT_CLASS, SOME_LABEL, INT_FACTORY); + + assertEquals(INT_FACTORY, cache.get(INT_CLASS, SOME_LABEL)); + assertEquals(STRING_FACTORY, cache.get(STRING_CLASS, SOME_LABEL)); + } + @Test public void putNullAndGetNothingBack() { cache.put((Class) null, STRING_FACTORY); assertNull(cache.get(null)); } + @Test + public void putNullAndGetNothingBackWithLabel() { + cache.put((Class) null, SOME_LABEL, STRING_FACTORY); + assertNull(cache.get(null, SOME_LABEL)); + } + @Test public void contains() { cache.put(STRING_CLASS, STRING_FACTORY); assertTrue(cache.contains(STRING_CLASS)); } + @Test + public void containsWithLabel() { + cache.put(STRING_CLASS, SOME_LABEL, STRING_FACTORY); + assertTrue(cache.contains(STRING_CLASS, SOME_LABEL)); + assertFalse(cache.contains(STRING_CLASS)); + } + @Test public void doesntContain() { assertFalse(cache.contains(STRING_CLASS)); } + @Test + public void doesntContainWithLabel() { + cache.put(STRING_CLASS, STRING_FACTORY); + assertFalse(cache.contains(STRING_CLASS, SOME_LABEL)); + } + + @Test + public void copy() { + cache.put(STRING_CLASS, STRING_FACTORY); + + FactoryCache copy = cache.copy(); + copy.put(INT_CLASS, INT_FACTORY); + + assertTrue(copy.contains(STRING_CLASS)); + + assertFalse(copy == cache); + assertFalse(cache.contains(INT_CLASS)); + } + @Test public void merge() { FactoryCache a = new FactoryCache();