### Question:
JacksonFromJsonFormat implements FromJsonFormat<SagaDefinition> { @Segment(name = "fromJson", category = "application", library = "kamon") @Override public SagaDefinition fromJson(String requestJson) { try { JsonSagaDefinition definition = objectMapper.readValue(requestJson, JsonSagaDefinition.class); for (JsonSagaRequest request : definition.requests()) { request.with(transportFactory); } return definition; } catch (IOException e) { throw new SagaException("Failed to interpret JSON " + requestJson, e); } } JacksonFromJsonFormat(TransportFactory transportFactory); @Segment(name = "fromJson", category = "application", library = "kamon") @Override SagaDefinition fromJson(String requestJson);  }### Answer:
@Test public void addTransportToDeserializedRequests() throws IOException { SagaRequest[] sagaRequests = format.fromJson(requests).requests(); assertThat(collect(sagaRequests, getRequestId), contains("request-aaa", "request-bbb", "request-ccc")); assertThat(collect(sagaRequests, getRequestServiceName), contains("aaa", "bbb", "ccc")); assertThat(collect(sagaRequests, getRequestType), Matchers .contains(Operation.TYPE_REST, Operation.TYPE_REST, Operation.TYPE_REST)); assertThat(collect(sagaRequests, getCompensationRetries), contains(3, 4, 5)); assertThat(collect(sagaRequests, getFallbackType), Matchers .contains(Operation.TYPE_REST, Operation.TYPE_REST, Operation.TYPE_REST)); SagaResponse response = sagaRequests[0].transaction().send("aaa"); assertThat(response, is(response11)); response = sagaRequests[0].compensation().send("aaa"); assertThat(response, is(response12)); response = sagaRequests[0].fallback().send("aaa"); assertThat(response, is(response13)); assertThat(sagaRequests[0].parents().length, is(0)); response = sagaRequests[1].transaction().send("bbb"); assertThat(response, is(response21)); response = sagaRequests[1].compensation().send("bbb"); assertThat(response, is(response22)); response = sagaRequests[1].fallback().send("bbb"); assertThat(response, is(response23)); assertThat(sagaRequests[1].parents().length, is(0)); response = sagaRequests[2].transaction().send("ccc"); assertThat(response, is(response31)); response = sagaRequests[2].compensation().send("ccc"); assertThat(response, is(response32)); response = sagaRequests[2].fallback().send("ccc"); assertThat(response, is(response33)); assertArrayEquals(new String[] {"request-aaa", "request-bbb"}, sagaRequests[2].parents()); }
@Test public void blowsUpWhenJsonIsInvalid() throws IOException { String invalidRequest = "invalid-json"; try { format.fromJson(invalidRequest); AssertUtils.expectFailing(SagaException.class); } catch (SagaException e) { assertThat(e.getMessage(), is("Failed to interpret JSON invalid-json")); } }