@Test
public void testCommitOrdinalQuery() {

    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.commitOrdinalQuery(projectId, 1, branchCommit));
    assertTrue(result.isEmpty());
    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.commitOrdinalQuery(projectId, firstBranchID, branchCommit));
    assertTrue(result.isEmpty());
    result = persistence.query(queries.commitOrdinalQuery(projectId, firstBranchID, mergedIntoCommit));
    assertTrue(result.isEmpty());
    // Parent and merged commits are not in the branch
    result = persistence.query(queries.commitOrdinalQuery(projectId, firstBranchID, originCommit));
    assertTrue(result.isEmpty());
    result = persistence.query(queries.commitOrdinalQuery(projectId, firstBranchID, mergedIntoCommit));
    assertTrue(result.isEmpty());
    executeSuccess(queries.branchCommitInsertionQuery(projectId, 4, branchCommit.sha, 5));
    executeSuccess(queries.branchCommitInsertionQuery(projectId, 4, anotherCommit.sha, 1));
    executeSuccess(queries.branchCommitInsertionQuery(projectId, 5, branchCommit.sha, 3));
    executeSuccess(queries.branchCommitInsertionQuery(projectId, 5, anotherCommit.sha, 4));
    // Adding commits to the branch will change our result
    result = persistence.query(queries.commitOrdinalQuery(projectId, firstBranchID, branchCommit));
    assertEquals(5, result.get(0).get("ordinal"));
    result = persistence.query(queries.commitOrdinalQuery(projectId, firstBranchID, anotherCommit));
    assertEquals(1, result.get(0).get("ordinal"));
    result = persistence.query(queries.commitOrdinalQuery(projectId, secondBranchID, branchCommit));
    assertEquals(3, result.get(0).get("ordinal"));
    result = persistence.query(queries.commitOrdinalQuery(projectId, secondBranchID, anotherCommit));
    assertEquals(4, result.get(0).get("ordinal"));
}