### Question:
MODSValidator { public void validate(File file) throws MetadataValidationException, IOException { validate(new ByteArrayInputStream(Files.readAllBytes(file.toPath()))); }  SchematronValidator getSchematronValidator(); void setSchematronValidator(SchematronValidator schematronValidator); Schema getModsSchema(); void setModsSchema(Schema modsSchema); void validate(File file); void validate(InputStream docStream);  }### Answer:
@Test public void testNonModsDocument() throws Exception { thrown.expect(MetadataValidationException.class); thrown.expectMessage("schema"); doc.addContent(new Element("root")); validator.validate(convertDocumentToStream(doc)); }
@Test public void testValidateSimple() throws Exception { doc.addContent(new Element("mods", MODS_V3_NS) .addContent(new Element("titleInfo", MODS_V3_NS) .addContent(new Element("title", MODS_V3_NS).setText("Value")))); validator.validate(convertDocumentToStream(doc)); }
@Test public void testSchemaFailure() throws Exception { thrown.expect(MetadataValidationException.class); thrown.expectMessage("schema"); doc.addContent(new Element("mods", MODS_V3_NS) .addContent(new Element("invalid", MODS_V3_NS))); validator.validate(convertDocumentToStream(doc)); }
@Test public void testInvalidLanguageCode() throws Exception { thrown.expect(MetadataValidationException.class); thrown.expectMessage("local conventions"); doc.addContent(new Element("mods", MODS_V3_NS) .addContent(new Element("language", MODS_V3_NS) .addContent(new Element("languageTerm", MODS_V3_NS) .setText("java") .setAttribute("authority", "iso639-2b") .setAttribute("type", "code")))); validator.validate(convertDocumentToStream(doc)); }
@Test public void testUnacceptableLanguageAuthority() throws Exception { thrown.expect(MetadataValidationException.class); thrown.expectMessage("local conventions"); doc.addContent(new Element("mods", MODS_V3_NS) .addContent(new Element("language", MODS_V3_NS) .addContent(new Element("languageTerm", MODS_V3_NS) .setText("eng") .setAttribute("authority", "rfc3066") .setAttribute("type", "code")))); validator.validate(convertDocumentToStream(doc)); }
@Test public void testValidLanguage() throws Exception { doc.addContent(new Element("mods", MODS_V3_NS) .addContent(new Element("language", MODS_V3_NS) .addContent(new Element("languageTerm", MODS_V3_NS) .setText("eng") .setAttribute("authority", "iso639-2b") .setAttribute("type", "code")))); validator.validate(convertDocumentToStream(doc)); }
@Test public void testFromFile() throws Exception { doc.addContent(new Element("mods", MODS_V3_NS) .addContent(new Element("titleInfo", MODS_V3_NS) .addContent(new Element("title", MODS_V3_NS).setText("Value")))); File docFile = Files.createTempFile("mods", ".xml").toFile(); new XMLOutputter().output(doc, new FileOutputStream(docFile)); validator.validate(docFile); }
@Test(expected = IOException.class) public void testMissingFile() throws Exception { File docFile = Files.createTempFile("mods", ".xml").toFile(); docFile.delete(); validator.validate(docFile); }