### Question:
FixedSizeMRUCachingFactory implements Factory<K, V> { @Override public V get(K key) { V value = cache.get(key); if (value != null) { return value; } value = delegate.get(key); cache.put(key, value); return value; } FixedSizeMRUCachingFactory(Factory<K, V> factory, int size); @Override V get(K key);  }### Answer:
@Test public void testCacheOfSize1() throws Exception { FixedSizeMRUCachingFactory<Integer, Integer> cache = new FixedSizeMRUCachingFactory<Integer, Integer>(callCountFactory, 1); assertEquals(0, callCountFactory.calls(0)); cache.get(0); assertEquals(1, callCountFactory.calls(0)); cache.get(0); assertEquals(1, callCountFactory.calls(0)); cache.get(0); assertEquals(1, callCountFactory.calls(0)); assertEquals(0, callCountFactory.calls(1)); cache.get(1); assertEquals(1, callCountFactory.calls(1)); cache.get(1); assertEquals(1, callCountFactory.calls(1)); cache.get(1); assertEquals(1, callCountFactory.calls(1)); assertEquals(1, callCountFactory.calls(0)); cache.get(0); assertEquals(2, callCountFactory.calls(0)); cache.get(0); assertEquals(2, callCountFactory.calls(0)); cache.get(0); assertEquals(2, callCountFactory.calls(0)); }
@Test public void testCacheOfSize2() throws Exception { FixedSizeMRUCachingFactory<Integer, Integer> cache = new FixedSizeMRUCachingFactory<Integer, Integer>(callCountFactory, 2); assertEquals(0, callCountFactory.calls(0)); cache.get(0); assertEquals(1, callCountFactory.calls(0)); assertEquals(0, callCountFactory.calls(1)); cache.get(1); assertEquals(1, callCountFactory.calls(1)); assertEquals(0, callCountFactory.calls(2)); cache.get(2); assertEquals(1, callCountFactory.calls(2)); assertEquals(1, callCountFactory.calls(1)); cache.get(1); assertEquals(1, callCountFactory.calls(1)); assertEquals(1, callCountFactory.calls(0)); cache.get(0); assertEquals(2, callCountFactory.calls(0)); }
@Test public void testCacheOfSize3() throws Exception { FixedSizeMRUCachingFactory<Integer, Integer> cache = new FixedSizeMRUCachingFactory<Integer, Integer>(callCountFactory, 3); cache.get(1); cache.get(0); cache.get(2); assertEquals(1, callCountFactory.calls(0)); assertEquals(1, callCountFactory.calls(1)); assertEquals(1, callCountFactory.calls(2)); cache.get(3); cache.get(0); cache.get(2); cache.get(1); assertEquals(1, callCountFactory.calls(0)); assertEquals(2, callCountFactory.calls(1)); assertEquals(1, callCountFactory.calls(2)); assertEquals(1, callCountFactory.calls(3)); }