RestartActionsFormatter { public String format() { StringBuilder builder = new StringBuilder(); for (RestartActions.Entry entry : actions.getEntries()) { builder.append("In cluster '" + entry.getClusterName() + "' of type '" + entry.getClusterType() + "':\n"); builder.append(" Restart services of type '" + entry.getServiceType() + "' because:\n"); int counter = 1; for (String message : entry.getMessages()) { builder.append(" " + counter++ + ") " + message + "\n"); } } return builder.toString(); } RestartActionsFormatter(RestartActions actions); String format();  }
@Test public void formatting_of_single_action() { RestartActions actions = new ConfigChangeActionsBuilder(). restart(CHANGE_MSG, CLUSTER, CLUSTER_TYPE, SERVICE_TYPE, SERVICE_NAME). build().getRestartActions(); assertThat(new RestartActionsFormatter(actions).format(), equalTo("In cluster 'foo' of type 'search':\n" + " Restart services of type 'searchnode' because:\n" + " 1) change\n")); }
@Test public void formatting_of_multiple_actions() { RestartActions actions = new ConfigChangeActionsBuilder(). restart(CHANGE_MSG, CLUSTER, CLUSTER_TYPE, SERVICE_TYPE, SERVICE_NAME). restart(CHANGE_MSG_2, CLUSTER, CLUSTER_TYPE, SERVICE_TYPE, SERVICE_NAME). restart(CHANGE_MSG, CLUSTER_2, CLUSTER_TYPE, SERVICE_TYPE, SERVICE_NAME). build().getRestartActions(); assertThat(new RestartActionsFormatter(actions).format(), equalTo("In cluster 'bar' of type 'search':\n" + " Restart services of type 'searchnode' because:\n" + " 1) change\n" + "In cluster 'foo' of type 'search':\n" + " Restart services of type 'searchnode' because:\n" + " 1) change\n" + " 2) other change\n")); }