### Question:
RdfPatchUtil { public static void applyPatch(Repository repository, String patch, Resource... contexts) throws RepositoryException, ParseException, InvalidPatchDocumentException { applyPatch(repository, getPatch(repository.getValueFactory(), patch), contexts); } private  RdfPatchUtil(); static void applyPatch(Repository repository, String patch, Resource... contexts); static void applyPatch(Repository repository, InputStream patchSource, Resource... contexts); static void applyPatch(RepositoryConnection connection, String patch, Resource... contexts); static void applyPatch(RepositoryConnection connection, InputStream patchSource, Resource... contexts); static void applyPatch(Repository repository, List<PatchLine> patch, Resource... contexts); static void applyPatch(RepositoryConnection connection, List<PatchLine> patch, Resource... contexts); static List<PatchLine> diff(Repository r1, Repository r2, boolean optimize, Resource... contexts); static List<PatchLine> diff(RepositoryConnection c1, RepositoryConnection c2, boolean optimize, Resource... contexts);  }### Answer:
@Test public void testApplyPatch() throws Exception { RepositoryConnection con = repository.getConnection(); try { con.begin(); Assert.assertTrue(con.hasStatement(bob, FOAF.NAME, lcBob, false)); Assert.assertFalse(con.hasStatement(bob, FOAF.NAME, ucBob, false)); Assert.assertFalse(con.hasStatement(bob, FOAF.KNOWS, alice, false)); Assert.assertTrue(con.hasStatement(bob, FOAF.KNOWS, charlie, false)); RdfPatchUtil.applyPatch(con, this.getClass().getResourceAsStream("/illustrative.rdfp")); Assert.assertFalse(con.hasStatement(bob, FOAF.NAME, lcBob, false)); Assert.assertTrue(con.hasStatement(bob, FOAF.NAME, ucBob, false)); Assert.assertTrue(con.hasStatement(bob, FOAF.KNOWS, alice, false)); Assert.assertFalse(con.hasStatement(bob, FOAF.KNOWS, charlie, false)); con.commit(); } finally { con.close(); } }
@Test(expected = InvalidPatchDocumentException.class) public void testInvalidPatchDocumentException() throws RepositoryException, ParseException, InvalidPatchDocumentException { RepositoryConnection con = repository.getConnection(); try { final String invalidPatch = "A <http: RdfPatchUtil.applyPatch(con, invalidPatch); Assert.fail("applyPatch should throw an InvalidPatchDocumentException"); } catch (final Throwable t) { con.rollback(); throw t; } finally { con.close(); } }