public void testHit() {
    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);

    when(storage.load(42d)).thenReturn('*');
    when(storage.size()).thenReturn(1);

    assert cache.getSize() == 1;
    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).size();
    verify(storage, atLeast(2)).load(42d);
    verifyNoMoreInteractions(storage);
  }
  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);
  }