### Question:
CachedRepository implements DataRepository { @Override public <T> T get(String key, Class<T> type) throws IOException { try { return type.cast(objCache.get(new Pair(key, type))); } catch (ExecutionException e) { LOG.warn("Error loading object from cache", e); return reg.get(key, type); } } CachedRepository(DataRepository reg);  CachedRepository(DataRepository reg, final int cacheSize); Iterable<Handle<?>> query(Filter<? super Handle<?>> filter); @Override T get(String key, Class<T> type); @Override void close();  }### Answer:
@Test public void testWorkspace() throws IOException { Workspace ws = createMock(Workspace.class); DataRepository reg = createMock(DataRepository.class); expect(reg.get("foo", Workspace.class)).andReturn(ws).once(); replay(ws, reg); CachedRepository cached = new CachedRepository(reg); assertNotNull(cached.get("foo", Workspace.class)); assertNotNull(cached.get("foo", Workspace.class)); assertNotNull(cached.get("foo", Workspace.class)); verify(ws, reg); }
@Test public void testLayer() throws IOException { Dataset l = createMock(Dataset.class); Workspace ws = createMock(Workspace.class); expect(ws.get("bar")).andReturn(l).once(); DataRepository reg = createMock(DataRepository.class); expect(reg.get("foo", Workspace.class)).andReturn(ws).once(); replay(l, ws, reg); CachedRepository cached = new CachedRepository(reg); assertNotNull(((Workspace)cached.get("foo", Workspace.class)).get("bar")); assertNotNull(((Workspace)cached.get("foo", Workspace.class)).get("bar")); assertNotNull(((Workspace)cached.get("foo", Workspace.class)).get("bar")); verify(l, ws, reg); }