@Test
  public void evictedTransactionsAreSentToServer() throws Exception {
    api_cache.setReportExpirationInterval(5L);
    api_cache.report(createTransactionData());
    Thread.sleep(800L);

    verify(sender).sendPostToServer(SERVER_URL, RESPONSE_DATA);
  }
 @Test
 public void multipleTransactionsWithSameTimestampAreReportedCorrectly() throws Exception {
   api_cache.setReportExpirationInterval(50L);
   api_cache.report(createTransactionData());
   api_cache.report(createTransactionData());
   Thread.sleep(800L);
   verify(sender).sendPostToServer(SERVER_URL, RESPONSE_MULTIPLE_TRANSACTION);
 }
  @Test
  public void multipleReportsTransactionsAreSentToServerAsOneMessage() throws Exception {
    api_cache.setReportExpirationInterval(5L);
    api_cache.report(createTransactionData());
    api_cache.report(createSecondSetOfTransactionData());
    Thread.sleep(800L);

    verify(sender).sendPostToServer(SERVER_URL, MULTIPLE_RESPONSE_DATA);
  }
  @Test
  public void isCorrectExpirationTimeSetForAppId() throws Exception {
    api_cache.report(createTransactionData());

    long time1 = api_cache.getTransactionExpirationTimeFor("bce4c8f4");
    assertEquals(
        "T1 had wrong expiration time", api_cache.getCurrentResponseExpirationTime(), time1);
    long time2 = api_cache.getTransactionExpirationTimeFor("bad7e480");
    assertEquals(
        "T2 had wrong expiration time", api_cache.getCurrentResponseExpirationTime(), time2);
  }
  @Test
  public void reportTransactions() throws Exception {

    api_cache.report(createTransactionData());

    ApiTransaction[] t1 = api_cache.getTransactionFor("bce4c8f4", "2009-01-01 14:23:08");
    assertNotNull("Transaction 1 was not stored in cache", t1);

    ApiTransaction[] t2 = api_cache.getTransactionFor("bad7e480", "2009-01-01 18:11:59");
    assertNotNull("Transaction 2 was not stored in cache", t2);
  }
  @Test
  public void transactionAreExpiredAtCorrectTime() throws Exception {
    api_cache.setReportExpirationInterval(5L);
    api_cache.report(createTransactionData());
    Thread.sleep(1000L);

    ApiTransaction[] t1 = api_cache.getTransactionFor("bce4c8f4", "2009-01-01 14:23:08");
    assertNull("Transaction 1 was still in cache", t1);

    ApiTransaction[] t2 = api_cache.getTransactionFor("bad7e480", "2009-01-01 18:11:59");
    assertNull("Transaction 2 was was still in cache", t2);
  }
  @Test
  public void cacheEvictionTimeIsBeingSetCorrectly() throws Exception {
    api_cache.setReportExpirationInterval(200L);
    long currentTime = api_cache.getCurrentResponseExpirationTime();
    Thread.sleep(550L);
    long newTime = api_cache.getCurrentResponseExpirationTime();

    SimpleDateFormat df = new SimpleDateFormat("yyyy MM dd hh mm ss S");

    log.info("Current time: " + df.format(currentTime));
    log.info("    New time: " + df.format(newTime));
    assertTrue("ExpirationTime was not incremented correctly", newTime == (currentTime + 200L));
  }