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

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

    CharacterLongCalculatable calculatable = mock(CharacterLongCalculatable.class);
    MxResource r = mock(MxResource.class);
    when(calculatable.calculate("123", '*')).thenThrow(new ResourceOccupied(r));

    CharacterLongCache cache =
        (CharacterLongCache)
            Wrapping.getFactory(
                    new Signature(char.class, Object.class),
                    new Signature(char.class, long.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('*') == 42L;

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

    verify(storage, atLeast(2)).load('*');
    verifyNoMoreInteractions(storage);
    verify(calculatable).calculate("123", '*');
    verifyNoMoreInteractions(calculatable);
  }
  public void testClear() {
    CharacterObjectStorage storage = mock(CharacterObjectStorage.class);

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

    cache.clear();

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

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

    CharacterLongCache cache =
        (CharacterLongCache)
            Wrapping.getFactory(
                    new Signature(char.class, Object.class),
                    new Signature(char.class, long.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('*') == 42L;

    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('*');
    verify(storage).save('*', 42L);
    verifyNoMoreInteractions(storage);
  }