### Question:
FileTypeValidator extends FileValidator { @Override public boolean isValid(String input) { return (!mustExist || super.isValid(input)) && type.matches(input); } FileTypeValidator(FileType type, boolean mustExist); @Override boolean isValid(String input);  }### Answer:
@Test public void notExisting() { Validator<String> victim = Validators.existingFileType(FileType.ALL); Assert.assertFalse(victim.isValid("/Chuck/Norris")); }
@Test public void existingAll() throws IOException { Validator<String> victim = Validators.existingFileType(FileType.ALL); Path test = Files.createTempFile("tmp", ".norris"); Assert.assertTrue(victim.isValid(test.toAbsolutePath().toString())); Files.delete(test); }
@Test public void existingAllNoExtension() throws IOException { Validator<String> victim = Validators.existingFileType(FileType.ALL); Path test = Files.createTempFile("tmp", ""); Assert.assertTrue(victim.isValid(test.toAbsolutePath().toString())); Files.delete(test); }
@Test public void existingHtml() throws IOException { Validator<String> victim = Validators.existingFileType(FileType.HTML); Path test = Files.createTempFile("tmp", ".htm"); Assert.assertTrue(victim.isValid(test.toAbsolutePath().toString())); Files.delete(test); }
@Test public void existingPdfInsensitive() throws IOException { Validator<String> victim = Validators.existingFileType(FileType.PDF); Path test = Files.createTempFile("tmp", ".PdF"); Assert.assertTrue(victim.isValid(test.toAbsolutePath().toString())); Files.delete(test); }
@Test public void allowBlank() { Validator<String> victim = Validators.existingFileType(FileType.HTML); Assert.assertFalse(victim.isValid("")); Assert.assertTrue(Validators.validEmpty(victim).isValid("")); }
@Test public void notExistingValid() { Validator<String> victim = Validators.fileType(FileType.ALL, false); Assert.assertTrue(victim.isValid("/Chuck/Norris")); }