public void testTimeout() {
   PendingCache<String, String> cache = new PendingCache<String, String>(10000, false);
   PendingElement<String> pending = cache.putPending("foo");
   long startTime = System.currentTimeMillis();
   assertNull("Null must be returned", cache.get("foo", 500));
   assertTrue("At least 500 ms must have passed", (System.currentTimeMillis() - startTime) >= 500);
 }
  public void testSetValue() {
    final String KEY = "foo";
    final String VALUE = "Hello world";
    PendingCache<String, String> cache = new PendingCache<String, String>(10000, false);
    final PendingElement<String> pending = cache.putPending(KEY);

    assertTrue("The key should be present", cache.containsKey(KEY));
    new Thread(
            new Runnable() {
              @Override
              public void run() {
                try {
                  Thread.sleep(500);
                } catch (InterruptedException e) {
                  fail("Interrupted");
                }
                pending.setValue(VALUE);
              }
            })
        .start();
    long startTime = System.currentTimeMillis();
    assertEquals("A (correct) response should be returned", VALUE, cache.get(KEY));
    assertTrue("At least 500 ms must have passed", (System.currentTimeMillis() - startTime) >= 500);
  }