StagingActionMessages { public String getMessageForAction(final StagingAction action) { checkNotNull(action); if (!Strings.isNullOrEmpty(stagingDescription)) { return stagingDescription; } if (stagingDescriptions.containsKey(action)) { return stagingDescriptions.get(action); } return defaultDescription; } StagingActionMessages(final String stagingDescription,
                               final Map<StagingAction, String> stagingDescriptions, final String defaultDescription); String getMessageForAction(final StagingAction action);  }
@Test(expected = NullPointerException.class) public void getMessageForActionNpe() { final StagingActionMessages subject = new StagingActionMessages(null, Collections.<StagingAction, String>emptyMap(), "default"); subject.getMessageForAction(null); }
@Test public void takesAll() { final StagingActionMessages subject = new StagingActionMessages("takes all", Collections.<StagingAction, String>emptyMap(), "default"); assertThat(subject.getMessageForAction(StagingAction.DROP), equalTo("takes all")); }
@Test public void usualUsecase() { final HashMap<StagingAction, String> messages = new HashMap<StagingAction, String>(); messages.put(StagingAction.START, StagingAction.START.name()); messages.put(StagingAction.FINISH, StagingAction.FINISH.name()); final StagingActionMessages subject = new StagingActionMessages(null, messages, "default"); assertThat(subject.getMessageForAction(StagingAction.START), equalTo(StagingAction.START.name())); assertThat(subject.getMessageForAction(StagingAction.FINISH), equalTo(StagingAction.FINISH.name())); assertThat(subject.getMessageForAction(StagingAction.DROP), equalTo("default")); assertThat(subject.getMessageForAction(StagingAction.PROMOTE), equalTo("default")); assertThat(subject.getMessageForAction(StagingAction.RELEASE), equalTo("default")); }