GetAsyncOperationActor { public void getOperation(final GetAsyncOperationMessage message) throws GetAsyncOperationActorException { try { String token = message.getToken(); IObject asyncOperation = collection.getAsyncOperation(token); if (asyncOperation == null) { throw new GetAsyncOperationActorException("Asynchronous operation by token " + token + " is null"); } message.setAsyncOperation(asyncOperation); } catch (ChangeValueException | GetAsyncOperationException | ReadValueException e) { throw new GetAsyncOperationActorException("Can't get async operation by token.", e); } } GetAsyncOperationActor(final IObject params); void getOperation(final GetAsyncOperationMessage message);  }
@Test public void ShouldReadOperationByToken() throws ReadValueException, GetAsyncOperationActorException, GetAsyncOperationException, ChangeValueException { String token = "token"; when(message.getToken()).thenReturn(token); IObject asyncOperation = mock(IObject.class); when(collection.getAsyncOperation(token)).thenReturn(asyncOperation); actor.getOperation(message); verify(message).setAsyncOperation(asyncOperation); }
@Test(expected = GetAsyncOperationActorException.class) public void ShouldThrowException_When_AsyncOperationIsNull() throws ReadValueException, GetAsyncOperationActorException, GetAsyncOperationException, ChangeValueException { when(collection.getAsyncOperation(anyString())).thenReturn(null); actor.getOperation(message); fail(); }