@Test public void doesNotAllowCompanyNames() { IllegalArgumentException thrown = Assertions.assertThrows(IllegalArgumentException.class, () -> SdkServiceIdValidator.validateServiceId("AWS Foo")); assertThat(thrown.getMessage(), containsString("company names")); }
public static void validateServiceId(String serviceId) { if (isPreviouslyReleasedInvalidServiceId(serviceId)) { return; } List<String> messages = new ArrayList<>(); if (!validForPattern(serviceId)) { messages.add(String.format("Does not match the required pattern `%s`", SERVICE_ID_PATTERN.pattern())); } if (containsCompanyName(serviceId)) { messages.add(String.format( "Must not contain any of the following company names: [%s]", ValidationUtils.tickedList(COMPANY_NAMES))); } endsWithForbiddenWord(serviceId).ifPresent(suffix -> { messages.add(String.format("Must not case-insensitively end with `%s`", suffix)); }); if (serviceId.length() < 2 || serviceId.length() > 50) { messages.add("Must be between 2 and 50 characters long."); } if (!messages.isEmpty()) { throw new IllegalArgumentException(String.format( "Invalid SDK service ID value, `%s`: %s", serviceId, String.join(";", messages))); } }
SdkServiceIdValidator extends AbstractValidator { public static void validateServiceId(String serviceId) { if (isPreviouslyReleasedInvalidServiceId(serviceId)) { return; } List<String> messages = new ArrayList<>(); if (!validForPattern(serviceId)) { messages.add(String.format("Does not match the required pattern `%s`", SERVICE_ID_PATTERN.pattern())); } if (containsCompanyName(serviceId)) { messages.add(String.format( "Must not contain any of the following company names: [%s]", ValidationUtils.tickedList(COMPANY_NAMES))); } endsWithForbiddenWord(serviceId).ifPresent(suffix -> { messages.add(String.format("Must not case-insensitively end with `%s`", suffix)); }); if (serviceId.length() < 2 || serviceId.length() > 50) { messages.add("Must be between 2 and 50 characters long."); } if (!messages.isEmpty()) { throw new IllegalArgumentException(String.format( "Invalid SDK service ID value, `%s`: %s", serviceId, String.join(";", messages))); } } }
SdkServiceIdValidator extends AbstractValidator { public static void validateServiceId(String serviceId) { if (isPreviouslyReleasedInvalidServiceId(serviceId)) { return; } List<String> messages = new ArrayList<>(); if (!validForPattern(serviceId)) { messages.add(String.format("Does not match the required pattern `%s`", SERVICE_ID_PATTERN.pattern())); } if (containsCompanyName(serviceId)) { messages.add(String.format( "Must not contain any of the following company names: [%s]", ValidationUtils.tickedList(COMPANY_NAMES))); } endsWithForbiddenWord(serviceId).ifPresent(suffix -> { messages.add(String.format("Must not case-insensitively end with `%s`", suffix)); }); if (serviceId.length() < 2 || serviceId.length() > 50) { messages.add("Must be between 2 and 50 characters long."); } if (!messages.isEmpty()) { throw new IllegalArgumentException(String.format( "Invalid SDK service ID value, `%s`: %s", serviceId, String.join(";", messages))); } }  }
SdkServiceIdValidator extends AbstractValidator { public static void validateServiceId(String serviceId) { if (isPreviouslyReleasedInvalidServiceId(serviceId)) { return; } List<String> messages = new ArrayList<>(); if (!validForPattern(serviceId)) { messages.add(String.format("Does not match the required pattern `%s`", SERVICE_ID_PATTERN.pattern())); } if (containsCompanyName(serviceId)) { messages.add(String.format( "Must not contain any of the following company names: [%s]", ValidationUtils.tickedList(COMPANY_NAMES))); } endsWithForbiddenWord(serviceId).ifPresent(suffix -> { messages.add(String.format("Must not case-insensitively end with `%s`", suffix)); }); if (serviceId.length() < 2 || serviceId.length() > 50) { messages.add("Must be between 2 and 50 characters long."); } if (!messages.isEmpty()) { throw new IllegalArgumentException(String.format( "Invalid SDK service ID value, `%s`: %s", serviceId, String.join(";", messages))); } }  @Override List<ValidationEvent> validate(Model model); static boolean isPreviouslyReleasedInvalidServiceId(String serviceId); static void validateServiceId(String serviceId); }
SdkServiceIdValidator extends AbstractValidator { public static void validateServiceId(String serviceId) { if (isPreviouslyReleasedInvalidServiceId(serviceId)) { return; } List<String> messages = new ArrayList<>(); if (!validForPattern(serviceId)) { messages.add(String.format("Does not match the required pattern `%s`", SERVICE_ID_PATTERN.pattern())); } if (containsCompanyName(serviceId)) { messages.add(String.format( "Must not contain any of the following company names: [%s]", ValidationUtils.tickedList(COMPANY_NAMES))); } endsWithForbiddenWord(serviceId).ifPresent(suffix -> { messages.add(String.format("Must not case-insensitively end with `%s`", suffix)); }); if (serviceId.length() < 2 || serviceId.length() > 50) { messages.add("Must be between 2 and 50 characters long."); } if (!messages.isEmpty()) { throw new IllegalArgumentException(String.format( "Invalid SDK service ID value, `%s`: %s", serviceId, String.join(";", messages))); } }  @Override List<ValidationEvent> validate(Model model); static boolean isPreviouslyReleasedInvalidServiceId(String serviceId); static void validateServiceId(String serviceId);  }