DynamoHolder { public T getDynamo(String meta, DynamoFactory<T> dynamoFactory) { if(!mDynamoMap.containsKey(meta)) { T dynamo = dynamoFactory.buildDynamo(); mDynamoMap.put(meta, dynamo); return dynamo; } else { return mDynamoMap.get(meta); } } DynamoHolder(int maxSize); T getDynamo(String meta, DynamoFactory<T> dynamoFactory); void clearAll(); void clear(String meta); Map<String, T> getAll();  }
@Test public void testCanRetrieveSameMetaName_multipleDynamos() { DynamoHolder<TestDynamo> testDynamoHolder = new DynamoHolder<TestDynamo>(10); DynamoHolder.DynamoFactory dynamoFactorySpy = Mockito.spy(new DynamoHolder.DynamoFactory<TestDynamo>() { @Override public TestDynamo buildDynamo() { return new TestDynamo(); } }); Dynamo firstDynamoRequest = testDynamoHolder.getDynamo("testMeta1", dynamoFactorySpy); Dynamo secondDynamoRequest = testDynamoHolder.getDynamo("testMeta2", dynamoFactorySpy); Dynamo thirdDynamoRequest = testDynamoHolder.getDynamo("testMeta1", dynamoFactorySpy); Dynamo fourthDynamoRequest = testDynamoHolder.getDynamo("testMeta2", dynamoFactorySpy); Assert.assertEquals(firstDynamoRequest, thirdDynamoRequest); Assert.assertEquals(secondDynamoRequest, fourthDynamoRequest); Assert.assertNotEquals(firstDynamoRequest, secondDynamoRequest); Mockito.verify(dynamoFactorySpy, Mockito.times(2)).buildDynamo(); }
@Test public void testSizeLimiting_singleDyanmoHolder_shouldRecreateTrimmedDynamos() { DynamoHolder<TestDynamo> testDynamoHolder = new DynamoHolder<TestDynamo>(1); DynamoHolder.DynamoFactory dynamoFactorySpy = Mockito.spy(new DynamoHolder.DynamoFactory<TestDynamo>() { @Override public TestDynamo buildDynamo() { return new TestDynamo(); } }); Dynamo firstDynamoRequest = testDynamoHolder.getDynamo("testMeta1", dynamoFactorySpy); Dynamo secondDynamoRequest = testDynamoHolder.getDynamo("testMeta2", dynamoFactorySpy); Dynamo thirdDynamoRequest = testDynamoHolder.getDynamo("testMeta1", dynamoFactorySpy); Dynamo fourthDynamoRequest = testDynamoHolder.getDynamo("testMeta2", dynamoFactorySpy); Assert.assertNotEquals(firstDynamoRequest, thirdDynamoRequest); Assert.assertNotEquals(secondDynamoRequest, fourthDynamoRequest); Assert.assertNotEquals(firstDynamoRequest, secondDynamoRequest); Mockito.verify(dynamoFactorySpy, Mockito.times(4)).buildDynamo(); }