### Question:
VaadinServiceNameChecker { public String check(String serviceName) { if (serviceName == null || serviceName.isEmpty()) { return "Service name cannot be blank"; } if (ECMA_SCRIPT_RESERVED_WORDS.contains(serviceName)) { return "Service name cannot be equal to JavaScript reserved words"; } if (CONTAINS_WHITESPACE_PATTERN.matcher(serviceName).matches()) { return "Service name cannot contain any whitespaces"; } return null; }  String check(String serviceName); static final Set<String> ECMA_SCRIPT_RESERVED_WORDS; }### Answer:
@Test public void should_ReturnValidationError_When_NullAsServiceNameGiven() { String validationResult = checker.check(null); assertNotNull(validationResult); assertTrue(validationResult.contains("blank")); }
@Test public void should_ReturnValidationError_When_EmptyAsServiceNameGiven() { String validationResult = checker.check(""); assertNotNull(validationResult); assertTrue(validationResult.contains("blank")); }
@Test public void should_ReturnValidationError_When_ReservedWordAsServiceNameGiven() { for (String reservedEsWord : VaadinServiceNameChecker.ECMA_SCRIPT_RESERVED_WORDS) { String validationResult = checker.check(reservedEsWord); assertNotNull(String.format( "Word '%s' should cause validation errors, but it did not", reservedEsWord), validationResult); assertTrue(validationResult.contains("reserved")); } }
@Test public void should_ReturnValidationError_When_ServiceNameWithWhitespaceGiven() { for (String wordWithWhitespace : Arrays.asList("bad name", "bad\nname", "bad\tname", "bad\rname")) { String validationResult = checker.check(wordWithWhitespace); assertNotNull(String.format( "Word '%s' should cause validation errors, but it did not", wordWithWhitespace), validationResult); assertTrue(validationResult.contains("whitespace")); } }
@Test public void should_ReturnNoErrors_When_ValidServiceNameGiven() { String validationResult = checker.check("ordinaryName"); assertNull(validationResult); }