コード例 #1
0
  /**
   * check that the cache is immutable by changing the data passed in the constructor and returned
   * from methods.
   *
   * @throws TimeStampedCacheException
   */
  @Test
  public void testImmutable() throws TimeStampedCacheException {
    // setup
    List<AbsoluteDate> actuals;
    List<AbsoluteDate> expecteds = new ArrayList<AbsoluteDate>(data);
    AbsoluteDate different = date.shiftedBy(-50);

    // actions + verify

    // check constructor
    data.set(0, different);
    Assert.assertArrayEquals(cache.getAll().toArray(), expecteds.toArray());

    // check getAll
    actuals = cache.getAll();
    try {
      actuals.set(0, different);
    } catch (UnsupportedOperationException e) {
      // exception ok
    }
    Assert.assertArrayEquals(cache.getAll().toArray(), expecteds.toArray());

    // check getNeighbors
    actuals = cache.getNeighbors(date);
    try {
      actuals.set(0, different);
    } catch (UnsupportedOperationException e) {
      // exception ok
    }
    Assert.assertArrayEquals(cache.getAll().toArray(), expecteds.toArray());
  }
コード例 #2
0
  /** check {@link ImmutableTimeStampedCache#emptyCache()}. */
  @Test
  public void testEmptyCache() {
    // setup
    cache = ImmutableTimeStampedCache.emptyCache();

    // actions + verify
    try {
      cache.getNeighbors(date);
      Assert.fail("Expected Exception");
    } catch (TimeStampedCacheException e) {
      // expected
    }
    try {
      cache.getEarliest();
      Assert.fail("Expected Exception");
    } catch (IllegalStateException e) {
      // expected
    }
    try {
      cache.getLatest();
      Assert.fail("Expected Exception");
    } catch (IllegalStateException e) {
      // expected
    }
    Assert.assertEquals(cache.getAll().size(), 0);
    Assert.assertEquals(cache.getNeighborsSize(), 0);
  }
コード例 #3
0
 /** check {@link ImmutableTimeStampedCache#getAll()} */
 @Test
 public void testGetAll() {
   Assert.assertArrayEquals(cache.getAll().toArray(), data.toArray());
 }