import static org.junit.Assert.*;
import org.junit.After;
import java.lang.management.*;
import java.io.*;
import java.net.*;
import javax.xml.xpath.*;
import org.xml.sax.InputSource;
import org.w3c.dom.NodeList;

public class SearchInHeap {
  @After public void searchInHeap() throws IOException, InterruptedException, XPathExpressionException {
    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 /really_unique_string/(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();

    xml = xml.replaceAll("(\\w+)=([^'\"][^ ]+?)([^'\"])", "$1='$2'$3");
    String xpath = "//table[@border=1]//td";
    XPath xPath = XPathFactory.newInstance().newXPath();
    NodeList nodeList = (NodeList) xPath.evaluate(xpath, new InputSource(new StringReader(xml)), XPathConstants.NODESET);
    assertEquals(0, nodeList.getLength());

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

@@ -430,37 +430,8 @@
 %22%22);
-%0A    System.out.println(pid);
 %0A%0A  
@@ -532,39 +532,8 @@
 f%22;%0A
-    System.out.println(hprof);%0A
     
@@ -642,42 +642,8 @@
 )));
-%0A    System.out.println(jhatPort);
 %0A%0A  

Remove debug prints