예제 #1
0
  @Test(expected = NotFoundException.class)
  public void updateWhenContactIsNotFound() throws NotFoundException {
    when(redisTemplateMock.opsForSet()).thenReturn(setOperationsMock);
    when(setOperationsMock.isMember(RedisContactService.KEY_CONTACT_SET, CONTACT_KEY))
        .thenReturn(false);

    Contact updated = ContactTestUtil.createModel(CONTACT_ID);
    service.update(updated);

    verifyThatExistCheckForContactIsDone(CONTACT_KEY);

    verifyNoMoreInteractions(redisTemplateMock, setOperationsMock);
    verifyZeroInteractions(boundHashOperationsMock, contactIdCounterMock);
  }
예제 #2
0
  @Test
  public void update() throws NotFoundException {
    when(redisTemplateMock.boundHashOps(CONTACT_KEY)).thenReturn(boundHashOperationsMock);
    when(redisTemplateMock.opsForSet()).thenReturn(setOperationsMock);
    when(setOperationsMock.isMember(RedisContactService.KEY_CONTACT_SET, CONTACT_KEY))
        .thenReturn(true);

    Contact updated = ContactTestUtil.createModel(CONTACT_ID);
    service.update(updated);

    verify(redisTemplateMock, times(1)).boundHashOps(CONTACT_KEY);
    verifyThatContactWasPersisted(CONTACT_ID, updated);

    verifyThatExistCheckForContactIsDone(CONTACT_KEY);

    verifyNoMoreInteractions(boundHashOperationsMock, redisTemplateMock);
    verifyZeroInteractions(contactIdCounterMock, setOperationsMock);
  }
예제 #3
0
  @Test
  public void add() {
    when(contactIdCounterMock.incrementAndGet()).thenReturn(CONTACT_ID);
    when(redisTemplateMock.boundHashOps(CONTACT_KEY)).thenReturn(boundHashOperationsMock);
    when(redisTemplateMock.opsForSet()).thenReturn(setOperationsMock);

    Contact added = ContactTestUtil.createModel();
    Contact actual = service.add(added);

    verify(contactIdCounterMock, times(1)).incrementAndGet();
    verifyNoMoreInteractions(contactIdCounterMock);

    verify(redisTemplateMock, times(1)).boundHashOps(CONTACT_KEY);
    verifyThatContactWasPersisted(CONTACT_ID, added);

    verify(redisTemplateMock, times(1)).opsForSet();
    verify(setOperationsMock, times(1)).add(RedisContactService.KEY_CONTACT_SET, CONTACT_KEY);
    verifyNoMoreInteractions(boundHashOperationsMock, setOperationsMock, redisTemplateMock);

    assertEquals(added, actual);
  }