### Question:
CreatedQueryLogicCacheBean { public boolean add(String queryId, String userId, QueryLogic<?> logic, Connector cxn) { Triple value = new Triple(userId, logic, cxn); long updateTime = System.currentTimeMillis(); return cache.putIfAbsent(new Pair<>(queryId, updateTime), value) == null; }  boolean add(String queryId, String userId, QueryLogic<?> logic, Connector cxn); Pair<QueryLogic<?>,Connector> poll(String id); Map<String,Pair<QueryLogic<?>,Connector>> snapshot(); Map<String,Pair<QueryLogic<?>,Connector>> entriesOlderThan(final Long now, final Long expiration); Pair<QueryLogic<?>,Connector> pollIfOwnedBy(String queryId, String userId); void clearQueryLogics(long currentTimeMs, long timeToLiveMs); @PreDestroy void shutdown();  }### Answer:
@Test public void testFirstInsertion() throws Exception { String queryId = "12345"; String userId = "me"; long timestamp = 1l; EasyMock.expect(System.currentTimeMillis()).andReturn(timestamp); PowerMock.replayAll(); boolean ret = qlCache.add(queryId, userId, queryLogic, conn); PowerMock.verifyAll(); Assert.assertTrue("Expected the cache add to return true", ret); }
@Test public void testDuplicateKeyInsertion() throws Exception { String queryId = "12345"; String userId = "me"; long timestamp = 1l; EasyMock.expect(System.currentTimeMillis()).andReturn(timestamp); PowerMock.replayAll(); boolean ret = qlCache.add(queryId, userId, queryLogic, conn); PowerMock.verifyAll(); Assert.assertTrue("Expected the cache add to return true", ret); Assert.assertEquals(1, internalCache.size()); PowerMock.resetAll(); long timestamp2 = 2l; EasyMock.expect(System.currentTimeMillis()).andReturn(timestamp2); PowerMock.replayAll(); ret = qlCache.add(queryId, userId, queryLogic, conn); PowerMock.verifyAll(); Assert.assertTrue("New timestamp should have caused duplicate entry", ret); Assert.assertEquals(2, internalCache.size()); }