@Test public void properMessageIsConstructed_forInitializeAgentResponse() { assertThat(new InitializeAgent(TestsMode.RUN, true, 100).toMessage()).isEqualTo( "{\"operating_mode\":{\"mode\":\"RUN\",\"wait_for_start_allowance\":true,\"max_lenght\":100}}"); assertThat(new InitializeAgent(TestsMode.RUN, false, 200).toMessage()).isEqualTo( "{\"operating_mode\":{\"mode\":\"RUN\",\"wait_for_start_allowance\":false,\"max_lenght\":200}}"); assertThat(new InitializeAgent(TestsMode.DEBUG, true, 300).toMessage()).isEqualTo( "{\"operating_mode\":{\"mode\":\"DEBUG\",\"wait_for_start_allowance\":true,\"max_lenght\":300}}"); assertThat(new InitializeAgent(TestsMode.DEBUG, false, 400).toMessage()).isEqualTo( "{\"operating_mode\":{\"mode\":\"DEBUG\",\"wait_for_start_allowance\":false,\"max_lenght\":400}}"); }
@Override public String toMessage() throws ResponseException { try { final Builder<String, Object> argsBuilder = ImmutableMap.<String, Object> builder() .put("mode", mode.name()) .put("wait_for_start_allowance", agentShouldWaitForSignal); if (maxValueLenght >= 0) { argsBuilder.put("max_lenght", maxValueLenght); } final Map<String, Object> value = ImmutableMap.of("operating_mode", argsBuilder.build()); return mapper.writeValueAsString(value); } catch (final IOException e) { throw new ResponseException("Unable to serialize initialize agent response arguments to json", e); } }
InitializeAgent implements ServerResponse { @Override public String toMessage() throws ResponseException { try { final Builder<String, Object> argsBuilder = ImmutableMap.<String, Object> builder() .put("mode", mode.name()) .put("wait_for_start_allowance", agentShouldWaitForSignal); if (maxValueLenght >= 0) { argsBuilder.put("max_lenght", maxValueLenght); } final Map<String, Object> value = ImmutableMap.of("operating_mode", argsBuilder.build()); return mapper.writeValueAsString(value); } catch (final IOException e) { throw new ResponseException("Unable to serialize initialize agent response arguments to json", e); } } }
InitializeAgent implements ServerResponse { @Override public String toMessage() throws ResponseException { try { final Builder<String, Object> argsBuilder = ImmutableMap.<String, Object> builder() .put("mode", mode.name()) .put("wait_for_start_allowance", agentShouldWaitForSignal); if (maxValueLenght >= 0) { argsBuilder.put("max_lenght", maxValueLenght); } final Map<String, Object> value = ImmutableMap.of("operating_mode", argsBuilder.build()); return mapper.writeValueAsString(value); } catch (final IOException e) { throw new ResponseException("Unable to serialize initialize agent response arguments to json", e); } } InitializeAgent(final TestsMode mode, final boolean agentShouldWaitForSignal, final int maxValueLenght); @VisibleForTesting  InitializeAgent(final ObjectMapper mapper, final TestsMode mode, final boolean agentShouldWaitForSignal,
            final int maxValueLenght); }
InitializeAgent implements ServerResponse { @Override public String toMessage() throws ResponseException { try { final Builder<String, Object> argsBuilder = ImmutableMap.<String, Object> builder() .put("mode", mode.name()) .put("wait_for_start_allowance", agentShouldWaitForSignal); if (maxValueLenght >= 0) { argsBuilder.put("max_lenght", maxValueLenght); } final Map<String, Object> value = ImmutableMap.of("operating_mode", argsBuilder.build()); return mapper.writeValueAsString(value); } catch (final IOException e) { throw new ResponseException("Unable to serialize initialize agent response arguments to json", e); } } InitializeAgent(final TestsMode mode, final boolean agentShouldWaitForSignal, final int maxValueLenght); @VisibleForTesting  InitializeAgent(final ObjectMapper mapper, final TestsMode mode, final boolean agentShouldWaitForSignal,
            final int maxValueLenght); @Override String toMessage(); }
InitializeAgent implements ServerResponse { @Override public String toMessage() throws ResponseException { try { final Builder<String, Object> argsBuilder = ImmutableMap.<String, Object> builder() .put("mode", mode.name()) .put("wait_for_start_allowance", agentShouldWaitForSignal); if (maxValueLenght >= 0) { argsBuilder.put("max_lenght", maxValueLenght); } final Map<String, Object> value = ImmutableMap.of("operating_mode", argsBuilder.build()); return mapper.writeValueAsString(value); } catch (final IOException e) { throw new ResponseException("Unable to serialize initialize agent response arguments to json", e); } } InitializeAgent(final TestsMode mode, final boolean agentShouldWaitForSignal, final int maxValueLenght); @VisibleForTesting  InitializeAgent(final ObjectMapper mapper, final TestsMode mode, final boolean agentShouldWaitForSignal,
            final int maxValueLenght); @Override String toMessage();  }