Skip to content

Commit

Permalink
Adds tests for FactoryCache
Browse files Browse the repository at this point in the history
  • Loading branch information
jqno committed Nov 19, 2024
1 parent 80e9e96 commit 382d9b4
Showing 1 changed file with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

public class FactoryCacheTest {

private static final String SOME_LABEL = "label";
private static final Class<String> STRING_CLASS = String.class;
private static final PrefabValueFactory<String> STRING_FACTORY = new SimpleFactory<>(
"red",
Expand All @@ -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
Expand All @@ -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();
Expand Down

0 comments on commit 382d9b4

Please sign in to comment.