@Test public void shouldConstructExecutionResultFromSuccessfulExecutionResponse() { GoPluginApiResponse response = mock(GoPluginApiResponse.class); when(response.responseBody()).thenReturn("{\"success\":true,\"message\":\"message1\"}"); ExecutionResult result = new JsonBasedTaskExtensionHandler_V1().toExecutionResult(response.responseBody()); assertThat(result.isSuccessful(), is(true)); assertThat(result.getMessagesForDisplay(), is("message1")); }
@Test public void shouldConstructExecutionResultFromFailureExecutionResponse() { GoPluginApiResponse response = mock(GoPluginApiResponse.class); when(response.responseBody()).thenReturn("{\"success\":false,\"message\":\"error1\"}"); ExecutionResult result = new JsonBasedTaskExtensionHandler_V1().toExecutionResult(response.responseBody()); assertThat(result.isSuccessful(), is(false)); assertThat(result.getMessagesForDisplay(), is("error1")); }
String json1 = "{}"; try { new JsonBasedTaskExtensionHandler_V1().toExecutionResult(json1); fail("should throw exception"); } catch (Exception e) { new JsonBasedTaskExtensionHandler_V1().toExecutionResult(json2); fail("should throw exception"); } catch (Exception e) { new JsonBasedTaskExtensionHandler_V1().toExecutionResult(json3); fail("should throw exception"); } catch (Exception e) { new JsonBasedTaskExtensionHandler_V1().toExecutionResult(json4); fail("should throw exception"); } catch (Exception e) {