@Test
public void testLastCommitSmellsQuery() {

    List<Map<String, Object>> result;
    Commit branchCommit = prepareCommit("sha", 0);
    Commit anotherCommit = prepareCommit("another", 4);
    // No merged branch means no result
    result = persistence.query(queries.lastCommitIdQuery(projectId, 1));
    assertTrue(result.isEmpty());
    String filtered_type = "MIM";
    Smell smell1 = new Smell(filtered_type, "instance1", "file1");
    Smell smell2 = new Smell(filtered_type, "instance2", "file2");
    Smell smell3 = new Smell("LIC", "instance3", "file3");
    addSmells(originCommit, smell1, smell2, smell3);
    addSmells(mergedIntoCommit, smell3);
    int firstBranchID = insertBranch(projectId, 4, originCommit, mergedIntoCommit);
    int secondBranchID = insertBranch(projectId, 5, mergedIntoCommit, originCommit);
    // Nothing returned if no commit in the branch
    result = persistence.query(queries.lastCommitSmellsQuery(projectId, mergedIntoCommit, null));
    assertTrue(result.isEmpty());
    result = persistence.query(queries.lastCommitSmellsQuery(projectId, originCommit, null));
    assertTrue(result.isEmpty());
    addSmells(branchCommit, smell1, smell2, smell3);
    addSmells(anotherCommit, smell3);
    executeSuccess(queries.branchCommitInsertionQuery(projectId, 4, branchCommit.sha, 5));
    executeSuccess(queries.branchCommitInsertionQuery(projectId, 4, anotherCommit.sha, 1));
    executeSuccess(queries.branchCommitInsertionQuery(projectId, 5, branchCommit.sha, 0));
    executeSuccess(queries.branchCommitInsertionQuery(projectId, 5, anotherCommit.sha, 1));
    // Adding commits to the branch will change our result
    // - First branch, merged into MergedIntoCommit
    result = persistence.query(queries.lastCommitSmellsQuery(projectId, mergedIntoCommit, null));
    checkContainsSmells(result, Arrays.asList(smell1, smell2, smell3));
    result = persistence.query(queries.lastCommitSmellsQuery(projectId, mergedIntoCommit, filtered_type));
    checkContainsSmells(result, Arrays.asList(smell1, smell2));
    // - Second branch, merged into originCommit
    result = persistence.query(queries.lastCommitSmellsQuery(projectId, originCommit, null));
    checkContainsSmells(result, Collections.singletonList(smell3));
    result = persistence.query(queries.lastCommitSmellsQuery(projectId, originCommit, smell3.type));
    checkContainsSmells(result, Collections.singletonList(smell3));
    result = persistence.query(queries.lastCommitSmellsQuery(projectId, originCommit, filtered_type));
    assertTrue(result.isEmpty());
}