CloseAsyncOperationActor { public void completeAsyncOp(final CloseAsyncOpMessage message) throws InvalidArgumentException { try { message.getOperationTokens().remove(message.getToken()); collection.complete(message.getOperation()); } catch (ReadValueException e) { throw new InvalidArgumentException("Can't read some of values in message", e); } catch (CompleteAsyncOperationException e) { throw new InvalidArgumentException("Can't close async operation with this parameters: " + message, e); } } CloseAsyncOperationActor(final IObject params); void completeAsyncOp(final CloseAsyncOpMessage message);  }
@Test public void MustCorrectCompleteAsyncOperation() throws ReadValueException, CompleteAsyncOperationException, InvalidArgumentException { String targetToken = "targetToken"; List<String> allTokens = mock(List.class); IObject operation = mock(IObject.class); CloseAsyncOpMessage message = mock(CloseAsyncOpMessage.class); when(message.getToken()).thenReturn(targetToken); when(message.getOperationTokens()).thenReturn(allTokens); when(message.getOperation()).thenReturn(operation); testActor.completeAsyncOp(message); verify(message).getToken(); verify(message).getOperationTokens(); verify(allTokens).remove(targetToken); verify(message).getOperation(); verify(targetCollection).complete(operation); }
@Test public void MustInCorrectCompleteAsyncOperationWhenMessageThrowReadValueException() throws ReadValueException { CloseAsyncOpMessage message = mock(CloseAsyncOpMessage.class); when(message.getToken()).thenThrow(new ReadValueException()); try { testActor.completeAsyncOp(message); } catch (InvalidArgumentException e) { verify(message).getToken(); return; } assertTrue("Must throw exception", false); }
@Test public void MustInCorrectCompleteAsyncOperationWhenCompleteCallInTargetCollectionThrowException() throws ReadValueException, CompleteAsyncOperationException { String targetToken = "targetToken"; List<String> allTokens = mock(List.class); IObject operation = mock(IObject.class); CloseAsyncOpMessage message = mock(CloseAsyncOpMessage.class); when(message.getToken()).thenReturn(targetToken); when(message.getOperationTokens()).thenReturn(allTokens); when(message.getOperation()).thenReturn(operation); doThrow(new CompleteAsyncOperationException("")).when(targetCollection).complete(operation); try { testActor.completeAsyncOp(message); } catch (InvalidArgumentException e) { verify(message).getToken(); verify(message).getOperationTokens(); verify(allTokens).remove(targetToken); verify(message).getOperation(); verify(targetCollection).complete(operation); return; } assertTrue("Must throw exception", false); }