import org.junit.After;
import java.lang.management.*;
import java.io.*;
import java.net.*;

public class SearchInHeap {
  @After public void searchInHeap() throws IOException, InterruptedException {
    String pid = ManagementFactory.getRuntimeMXBean().getName().replaceAll("@.*", "");
    System.out.println(pid);

    String tmp = System.getProperty("temporaryDir");
    String hprof = tmp + "/" + pid + ".hprof";
    System.out.println(hprof);
    String jhatPort = Integer.toString(7000 + Integer.parseInt(System.getProperty("org.gradle.test.worker")));
    System.out.println(jhatPort);

    Runtime.getRuntime().exec(new String[] {"jmap", String.format("-dump:format=b,file=%s", hprof), pid}).waitFor();
    String jhat = "jhat -port " + jhatPort + " " + hprof;
    Process p=Runtime.getRuntime().exec(jhat);

    BufferedReader reader=new BufferedReader(new InputStreamReader(p.getInputStream()));
    String line=reader.readLine();
    while(!line.matches("Server is ready."))
    {
      line=reader.readLine();
    }
    Thread.sleep(1000);

    URL oqlUrl = new URL("http://localhost:" + jhatPort + "/oql/?query=" + URLEncoder.encode("select a.toString() from [C a where /javax.security/(a.toString())", "UTF-8"));
    URLConnection oql = oqlUrl.openConnection();
    BufferedReader in = new BufferedReader(new InputStreamReader(oql.getInputStream()));
    String inputLine;
    String xml = "";

    while ((inputLine = in.readLine()) != null)
      xml += inputLine;
    in.close();

    System.out.println(xml);

    Runtime.getRuntime().exec(new String[] {"pkill", "-f", jhat}).waitFor();
    new File(hprof).delete();
  }
}

@@ -1,12 +1,46 @@
+import static org.junit.Assert.*;%0A
 import org.j
@@ -118,16 +118,103 @@
 a.net.*;
+%0Aimport javax.xml.xpath.*;%0Aimport org.xml.sax.InputSource;%0Aimport org.w3c.dom.NodeList;
 %0A%0Apublic
@@ -311,16 +311,42 @@
 xception
+, XPathExpressionException
  %7B%0A    S
@@ -1646,30 +1646,340 @@
     
-System.out.println(xml
+xml = xml.replaceAll(%22(%5C%5Cw+)=(%5B%5E'%5C%22%5D%5B%5E %5D+?)(%5B%5E'%5C%22%5D)%22, %22$1='$2'$3%22);%0A    String xpath = %22//table%5B@border=1%5D//td%22;%0A    XPath xPath = XPathFactory.newInstance().newXPath();%0A    NodeList nodeList = (NodeList) xPath.evaluate(xpath, new InputSource(new StringReader(xml)), XPathConstants.NODESET);%0A    assertEquals(0, nodeList.getLength()
 );%0A%0A

Search the jhat HTML and assert the results are 0