### Question:
ContainerNameValidator extends DnsNameValidator { public void validate(String containerName) { super.validate(containerName); if (containerName.contains("--")) throw exception(containerName, "Every dash must be followed by letter or number"); if (containerName.endsWith("-")) throw exception(containerName, "Shouldn't end with a dash"); } @Inject  ContainerNameValidator(); void validate(String containerName);  }### Answer:
@Test public void testInvalidNames() { ContainerNameValidator validator = new ContainerNameValidator(); try { validator.validate("adasd-ab--baba"); throw new RuntimeException("to be converted to TestException later"); } catch (IllegalArgumentException e) { } try { validator.validate("abc.zz.la"); throw new RuntimeException("to be converted to TestException later"); } catch (IllegalArgumentException e) { } try { validator.validate("abcZZla"); throw new RuntimeException("to be converted to TestException later"); } catch (IllegalArgumentException e) { } try { validator.validate("zz"); throw new RuntimeException("to be converted to TestException later"); } catch (IllegalArgumentException e) { } try { validator.validate("a????"); throw new RuntimeException("to be converted to TestException later"); } catch (IllegalArgumentException e) { } try { validator.validate("-adasd"); throw new RuntimeException("to be converted to TestException later"); } catch (IllegalArgumentException e) { } try { validator.validate("adasd-"); throw new RuntimeException("to be converted to TestException later"); } catch (IllegalArgumentException e) { } }
@Test public void testNamesValidity() { ContainerNameValidator validator = new ContainerNameValidator(); validator.validate("adasd"); validator.validate("adasd-ab"); validator.validate("zzz"); validator.validate("abcefghjlkmnop"); }
@Test public void testInvalidNames() { ContainerNameValidator validator = new ContainerNameValidator(); try { validator.validate("adasd-ab--baba"); throw new RuntimeException("to be converted to TestException later"); } catch(IllegalArgumentException e) { } try { validator.validate("abc.zz.la"); throw new RuntimeException("to be converted to TestException later"); } catch(IllegalArgumentException e) { } try { validator.validate("abcZZla"); throw new RuntimeException("to be converted to TestException later"); } catch(IllegalArgumentException e) { } try { validator.validate("zz"); throw new RuntimeException("to be converted to TestException later"); } catch(IllegalArgumentException e) { } try { validator.validate("a????"); throw new RuntimeException("to be converted to TestException later"); } catch(IllegalArgumentException e) { } try { validator.validate("-adasd"); throw new RuntimeException("to be converted to TestException later"); } catch(IllegalArgumentException e) { } try { validator.validate("adasd-"); throw new RuntimeException("to be converted to TestException later"); } catch(IllegalArgumentException e) { } }