public void testSetDuringDependencyNodeOperations() {
    DoubleObjectStorage storage = mock(DoubleObjectStorage.class);

    when(storage.load(42d)).thenReturn(Storage.UNDEFINED, '*');

    DoubleCharacterCalculatable calculatable = mock(DoubleCharacterCalculatable.class);
    MxResource r = mock(MxResource.class);
    when(calculatable.calculate("123", 42d)).thenThrow(new ResourceOccupied(r));

    DoubleCharacterCache cache =
        (DoubleCharacterCache)
            Wrapping.getFactory(
                    new Signature(double.class, Object.class),
                    new Signature(double.class, char.class),
                    false)
                .wrap("123", calculatable, storage, new MutableStatisticsImpl());
    cache.setDependencyNode(DependencyTracker.DUMMY_NODE);

    assert cache.getStatistics().getHits() == 0;
    assert cache.getStatistics().getMisses() == 0;

    assert cache.getOrCreate(42d) == '*';

    assert cache.getStatistics().getHits() == 1;
    assert cache.getStatistics().getMisses() == 0;

    verify(storage, atLeast(2)).load(42d);
    verifyNoMoreInteractions(storage);
    verify(calculatable).calculate("123", 42d);
    verifyNoMoreInteractions(calculatable);
  }
  public void testClear() {
    DoubleObjectStorage storage = mock(DoubleObjectStorage.class);

    DoubleCharacterCache cache =
        (DoubleCharacterCache)
            Wrapping.getFactory(
                    new Signature(double.class, Object.class),
                    new Signature(double.class, char.class),
                    false)
                .wrap("123", CALCULATABLE, storage, new MutableStatisticsImpl());
    cache.setDependencyNode(DependencyTracker.DUMMY_NODE);

    cache.clear();

    verify(storage).clear();
    verifyNoMoreInteractions(storage);
  }
  public void testResetStat() {
    DoubleObjectStorage storage = mock(DoubleObjectStorage.class);

    when(storage.load(42d)).thenReturn(Storage.UNDEFINED);

    DoubleCharacterCache cache =
        (DoubleCharacterCache)
            Wrapping.getFactory(
                    new Signature(double.class, Object.class),
                    new Signature(double.class, char.class),
                    false)
                .wrap("123", CALCULATABLE, storage, new MutableStatisticsImpl());
    cache.setDependencyNode(DependencyTracker.DUMMY_NODE);

    assert cache.getStatistics().getHits() == 0;
    assert cache.getStatistics().getMisses() == 0;

    assert cache.getOrCreate(42d) == '*';

    assert cache.getStatistics().getHits() == 0;
    assert cache.getStatistics().getMisses() == 1;

    cache.getStatistics().reset();

    assert cache.getStatistics().getHits() == 0;
    assert cache.getStatistics().getMisses() == 0;

    verify(storage, atLeast(1)).load(42d);
    verify(storage).save(42d, '*');
    verifyNoMoreInteractions(storage);
  }