@Test public void testMergeIsLastBranchCommitBranchesSeparateSmells() throws QueryException { Commit A = new Commit("0-A", 0); Commit B = new Commit("1-B", 1); Commit C = new Commit("3-C", 2); Commit D = new Commit("2-D", 3); Commit E = new Commit("1-E", 4); Commit F = new Commit("0-F", 5); mockCommitSmells(A, firstSmell, secondSmell); mockCommitSmells(B, firstSmell); mockCommitSmells(C, firstSmell, thirdSmell); mockCommitSmells(D, firstSmell, thirdSmell); mockCommitSmells(E, firstSmell, thirdSmell); mockCommitSmells(F, firstSmell, thirdSmell); mockCommitBranch(A, 0, 0); mockCommitBranch(B, 1, 0); mockCommitBranch(C, 3, 0); mockCommitBranch(D, 2, 0); mockCommitBranch(E, 1, 1); mockCommitBranch(F, 0, 1); mockLastBranchCommit(0, F); mockLastBranchCommit(1, E); mockLastBranchCommit(2, D); mockLastBranchCommit(3, C); mockMergeCommit(F, E); mockMergeCommit(E, D); mockMergeCommit(D, C); mockBranchParentCommitSmells(1, firstSmell, secondSmell); mockBranchParentCommitSmells(2, firstSmell); mockBranchParentCommitSmells(3, firstSmell); getAnalysis().query(); verify(persistence, times(3)).execute(any()); verify(smellQueries).smellInsertionStatement(projectId, firstSmell); verify(smellQueries).smellInsertionStatement(projectId, secondSmell); verify(smellQueries).smellInsertionStatement(projectId, thirdSmell); verify(persistence, times(15)).addStatements(any()); verify(smellQueries).smellCategoryInsertionStatement(projectId, A.sha, firstSmell, SmellCategory.PRESENCE); verify(smellQueries).smellCategoryInsertionStatement(projectId, A.sha, firstSmell, SmellCategory.INTRODUCTION); verify(smellQueries).smellCategoryInsertionStatement(projectId, A.sha, secondSmell, SmellCategory.PRESENCE); verify(smellQueries).smellCategoryInsertionStatement(projectId, A.sha, secondSmell, SmellCategory.INTRODUCTION); verify(smellQueries).smellCategoryInsertionStatement(projectId, B.sha, firstSmell, SmellCategory.PRESENCE); verify(smellQueries).smellCategoryInsertionStatement(projectId, B.sha, secondSmell, SmellCategory.REFACTOR); verify(smellQueries).smellCategoryInsertionStatement(projectId, E.sha, firstSmell, SmellCategory.PRESENCE); verify(smellQueries).smellCategoryInsertionStatement(projectId, E.sha, thirdSmell, SmellCategory.PRESENCE); verify(smellQueries).smellCategoryInsertionStatement(projectId, C.sha, firstSmell, SmellCategory.PRESENCE); verify(smellQueries).smellCategoryInsertionStatement(projectId, C.sha, thirdSmell, SmellCategory.PRESENCE); verify(smellQueries).smellCategoryInsertionStatement(projectId, C.sha, thirdSmell, SmellCategory.INTRODUCTION); verify(smellQueries).smellCategoryInsertionStatement(projectId, D.sha, firstSmell, SmellCategory.PRESENCE); verify(smellQueries).smellCategoryInsertionStatement(projectId, D.sha, thirdSmell, SmellCategory.PRESENCE); verify(smellQueries).smellCategoryInsertionStatement(projectId, F.sha, firstSmell, SmellCategory.PRESENCE); verify(smellQueries).smellCategoryInsertionStatement(projectId, F.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();  }