コード例 #1
0
  @Test(expected = ServiceException.class)
  public void shouldThrowServiceExceptionIfConnectorExceptionThrownWhenReceivingMessages()
      throws ConnectorException, ServiceException, TransformException {
    // given
    given(connector.receiveMessages(MessagesService.WHERE_ARE_YOU_SUBJECT))
        .willThrow(new ConnectorException(""));

    // when
    service.receiveMessages();

    // then
    // throws exception
  }
コード例 #2
0
  @Test(expected = TransformException.class)
  public void shouldThrowTransformExceptionIfTransformExceptionThrownWhenReceivingMessages()
      throws ConnectorException, ServiceException, TransformException {
    // given
    Set<Object> messages = new HashSet<Object>();
    messages.add(message1);
    given(connector.receiveMessages(MessagesService.WHERE_ARE_YOU_SUBJECT)).willReturn(messages);
    given(messageTransformer.transform(any(String.class))).willThrow(new TransformException(""));

    // when
    service.receiveMessages();

    // then
    // throws exception
  }
コード例 #3
0
  @Test
  public void shouldReceiveMessagesSuccessfully()
      throws ConnectorException, ServiceException, TransformException {
    // given
    Set<Object> messages = new HashSet<Object>();
    messages.add(message1);
    messages.add(message2);
    given(connector.receiveMessages(MessagesService.WHERE_ARE_YOU_SUBJECT)).willReturn(messages);
    given(messageTransformer.transform(any(String.class)))
        .willReturn(ownerResponseMessage)
        .willReturn(ownerLocationDataMessage);

    // when
    Set<GenericMessage> messagesReceived = service.receiveMessages();

    // then
    assertEquals(2, messagesReceived.size());
  }