コード例 #1
0
  @Test
  public void serializeHandlesException() throws IOException {
    // given
    thrown.expect(RuntimeException.class);
    thrown.expectMessage(
        "Exception while serializing verification to JSON with value {"
            + System.getProperty("line.separator")
            + "  \"httpRequest\" : { },"
            + System.getProperty("line.separator")
            + "  \"times\" : {"
            + System.getProperty("line.separator")
            + "    \"count\" : 1,"
            + System.getProperty("line.separator")
            + "    \"exact\" : false"
            + System.getProperty("line.separator")
            + "  }"
            + System.getProperty("line.separator")
            + "}");
    // and
    when(objectMapper.writerWithDefaultPrettyPrinter()).thenReturn(objectWriter);
    when(objectWriter.writeValueAsString(any(VerificationDTO.class)))
        .thenThrow(new RuntimeException("TEST EXCEPTION"));

    // when
    verificationSerializer.serialize(new Verification());
  }
コード例 #2
0
  @Test
  public void deserializeHandleException() throws IOException {
    // given
    thrown.expect(RuntimeException.class);
    thrown.expectMessage("Exception while parsing response [requestBytes] for verification");
    // and
    when(objectMapper.readValue(eq("requestBytes"), same(VerificationDTO.class)))
        .thenThrow(new IOException("TEST EXCEPTION"));

    // when
    verificationSerializer.deserialize("requestBytes");
  }
コード例 #3
0
  @Test
  public void serialize() throws IOException {
    // given
    when(objectMapper.writerWithDefaultPrettyPrinter()).thenReturn(objectWriter);

    // when
    verificationSerializer.serialize(fullVerification);

    // then
    verify(objectMapper).writerWithDefaultPrettyPrinter();
    verify(objectWriter).writeValueAsString(fullVerificationDTO);
  }
コード例 #4
0
  @Test
  public void deserialize() throws IOException {
    // given
    when(objectMapper.readValue(eq("requestBytes"), same(VerificationDTO.class)))
        .thenReturn(fullVerificationDTO);

    // when
    Verification verification = verificationSerializer.deserialize("requestBytes");

    // then
    assertEquals(fullVerification, verification);
  }