title: JUnit test for System.out.println()
body: <p>I need to write JUnit tests for an old application that's poorly designed and is writing a lot of error messages to standard output. When the <code>getResponse(String request)</code> method behaves correctly it returns a XML response:</p>
  
  <pre><code>@BeforeClass
  public static void setUpClass() throws Exception {
      Properties queries = loadPropertiesFile("requests.properties");
      Properties responses = loadPropertiesFile("responses.properties");
      instance = new ResponseGenerator(queries, responses);
  }
  
  @Test
  public void testGetResponse() {
      String request = "&lt;some&gt;request&lt;/some&gt;";
      String expResult = "&lt;some&gt;response&lt;/some&gt;";
      String result = instance.getResponse(request);
      assertEquals(expResult, result);
  }
  </code></pre>
  
  <p>But when it gets malformed XML or does not understand the request it returns <code>null</code> and writes some  stuff to standard output.</p>
  
  <p>Is there any way to assert console output in JUnit? To catch cases like:</p>
  
  <pre><code>System.out.println("match found: " + strExpr);
  System.out.println("xml not well formed: " + e.getMessage());
  </code></pre>