RegionNameValidation { public static void validate(String name) { validate(name, new InternalRegionArguments()); }  static void validate(String name);  }
@Test public void nullThrows() { assertThatThrownBy(() -> validate(null)).isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("name cannot be null"); }
@Test public void emptyThrows() { assertThatThrownBy(() -> validate("")).isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("name cannot be empty"); }
@Test public void endingWithSeparatorThrows() { assertThatThrownBy(() -> validate("foo" + SEPARATOR)) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining(String.format("name cannot contain the separator ' %s '", SEPARATOR)); }
@Test public void startingWithSeparatorThrows() { assertThatThrownBy(() -> validate(SEPARATOR + "foo")) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining(String.format("name cannot contain the separator ' %s '", SEPARATOR)); }
@Test public void containingSeparatorThrows() { assertThatThrownBy(() -> validate("foo" + SEPARATOR + "bar")) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining(String.format("name cannot contain the separator ' %s '", SEPARATOR)); }
@Test public void startingWithDoubleUnderscoreThrows() { assertThatThrownBy(() -> validate("__InvalidInternalRegionName")) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("Region names may not begin with a double-underscore"); }
@Test public void startingWithDoubleUnderscoreIsOkForInternalRegion() { InternalRegionArguments internalRegionArguments = new InternalRegionArguments(); internalRegionArguments.setInternalRegion(true); assertThatCode(() -> validate("__ValidInternalRegionName", internalRegionArguments)) .doesNotThrowAnyException(); }
@Test public void startingWithUnderscoreIsOk() { validate("_validRegionName"); }
@Test public void containingUnderscoreIsOk() { validate("valid_regionName"); }
@Test public void containingMultipleUnderscoresIsOk() { validate("valid_region_name"); }
@Test public void endingWithUnderscoreIsOk() { validate("validRegionName_"); }
@Test public void containingDoubleUnderscoreIsOk() { validate("valid__regionName"); }
@Test public void endingWithDoubleUnderscoreIsOk() { validate("validRegionName__"); }
@Test public void startingWithHyphenIsOk() { validate("-validRegionName"); }
@Test public void startingWithDoubleHyphenIsOk() { validate("--validRegionName"); }
@Test public void containingHyphenIsOk() { validate("valid-regionName"); }
@Test public void containingDoubleHyphenIsOk() { validate("valid--regionName"); }
@Test public void endingWithHyphenIsOk() { validate("validRegionName-"); }
@Test public void startingAndEndingWithSquareBracketsIsOk() { validate("[validRegionName]"); }
@Test public void containingSquareBracketsIsOk() { validate("validRegion[EMPTY]Name"); }
@Test public void startingWithCaretIsOk() { validate("^validRegionName"); }
@Test public void containingCaretIsOk() { validate("validRegion^Name"); }
@Test public void endingWithCaretIsOk() { validate("validRegionName^"); }
@Test public void startingWithBackquoteIsOk() { validate("`validRegionName"); }
@Test public void containingBackquoteIsOk() { validate("validRegion`Name"); }
@Test public void endingWithBackquoteIsOk() { validate("validRegionName`"); }
@Test public void nameWithDot() throws Exception { validate("valid.valid"); }
@Test public void endingWithDoubleHyphenIsOk() { validate("validRegionName--"); }