@Test public void testMergeNotInDirectParentBranchesSeparateSmells() throws QueryException { Commit A = new Commit("0-A", 0); Commit B = new Commit("0-B", 1); Commit C = new Commit("0-C", 3); Commit D = new Commit("1-D", 2); Commit E = new Commit("2-E", 4); Commit F = new Commit("1-F", 5); Commit G = new Commit("0-G", 6); Commit H = new Commit("1-H", 7); Commit I = new Commit("0-I", 8); mockCommitSmells(A, firstSmell); mockCommitSmells(D, firstSmell, secondSmell); mockCommitSmells(E, secondSmell); mockCommitSmells(F, firstSmell, secondSmell); mockCommitSmells(G, secondSmell); mockCommitSmells(H, firstSmell, secondSmell, thirdSmell); mockCommitSmells(I, secondSmell, thirdSmell); mockCommitBranch(A, 0, 0); mockCommitBranch(B, 0, 1); mockCommitBranch(C, 0, 2); mockCommitBranch(D, 1, 0); mockCommitBranch(E, 2, 0); mockCommitBranch(F, 1, 1); mockCommitBranch(G, 0, 3); mockCommitBranch(H, 1, 2); mockCommitBranch(I, 0, 4); mockLastBranchCommit(0, I); mockLastBranchCommit(1, H); mockLastBranchCommit(2, E); mockMergeCommit(I, H); mockMergeCommit(G, E); mockBranchParentCommitSmells(1, firstSmell); mockBranchParentCommitSmells(2, firstSmell, secondSmell); getAnalysis().query(); debugSmellInsertions(); verify(persistence, times(3)).execute(any()); verify(smellQueries).smellInsertionStatement(projectId, firstSmell); verify(smellQueries).smellInsertionStatement(projectId, secondSmell); verify(smellQueries).smellInsertionStatement(projectId, thirdSmell); verify(persistence, times(17)).addStatements(any()); verify(smellQueries).smellCategoryInsertionStatement(projectId, A.sha, firstSmell, SmellCategory.PRESENCE); verify(smellQueries).smellCategoryInsertionStatement(projectId, A.sha, firstSmell, SmellCategory.INTRODUCTION); verify(smellQueries).smellCategoryInsertionStatement(projectId, B.sha, firstSmell, SmellCategory.REFACTOR); verify(smellQueries).smellCategoryInsertionStatement(projectId, D.sha, firstSmell, SmellCategory.PRESENCE); verify(smellQueries).smellCategoryInsertionStatement(projectId, D.sha, secondSmell, SmellCategory.PRESENCE); verify(smellQueries).smellCategoryInsertionStatement(projectId, D.sha, secondSmell, SmellCategory.INTRODUCTION); verify(smellQueries).smellCategoryInsertionStatement(projectId, F.sha, firstSmell, SmellCategory.PRESENCE); verify(smellQueries).smellCategoryInsertionStatement(projectId, F.sha, secondSmell, SmellCategory.PRESENCE); verify(smellQueries).smellCategoryInsertionStatement(projectId, H.sha, firstSmell, SmellCategory.PRESENCE); verify(smellQueries).smellCategoryInsertionStatement(projectId, H.sha, secondSmell, SmellCategory.PRESENCE); verify(smellQueries).smellCategoryInsertionStatement(projectId, H.sha, thirdSmell, SmellCategory.PRESENCE); verify(smellQueries).smellCategoryInsertionStatement(projectId, H.sha, thirdSmell, SmellCategory.INTRODUCTION); verify(smellQueries).smellCategoryInsertionStatement(projectId, E.sha, firstSmell, SmellCategory.REFACTOR); verify(smellQueries).smellCategoryInsertionStatement(projectId, E.sha, secondSmell, SmellCategory.PRESENCE); verify(smellQueries).smellCategoryInsertionStatement(projectId, G.sha, secondSmell, SmellCategory.PRESENCE); verify(smellQueries).smellCategoryInsertionStatement(projectId, I.sha, secondSmell, SmellCategory.PRESENCE); verify(smellQueries).smellCategoryInsertionStatement(projectId, I.sha, thirdSmell, SmellCategory.PRESENCE); }
@Override public void query() throws QueryException { Smell smell; Commit previousCommit; Commit commit = Commit.empty(); Integer previousBranch; Integer currentBranch = -1; Map<String, Object> instance; while (smells.hasNext()) { instance = smells.next(); previousCommit = commit; previousBranch = currentBranch; commit = Commit.fromInstance(instance); smell = Smell.fromPaprikaInstance(instance, smellType); try { currentBranch = fetchCommitBranch(commit); } catch (BranchNotFoundException e) { logger.warn("[" + projectId + "] ==> Unable to guess branch for commit (" + commit.sha + "), skipping", e.getMessage()); continue; } if (!branchAnalyzers.containsKey(currentBranch)) { logger.debug("[" + projectId + "] => Initializing new branch: " + currentBranch); initializeBranch(currentBranch); } commit.setBranchOrdinal(fetchCommitOrdinal(currentBranch, commit)); branchAnalyzers.get(currentBranch).notifyCommit(commit); if (!previousCommit.equals(commit)) { synchronizeMergeSmells(commit, currentBranch); } branchAnalyzers.get(currentBranch).notifySmell(smell); if (!previousCommit.equals(commit) && isLastBranchCommit(previousCommit, previousBranch)) { finalizeBranch(previousBranch); branchAnalyzers.remove(previousBranch); } } for (int branchId : branchAnalyzers.keySet()) { finalizeBranch(branchId); } }
BranchAwareSmellTypeAnalysis implements Query { @Override public void query() throws QueryException { Smell smell; Commit previousCommit; Commit commit = Commit.empty(); Integer previousBranch; Integer currentBranch = -1; Map<String, Object> instance; while (smells.hasNext()) { instance = smells.next(); previousCommit = commit; previousBranch = currentBranch; commit = Commit.fromInstance(instance); smell = Smell.fromPaprikaInstance(instance, smellType); try { currentBranch = fetchCommitBranch(commit); } catch (BranchNotFoundException e) { logger.warn("[" + projectId + "] ==> Unable to guess branch for commit (" + commit.sha + "), skipping", e.getMessage()); continue; } if (!branchAnalyzers.containsKey(currentBranch)) { logger.debug("[" + projectId + "] => Initializing new branch: " + currentBranch); initializeBranch(currentBranch); } commit.setBranchOrdinal(fetchCommitOrdinal(currentBranch, commit)); branchAnalyzers.get(currentBranch).notifyCommit(commit); if (!previousCommit.equals(commit)) { synchronizeMergeSmells(commit, currentBranch); } branchAnalyzers.get(currentBranch).notifySmell(smell); if (!previousCommit.equals(commit) && isLastBranchCommit(previousCommit, previousBranch)) { finalizeBranch(previousBranch); branchAnalyzers.remove(previousBranch); } } for (int branchId : branchAnalyzers.keySet()) { finalizeBranch(branchId); } } }
BranchAwareSmellTypeAnalysis implements Query { @Override public void query() throws QueryException { Smell smell; Commit previousCommit; Commit commit = Commit.empty(); Integer previousBranch; Integer currentBranch = -1; Map<String, Object> instance; while (smells.hasNext()) { instance = smells.next(); previousCommit = commit; previousBranch = currentBranch; commit = Commit.fromInstance(instance); smell = Smell.fromPaprikaInstance(instance, smellType); try { currentBranch = fetchCommitBranch(commit); } catch (BranchNotFoundException e) { logger.warn("[" + projectId + "] ==> Unable to guess branch for commit (" + commit.sha + "), skipping", e.getMessage()); continue; } if (!branchAnalyzers.containsKey(currentBranch)) { logger.debug("[" + projectId + "] => Initializing new branch: " + currentBranch); initializeBranch(currentBranch); } commit.setBranchOrdinal(fetchCommitOrdinal(currentBranch, commit)); branchAnalyzers.get(currentBranch).notifyCommit(commit); if (!previousCommit.equals(commit)) { synchronizeMergeSmells(commit, currentBranch); } branchAnalyzers.get(currentBranch).notifySmell(smell); if (!previousCommit.equals(commit) && isLastBranchCommit(previousCommit, previousBranch)) { finalizeBranch(previousBranch); branchAnalyzers.remove(previousBranch); } } for (int branchId : branchAnalyzers.keySet()) { finalizeBranch(branchId); } } BranchAwareSmellTypeAnalysis(int projectId, Persistence persistence, Iterator<Map<String, Object>> smells,
                                 String smellType, SmellDuplicationChecker duplicationChecker,
                                 CommitQueries commitQueries, SmellQueries smellQueries, BranchQueries branchQueries); }
BranchAwareSmellTypeAnalysis implements Query { @Override public void query() throws QueryException { Smell smell; Commit previousCommit; Commit commit = Commit.empty(); Integer previousBranch; Integer currentBranch = -1; Map<String, Object> instance; while (smells.hasNext()) { instance = smells.next(); previousCommit = commit; previousBranch = currentBranch; commit = Commit.fromInstance(instance); smell = Smell.fromPaprikaInstance(instance, smellType); try { currentBranch = fetchCommitBranch(commit); } catch (BranchNotFoundException e) { logger.warn("[" + projectId + "] ==> Unable to guess branch for commit (" + commit.sha + "), skipping", e.getMessage()); continue; } if (!branchAnalyzers.containsKey(currentBranch)) { logger.debug("[" + projectId + "] => Initializing new branch: " + currentBranch); initializeBranch(currentBranch); } commit.setBranchOrdinal(fetchCommitOrdinal(currentBranch, commit)); branchAnalyzers.get(currentBranch).notifyCommit(commit); if (!previousCommit.equals(commit)) { synchronizeMergeSmells(commit, currentBranch); } branchAnalyzers.get(currentBranch).notifySmell(smell); if (!previousCommit.equals(commit) && isLastBranchCommit(previousCommit, previousBranch)) { finalizeBranch(previousBranch); branchAnalyzers.remove(previousBranch); } } for (int branchId : branchAnalyzers.keySet()) { finalizeBranch(branchId); } } BranchAwareSmellTypeAnalysis(int projectId, Persistence persistence, Iterator<Map<String, Object>> smells,
                                 String smellType, SmellDuplicationChecker duplicationChecker,
                                 CommitQueries commitQueries, SmellQueries smellQueries, BranchQueries branchQueries); @Override void query(); }
BranchAwareSmellTypeAnalysis implements Query { @Override public void query() throws QueryException { Smell smell; Commit previousCommit; Commit commit = Commit.empty(); Integer previousBranch; Integer currentBranch = -1; Map<String, Object> instance; while (smells.hasNext()) { instance = smells.next(); previousCommit = commit; previousBranch = currentBranch; commit = Commit.fromInstance(instance); smell = Smell.fromPaprikaInstance(instance, smellType); try { currentBranch = fetchCommitBranch(commit); } catch (BranchNotFoundException e) { logger.warn("[" + projectId + "] ==> Unable to guess branch for commit (" + commit.sha + "), skipping", e.getMessage()); continue; } if (!branchAnalyzers.containsKey(currentBranch)) { logger.debug("[" + projectId + "] => Initializing new branch: " + currentBranch); initializeBranch(currentBranch); } commit.setBranchOrdinal(fetchCommitOrdinal(currentBranch, commit)); branchAnalyzers.get(currentBranch).notifyCommit(commit); if (!previousCommit.equals(commit)) { synchronizeMergeSmells(commit, currentBranch); } branchAnalyzers.get(currentBranch).notifySmell(smell); if (!previousCommit.equals(commit) && isLastBranchCommit(previousCommit, previousBranch)) { finalizeBranch(previousBranch); branchAnalyzers.remove(previousBranch); } } for (int branchId : branchAnalyzers.keySet()) { finalizeBranch(branchId); } } BranchAwareSmellTypeAnalysis(int projectId, Persistence persistence, Iterator<Map<String, Object>> smells,
                                 String smellType, SmellDuplicationChecker duplicationChecker,
                                 CommitQueries commitQueries, SmellQueries smellQueries, BranchQueries branchQueries); @Override void query();  }