ProtocolFactory { @SuppressWarnings({"squid:S1166"}) public static TopicPath newTopicPath(final String path) { checkNotNull(path, "path"); final LinkedList<String> parts = new LinkedList<>(Arrays.asList(path.split(TopicPath.PATH_DELIMITER))); try { final String namespace = parts.pop(); final String id = parts.pop(); final TopicPath.Group group = TopicPath.Group.forName(parts.pop()) .orElseThrow(() -> UnknownTopicPathException.newBuilder(path).build()); final TopicPath.Channel channel; switch (group) { case POLICIES: channel = TopicPath.Channel.NONE; break; case THINGS: channel = TopicPath.Channel.forName(parts.pop()) .orElseThrow(() -> UnknownTopicPathException.newBuilder(path).build()); break; default: throw UnknownTopicPathException.newBuilder(path).build(); } final TopicPath.Criterion criterion = TopicPath.Criterion.forName(parts.pop()) .orElseThrow(() -> UnknownTopicPathException.newBuilder(path).build()); switch (criterion) { case COMMANDS: case EVENTS: final TopicPath.Action action = TopicPath.Action.forName(parts.pop()) .orElseThrow(() -> UnknownTopicPathException.newBuilder(path).build()); return ImmutableTopicPath.of(namespace, id, group, channel, criterion, action); case SEARCH: final TopicPath.SearchAction searchAction = TopicPath.SearchAction.forName(parts.pop()) .orElseThrow(() -> UnknownTopicPathException.newBuilder(path).build()); return ImmutableTopicPath.of(namespace, id, group, channel, criterion, searchAction); case ERRORS: return ImmutableTopicPath.of(namespace, id, group, channel, criterion); case MESSAGES: case ACKS: final String subject = String.join(TopicPath.PATH_DELIMITER, parts); if (subject.isEmpty()) { return ImmutableTopicPath.of(namespace, id, group, channel, criterion); } else { return ImmutableTopicPath.of(namespace, id, group, channel, criterion, subject); } default: throw UnknownTopicPathException.newBuilder(path).build(); } } catch (final NoSuchElementException e) { throw UnknownTopicPathException.newBuilder(path).build(); } } private  ProtocolFactory(); static AdaptableBuilder newAdaptableBuilder(final TopicPath topicPath); static AdaptableBuilder newAdaptableBuilder(final Adaptable existingAdaptable); @Deprecated static AdaptableBuilder newAdaptableBuilder(final Adaptable existingAdaptable,
            final TopicPath overwriteTopicPath); static Adaptable setExtra(final Adaptable existingAdaptable, final JsonObject extra); static TopicPath emptyTopicPath(); @SuppressWarnings({"squid:S1166"}) static TopicPath newTopicPath(final String path); @Deprecated static TopicPathBuilder newTopicPathBuilder(final String thingId); static TopicPathBuilder newTopicPathBuilder(final ThingId thingId); static TopicPathBuilder newTopicPathBuilder(final NamespacedEntityId entityId); static TopicPathBuilder newTopicPathBuilder(final PolicyId policyId); static TopicPathBuilder newTopicPathBuilderFromNamespace(final String namespace); static Payload newPayload(final String jsonString); static Payload newPayload(final JsonObject jsonObject); static PayloadBuilder newPayloadBuilder(); static PayloadBuilder newPayloadBuilder(@Nullable final JsonPointer path); static DittoHeaders emptyHeaders(); static DittoHeaders newHeadersWithDittoContentType(final Map<String, String> headers); static DittoHeaders newHeaders(final Collection<Map.Entry<String, String>> headers); static DittoHeaders newHeaders(final JsonObject headersAsJson); static JsonifiableAdaptable wrapAsJsonifiableAdaptable(final Adaptable adaptable); static JsonifiableAdaptable jsonifiableAdaptableFromJson(final JsonObject adaptableAsJson);  }
@Test(expected = UnknownTopicPathException.class) public void testInvalidPolicyModifyTopicPathWithChannel() { ProtocolFactory.newTopicPath("namespace/id/policies/twin/commands/modify"); }
@Test(expected = UnknownTopicPathException.class) public void testInvalidGroup() { ProtocolFactory.newTopicPath("namespace/id/invalid/commands/modify"); }
@Test(expected = UnknownTopicPathException.class) public void testInvalidCriterion() { ProtocolFactory.newTopicPath("namespace/id/things/twin/invalid/modify"); }
@Test(expected = UnknownTopicPathException.class) public void testInvalidChannel() { ProtocolFactory.newTopicPath("namespace/id/things/invalid/commands/modify"); }
@Test(expected = UnknownTopicPathException.class) public void testInvalidAction() { ProtocolFactory.newTopicPath("namespace/id/things/twin/commands/invalid"); }
@Test(expected = UnknownTopicPathException.class) public void testMissingGroup() { ProtocolFactory.newTopicPath("namespace/id"); }
@Test(expected = UnknownTopicPathException.class) public void testMissingId() { ProtocolFactory.newTopicPath("namespace"); }
@Test(expected = UnknownTopicPathException.class) public void testMissingNamespace() { ProtocolFactory.newTopicPath(""); }
@Test(expected = NullPointerException.class) public void testNullPath() { ProtocolFactory.newTopicPath(null); }