コード例 #1
0
  @Test
  public void shouldThrowException_WhenOperatingWithNoKey() {
    when(coRepository.lock(noKey)).thenReturn(true);
    when(originalRepository.read(noKey)).thenReturn(Item.withNoValue(noKey));
    sut = new CoRepositoryClient(coRepository, originalRepository);

    try {
      when(coRepository.selectAsInt(noKey)).thenReturn(Item.withNoValue(noKey));
      sut.selectAsInt(noKey);
      fail();
    } catch (NonExistentKeyException e) {
    }

    try {
      sut.update(new Item(noKey, "anyValue"));
      fail();
    } catch (NonExistentKeyException e) {
    }

    try {
      sut.increase(noKey);
      fail();
    } catch (NonExistentKeyException e) {
    }

    try {
      sut.decrease(noKey);
      fail();
    } catch (NonExistentKeyException e) {
    }
  }
コード例 #2
0
  @Test
  public void canIncreaseValue() {
    when(originalRepository.read(key)).thenReturn(integerItem);
    sut = new CoRepositoryClient(coRepository, originalRepository, keyUpdateTime, 1);

    sut.increase(key);

    verify(coRepository).increase(key);
    verify(keyUpdateTime, times(2)).notifyUpdated(Mockito.eq(key), Mockito.anyLong());
  }