[Demonstration 1]

[Buggy Method]
@Test
public void testDefaultException() {
    exceptionMessage = "Something went wrong somewhere!";
    ModelAndView model = exceptionService.addException(null, exceptionMessage);
    assertEquals(exceptionMessage, model.getModel().get("exception_message"));
    assertEquals("exception", model.getViewName());
}

[Buggy Hunk]
ModelAndView model = exceptionService.addException(null, exceptionMessage);

[Patch]
ModelAndView model = exceptionService.addException(new ModelAndView("exception"), exceptionMessage);

[Demonstration 2]

[Buggy Method]
public static String[] readURLStringFromFile(String filename) {
    LOG.debug("Start readURLStringFromFile.. filename={}", filename);
    String[] urlStrings = null;
    try (BufferedReader bufferedReader = new BufferedReader(new FileReader(filename))) {
        List<String> lines = new ArrayList();
        String line = null;
        while ((line = bufferedReader.readLine()) != null) {
            line = line.trim();
            if (!line.equals("")) {
                lines.add(line);
            }
        }
        urlStrings = lines.toArray(new String[lines.size()]);
    } catch (IOException ie) {
        LOG.error(ie.getMessage());
    }
    return urlStrings;
}

[Buggy Hunk]
public static String[] readURLStringFromFile(String filename) {

[Patch]
private static String[] readURLStringFromFile(String filename) {

[Demonstration 3]

[Buggy Method]
@Test
public void testSAMLFederatedAuthenticationPOSTBinding() {
    try {
        HttpURLConnection urlConnection = SAMLOutboundTestUtils.request(SAMLOutboundTestConstants.GATEWAY_ENDPOINT + "?" + SAMLOutboundTestConstants.SAMPLE_PROTOCOL + "=true", HttpMethod.GET, false);
        String content = SAMLOutboundTestUtils.getContent(urlConnection);
        String relayState = SAMLOutboundTestUtils.getParameterFromHTML(content, "'RelayState' value='", "'>");
        String samlResponse = SAMLOutboundTestUtils.getSAMLResponse(false);
        samlResponse = URLEncoder.encode(samlResponse);
        urlConnection = SAMLOutboundTestUtils.request(SAMLOutboundTestConstants.GATEWAY_ENDPOINT, HttpMethod.POST, true);
        String postData = "SAMLResponse=" + samlResponse + "&" + "RelayState=" + relayState;
        urlConnection.setDoOutput(true);
        urlConnection.getOutputStream().write(postData.toString().getBytes(Charsets.UTF_8));
        urlConnection.getResponseCode();
        String locationHeader = SAMLOutboundTestUtils.getResponseHeader(HttpHeaders.LOCATION, urlConnection);
        Assert.assertTrue(locationHeader.contains("authenticatedUser=AuthenticatedUserName"));
    } catch (IOException e) {
        Assert.fail("Error while running federated authentication test case");
    } catch (IdentityException e) {
        Assert.fail("Error while running federated authentication test case");
    }
}

[Buggy Hunk]
Assert.assertTrue(locationHeader.contains("authenticatedUser=AuthenticatedUserName"));

[Patch]
Assert.assertTrue(locationHeader.contains("authenticatedUser=" + SAMLOutboundTestConstants.AUTHENTICATED_USER_NAME));