ResourceValidatorImpl implements ResourceValidator { public void validateName(String name) throws InvalidEntityException { if (name == null) { throw new InvalidEntityException("The environment name is not valid. It is null"); } if (name.indexOf('.') != -1 || name.indexOf('_') != -1 || name.indexOf(' ') != -1) { throw new InvalidEntityException("The name is not valid. There is a strange name"); } if (name.length() == 0) { throw new InvalidEntityException("The name is not valid. It is empty"); } if (name.length() > NAME_LENGHT) { throw new InvalidEntityException("The name is not valid. The name has mor than 30 characteres"); } }  void validateName(String name); void validateDescription(String name);  }
@Test(expected = InvalidEntityException.class) public void shouldValidateEmptyName() throws AlreadyExistEntityException, InvalidEntityException { resourceValidator.validateName(""); }
@Test(expected = InvalidEntityException.class) public void shouldValidateStrangeCharacterinName() throws AlreadyExistEntityException, InvalidEntityException { resourceValidator.validateName("name.name"); }
@Test(expected = InvalidEntityException.class) public void shouldValidateNameTooLong() throws AlreadyExistEntityException, InvalidEntityException { resourceValidator.validateName("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); }