[Demonstration 1]

[Buggy Method]
@Test(groups = { "wso2.am" }, description = "Pagination test case")
public void testPagination() {
    int numberOfAPIs = 24;
    boolean isLoginSuccess = false;
    boolean isPaginationCorrect = false;
    String storeURLHttp = storeUrls.getWebAppURLHttp();
    APIStoreRestClient apiStore = new APIStoreRestClient(storeURLHttp);
    HttpResponse storeLoginResponse = null;
    String successResponse = "{\"error\" : false}";
    //create 24 APIs and publish them; these APIs should be paginated as 10,10,4
    try {
        for (int i = 0; i < numberOfAPIs; i++) {
            String APIName = "PaginationTestAPI" + Integer.toString(i);
            String APIContext = "paginationTest" + Integer.toString(i);
            String tags = "pagination";
            String url = "https://localhost:9443/test";
            String description = "This is test API create by API manager integration test";
            String providerName = publisherContext.getContextTenant().getTenantAdmin().getUserName() + "@" + tenantDomain;
            String APIVersion = "1.0.0";
            APIPublisherRestClient apiPublisher = new APIPublisherRestClient(publisherURLHttp);
            apiPublisher.login(publisherContext.getContextTenant().getTenantAdmin().getUserName() + "@" + tenantDomain, publisherContext.getContextTenant().getTenantAdmin().getPassword());
            APIRequest apiRequest = new APIRequest(APIName, APIContext, new URL(url));
            apiRequest.setTags(tags);
            apiRequest.setDescription(description);
            apiRequest.setVersion(APIVersion);
            apiRequest.setSandbox(url);
            apiRequest.setResourceMethod("GET");
            apiRequest.setProvider(providerName);
            apiPublisher.addAPI(apiRequest);
            //update the lifecycle of the API to Published state, so that is it visible in store
            APILifeCycleStateRequest updateRequest = new APILifeCycleStateRequest(APIName, providerName, APILifeCycleState.PUBLISHED);
            apiPublisher.changeAPILifeCycleStatus(updateRequest);
        }
        //give a short time to apply the changes and build index, otherwise it will not be visible in the store
        Thread.sleep(60000);
        //after adding the APIs, send the request to log-in to the api store
        storeLoginResponse = apiStore.login("admin", "admin");
    } catch (XPathExpressionException e) {
        assertTrue(false, "Error occurred when retrieving context to add APIs. Pagination count test case failed.");
    } catch (APIManagerIntegrationTestException e) {
        assertTrue(false, "Error occurred while log-in to add APIs. Pagination count test case failed.");
    } catch (MalformedURLException e) {
        assertTrue(false, "Invalid service URL to add APIs. Pagination count test case failed.");
    } catch (InterruptedException e) {
        assertTrue(false, "Error while pausing the current thread. Pagination count test case failed.");
    }
    String loginResponseCookie = null;
    //get the cookie related to the login
    if (storeLoginResponse != null) {
        loginResponseCookie = storeLoginResponse.getHeaders().get("Set-Cookie");
        if (successResponse.equals(storeLoginResponse.getData())) {
            isLoginSuccess = true;
        }
    }
    //the second request to get APIs for the pages, is sent only if the login is successful and and cookie is ok
    if (isLoginSuccess && loginResponseCookie != null) {
        int offset = 10;
        //fetch the first page, this page should have 10 results
        int countInFirstPage = getPaginationElementsCount(storeURLHttp, loginResponseCookie, 0, offset);
        //fetch the 2nd page, this page should have 10 results
        int countInSecondPage = getPaginationElementsCount(storeURLHttp, loginResponseCookie, 10, offset);
        //fetch the 3nd page, this page should have 4 results
        int countInThirdPage = getPaginationElementsCount(storeURLHttp, loginResponseCookie, 20, offset);
        //testing the output; added 24 APIs should be paginated as 10,10,4
        if (countInFirstPage == 10 && countInSecondPage == 10 && countInThirdPage == 4) {
            isPaginationCorrect = true;
        }
    }
    assertTrue(isPaginationCorrect, "Incorrect Pagination during API Search. Pagination count test case failed.");
}

[Buggy Hunk]
public void testPagination() {

[Patch]
public void testPagination() throws Exception {

[Demonstration 2]

[Buggy Method]
private ArrayList<String> getOutputForStream(InputStream stream) throws Exception {
    ArrayList<String> output = new ArrayList<>();
    try (BufferedReader reader = new BufferedReader(new InputStreamReader(stream))) {
        String line;
        while ((line = reader.readLine()) != null) {
            output.add(line);
        }
    }
    return output;
}

[Buggy Hunk]
private ArrayList<String> getOutputForStream(InputStream stream) throws Exception {

[Patch]
private ArrayList<String> getOutputForStream(InputStream stream) throws IOException {

[Demonstration 3]

[Buggy Method]
public static List<String> getUsers(String rawdata) {
    JSONObject jsonobj = new JSONObject(rawdata);
    if (jsonobj.has("Users")) {
        JSONArray jsonarray = new JSONArray(jsonobj.get("Users").toString());
        List<String> users = new ArrayList<String>();
        for (int i = 0; i < jsonarray.length(); i++) {
            users.add(jsonarray.get(i).toString());
        }
        return users;
    }
    return null;
}

[Buggy Hunk]
if (jsonobj.has("Users")) {

[Patch]
if (!jsonobj.isNull("Users")) {