SmithyPattern { public static Builder builder() { return new Builder(); } protected  SmithyPattern(Builder builder); final List<Segment> getSegments(); final List<Segment> getLabels(); final Optional<Segment> getLabel(String name); final Optional<Segment> getGreedyLabel(); @Override String toString(); @Override boolean equals(Object other); @Override int hashCode(); static Builder builder();  }
@Test public void labelsMustSpanEntireSegment() { Throwable thrown = Assertions.assertThrows(InvalidPatternException.class, () -> { String target = "/{foo}baz"; SmithyPattern.builder() .segments(parser(target)) .pattern(target) .build(); }); assertThat(thrown.getMessage(), containsString("Literal segments must not contain")); }
@Test public void labelsMustNotIncludeEmptySegments() { Throwable thrown = Assertions.assertThrows(InvalidPatternException.class, () -> { String target = " SmithyPattern.builder() .segments(parser(target)) .pattern(target) .build(); }); assertThat(thrown.getMessage(), containsString("Segments must not be empty")); }
@Test public void labelsMustNotBeRepeated() { Throwable thrown = Assertions.assertThrows(InvalidPatternException.class, () -> { String target = "/{foo}/{Foo}"; SmithyPattern.builder() .segments(parser(target)) .pattern(target) .build(); }); assertThat(thrown.getMessage(), containsString("Label `Foo` is defined more than once")); }
@Test public void restrictsGreedyLabels() { Throwable thrown = Assertions.assertThrows(InvalidPatternException.class, () -> { String target = "/foo/{baz+}"; SmithyPattern.builder() .allowsGreedyLabels(false) .segments(parser(target)) .pattern(target) .build(); }); assertThat(thrown.getMessage(), containsString("Pattern must not contain a greedy label")); }
@Test public void noMoreThanOneGreedyLabel() { Throwable thrown = Assertions.assertThrows(InvalidPatternException.class, () -> { String target = "/{foo+}/{baz+}"; SmithyPattern.builder() .segments(parser(target)) .pattern(target) .build(); }); assertThat(thrown.getMessage(), containsString("At most one greedy label segment may exist in a pattern")); }
@Test public void greedyLabelsMustBeLastLabelInPattern() { Throwable thrown = Assertions.assertThrows(InvalidPatternException.class, () -> { String target = "/{foo+}/{baz}"; SmithyPattern.builder() .segments(parser(target)) .pattern(target) .build(); }); assertThat(thrown.getMessage(), containsString("A greedy label must be the last label in its pattern")); }
@Test public void noEmptyLabels() { Throwable thrown = Assertions.assertThrows(InvalidPatternException.class, () -> { String target = "/{}"; SmithyPattern.builder() .segments(parser(target)) .pattern(target) .build(); }); assertThat(thrown.getMessage(), containsString("Empty label declaration")); }
@Test public void labelsMustMatchRegex() { Throwable thrown = Assertions.assertThrows(InvalidPatternException.class, () -> { String target = "/{!}"; SmithyPattern.builder() .segments(parser(target)) .pattern(target) .build(); }); assertThat(thrown.getMessage(), containsString("Invalid label name")); }