ImmutableTopicPathPlaceholder implements TopicPathPlaceholder { @Override public Optional<String> resolve(final TopicPath topicPath, final String placeholder) { ConditionChecker.argumentNotEmpty(placeholder, "placeholder"); switch (placeholder) { case NAMESPACE_PLACEHOLDER: return Optional.of(topicPath.getNamespace()); case ENTITYID_PLACEHOLDER: return Optional.of(topicPath.getId()); case GROUP_PLACEHOLDER: return Optional.of(topicPath.getGroup().getName()); case CHANNEL_PLACEHOLDER: return Optional.of(topicPath.getChannel().getName()); case CRITERION_PLACEHOLDER: return Optional.of(topicPath.getCriterion().getName()); case ACTION_PLACEHOLDER: return topicPath.getAction().map(TopicPath.Action::getName); case SUBJECT_PLACEHOLDER: return topicPath.getSubject(); case ACTION_OR_SUBJECT_PLACEHOLDER: return Optional.ofNullable( topicPath.getSubject() .orElseGet(() -> topicPath.getAction().map(TopicPath.Action::getName).orElse(null) ) ); case FULL_PLACEHOLDER: return Optional.of(topicPath.getPath()); default: return Optional.empty(); } } private  ImmutableTopicPathPlaceholder(); @Override String getPrefix(); @Override List<String> getSupportedNames(); @Override boolean supports(final String name); @Override Optional<String> resolve(final TopicPath topicPath, final String placeholder); @Override String toString();  }
@Test public void testReplaceFull() { assertThat(UNDER_TEST.resolve(KNOWN_TOPIC_PATH, "full")).contains(KNOWN_TOPIC_PATH.getPath()); }
@Test public void testReplaceNamespace() { assertThat(UNDER_TEST.resolve(KNOWN_TOPIC_PATH, "namespace")).contains(KNOWN_NAMESPACE); }
@Test public void testReplaceEntityId() { assertThat(UNDER_TEST.resolve(KNOWN_TOPIC_PATH, "entityId")).contains(KNOWN_ID); }
@Test public void testReplaceChannel() { assertThat(UNDER_TEST.resolve(KNOWN_TOPIC_PATH, "channel")).contains(KNOWN_CHANNEL.getName()); }
@Test public void testReplaceGroup() { assertThat(UNDER_TEST.resolve(KNOWN_TOPIC_PATH, "group")).contains(KNOWN_GROUP.getName()); }
@Test public void testReplaceCriterion() { assertThat(UNDER_TEST.resolve(KNOWN_TOPIC_PATH, "criterion")).contains(KNOWN_CRITERION.getName()); }
@Test public void testReplaceAction() { assertThat(UNDER_TEST.resolve(KNOWN_TOPIC_PATH, "action")).contains(KNOWN_ACTION.getName()); }
@Test public void testReplaceSubjectEmpty() { assertThat(UNDER_TEST.resolve(KNOWN_TOPIC_PATH, "subject")).isEmpty(); }
@Test public void testReplaceSubject() { assertThat(UNDER_TEST.resolve(KNOWN_TOPIC_PATH_SUBJECT1, "subject")).contains(KNOWN_SUBJECT); }
@Test public void testReplaceWeirdSubject() { assertThat(UNDER_TEST.resolve(KNOWN_TOPIC_PATH_SUBJECT2, "subject")).contains(KNOWN_SUBJECT2); }
@Test public void testReplaceActionOrSubject() { assertThat(UNDER_TEST.resolve(KNOWN_TOPIC_PATH, "action-subject")).contains(KNOWN_ACTION.getName()); }
@Test public void testReplaceActionOrSubjectWithSubject() { assertThat(UNDER_TEST.resolve(KNOWN_TOPIC_PATH_SUBJECT1, "action-subject")).contains(KNOWN_SUBJECT); }
@Test public void testReplaceActionOrSubjectWithWeirdSubject() { assertThat(UNDER_TEST.resolve(KNOWN_TOPIC_PATH_SUBJECT2, "action-subject")).contains(KNOWN_SUBJECT2); }
@Test public void testUnknownPlaceholderReturnsEmpty() { assertThat(UNDER_TEST.resolve(KNOWN_TOPIC_PATH, "foo")).isEmpty(); }