@Test
public void testCommitSmellsQuery() {

    List<Map<String, Object>> result;
    Commit commit = prepareCommit("sha");
    Commit second_commit = prepareCommit("another_sha");
    String commitIdQuery = commitQueries.idFromShaQuery(projectId, commit.sha);
    int commitId = (int) persistence.query(commitIdQuery).get(0).get("id");
    // No smell means no result
    result = persistence.query(queries.commitSmellsQuery(projectId, String.valueOf(commitId), smell.type));
    assertTrue(result.isEmpty());
    Smell anotherSmellType = new Smell("MIM", smell.instance, "yetanotherfile");
    Smell anotherSmell = new Smell(smell.type, "anotherinstance", "anotherfile");
    Smell smellOtherCommit = new Smell(smell.type, "my.smell.instance", "anotherfile");
    smell.id = createSmell(projectId, smell, queries);
    anotherSmell.id = createSmell(projectId, anotherSmell, queries);
    anotherSmellType.id = createSmell(projectId, anotherSmellType, queries);
    smellOtherCommit.id = createSmell(projectId, smellOtherCommit, queries);
    // Presences in first commit
    executeSuccess(queries.smellCategoryInsertionStatement(projectId, commit.sha, smell, SmellCategory.PRESENCE));
    executeSuccess(queries.smellCategoryInsertionStatement(projectId, commit.sha, anotherSmell, SmellCategory.PRESENCE));
    executeSuccess(queries.smellCategoryInsertionStatement(projectId, commit.sha, anotherSmellType, SmellCategory.PRESENCE));
    // Presences in second commit
    executeSuccess(queries.smellCategoryInsertionStatement(projectId, second_commit.sha, anotherSmell, SmellCategory.PRESENCE));
    executeSuccess(queries.smellCategoryInsertionStatement(projectId, second_commit.sha, smellOtherCommit, SmellCategory.PRESENCE));
    // We can use the raw commit ID
    result = persistence.query(queries.commitSmellsQuery(projectId, String.valueOf(commitId), null));
    assertEquals(3, result.size());
    checkContainsSmells(result, Arrays.asList(smell, anotherSmellType, anotherSmell));
    // We can use a query to retrieve commitId
    result = persistence.query(queries.commitSmellsQuery(projectId, "(" + commitIdQuery + ")", null));
    assertEquals(3, result.size());
    checkContainsSmells(result, Arrays.asList(smell, anotherSmellType, anotherSmell));
    // We can filter by smell type
    result = persistence.query(queries.commitSmellsQuery(projectId, String.valueOf(commitId), smell.type));
    assertEquals(2, result.size());
    checkContainsSmells(result, Arrays.asList(smell, anotherSmell));
    // We can return the smell parent's values
    Smell withParent = new Smell(smell.type, "withParentInstance", "withParentFile");
    withParent.parent = smell;
    withParent.id = createSmell(projectId, withParent, queries);
    executeSuccess(queries.smellCategoryInsertionStatement(projectId, commit.sha, withParent, SmellCategory.PRESENCE));
    result = persistence.query(queries.commitSmellsQuery(projectId, String.valueOf(commitId), smell.type));
    assertEquals(3, result.size());
    checkContainsSmells(result, Arrays.asList(smell, anotherSmell, withParent));
    // We filter by commit
    result = persistence.query(queries.commitSmellsQuery(projectId, "(" + commitQueries.idFromShaQuery(projectId, second_commit.sha) + ")", smell.type));
    assertEquals(2, result.size());
    checkContainsSmells(result, Arrays.asList(anotherSmell, smellOtherCommit));
}