OrdinalSmellTypeAnalysis implements Query { @Override public void query() throws QueryException { Smell smell; Commit commit; Map<String, Object> instance; BranchAnalyzer branchAnalyzer = new BranchAnalyzer( projectId, persistence, duplicationChecker, commitQueries, smellQueries ); while (smells.hasNext()) { instance = smells.next(); smell = Smell.fromPaprikaInstance(instance, smellType); commit = Commit.fromInstance(instance); branchAnalyzer.notifyCommit(commit); branchAnalyzer.notifySmell(smell); } branchAnalyzer.notifyEnd(); } OrdinalSmellTypeAnalysis(int projectId, Persistence persistence, Iterator<Map<String, Object>> smells,
                             String smellType, SmellDuplicationChecker duplicationChecker,
                             CommitQueries commitQueries, SmellQueries smellQueries); @Override void query();  }
@Test(expected = QueryException.class) public void testNoEndCommitFoundWillThrow() throws QueryException { addSmell(firstCommit, firstSmell); mockNoEndCommit(); getAnalysis().query(); debugSmellInsertions(); }
@Test public void handlePresenceAndIntroductionOnSingleCommitAlsoLastCommit() throws QueryException { addSmell(firstCommit, firstSmell); mockEndCommit(firstCommit.sha); getAnalysis().query(); debugSmellInsertions(); verify(persistence, times(1)).execute(any()); verify(smellQueries).smellInsertionStatement(projectId, firstSmell); verify(persistence, times(2)).addStatements(any()); verify(smellQueries).smellCategoryInsertionStatement(projectId, firstCommit.sha, firstSmell, SmellCategory.PRESENCE); verify(smellQueries).smellCategoryInsertionStatement(projectId, firstCommit.sha, firstSmell, SmellCategory.INTRODUCTION); }
@Test public void handlePresenceAndIntroductionOnSingleCommitNotLastCommit() throws QueryException { addSmell(firstCommit, firstSmell); String lastCommitSha = "another"; mockGapCommit(lastCommitSha); mockEndCommit(lastCommitSha); getAnalysis().query(); debugSmellInsertions(); verify(persistence, times(1)).execute(any()); verify(smellQueries).smellInsertionStatement(projectId, firstSmell); verify(persistence, times(3)).addStatements(any()); verify(smellQueries).smellCategoryInsertionStatement(projectId, firstCommit.sha, firstSmell, SmellCategory.PRESENCE); verify(smellQueries).smellCategoryInsertionStatement(projectId, firstCommit.sha, firstSmell, SmellCategory.INTRODUCTION); verify(smellQueries).smellCategoryInsertionStatement(projectId, lastCommitSha, firstSmell, SmellCategory.REFACTOR); }
@Test public void handleIntroductionAndRefactoring() throws QueryException { addSmell(firstCommit, firstSmell); addSmell(secondCommit, secondSmell); mockEndCommit(secondCommit.sha); getAnalysis().query(); debugSmellInsertions(); verify(persistence, times(2)).execute(any()); verify(smellQueries).smellInsertionStatement(projectId, firstSmell); verify(smellQueries).smellInsertionStatement(projectId, secondSmell); verify(persistence, times(5)).addStatements(any()); verify(smellQueries).smellCategoryInsertionStatement(projectId, firstCommit.sha, firstSmell, SmellCategory.PRESENCE); verify(smellQueries).smellCategoryInsertionStatement(projectId, firstCommit.sha, firstSmell, SmellCategory.INTRODUCTION); verify(smellQueries).smellCategoryInsertionStatement(projectId, secondCommit.sha, secondSmell, SmellCategory.PRESENCE); verify(smellQueries).smellCategoryInsertionStatement(projectId, secondCommit.sha, secondSmell, SmellCategory.INTRODUCTION); verify(smellQueries).smellCategoryInsertionStatement(projectId, secondCommit.sha, firstSmell, SmellCategory.REFACTOR); }
@Test public void handleIntroductionOnly() throws QueryException { addSmell(firstCommit, firstSmell); addSmell(secondCommit, firstSmell); addSmell(secondCommit, secondSmell); mockEndCommit(secondCommit.sha); getAnalysis().query(); debugSmellInsertions(); verify(persistence, times(2)).execute(any()); verify(smellQueries).smellInsertionStatement(projectId, firstSmell); verify(smellQueries).smellInsertionStatement(projectId, secondSmell); verify(persistence, times(5)).addStatements(any()); verify(smellQueries).smellCategoryInsertionStatement(projectId, firstCommit.sha, firstSmell, SmellCategory.PRESENCE); verify(smellQueries).smellCategoryInsertionStatement(projectId, firstCommit.sha, firstSmell, SmellCategory.INTRODUCTION); verify(smellQueries).smellCategoryInsertionStatement(projectId, secondCommit.sha, firstSmell, SmellCategory.PRESENCE); verify(smellQueries).smellCategoryInsertionStatement(projectId, secondCommit.sha, secondSmell, SmellCategory.PRESENCE); verify(smellQueries).smellCategoryInsertionStatement(projectId, secondCommit.sha, secondSmell, SmellCategory.INTRODUCTION); }
@Test public void handleRefactorOnly() throws QueryException { addSmell(firstCommit, firstSmell); addSmell(firstCommit, secondSmell); addSmell(secondCommit, firstSmell); mockEndCommit(secondCommit.sha); getAnalysis().query(); debugSmellInsertions(); verify(persistence, times(2)).execute(any()); verify(smellQueries).smellInsertionStatement(projectId, firstSmell); verify(smellQueries).smellInsertionStatement(projectId, secondSmell); verify(persistence, times(6)).addStatements(any()); verify(smellQueries).smellCategoryInsertionStatement(projectId, firstCommit.sha, firstSmell, SmellCategory.PRESENCE); verify(smellQueries).smellCategoryInsertionStatement(projectId, firstCommit.sha, firstSmell, SmellCategory.INTRODUCTION); verify(smellQueries).smellCategoryInsertionStatement(projectId, firstCommit.sha, secondSmell, SmellCategory.PRESENCE); verify(smellQueries).smellCategoryInsertionStatement(projectId, firstCommit.sha, secondSmell, SmellCategory.INTRODUCTION); verify(smellQueries).smellCategoryInsertionStatement(projectId, secondCommit.sha, firstSmell, SmellCategory.PRESENCE); verify(smellQueries).smellCategoryInsertionStatement(projectId, secondCommit.sha, secondSmell, SmellCategory.REFACTOR); }
@Test public void handleNoChange() throws QueryException { addSmell(firstCommit, firstSmell); addSmell(secondCommit, firstSmell); mockEndCommit(secondCommit.sha); getAnalysis().query(); debugSmellInsertions(); verify(persistence, times(1)).execute(any()); verify(smellQueries).smellInsertionStatement(projectId, firstSmell); verify(persistence, times(3)).addStatements(any()); verify(smellQueries).smellCategoryInsertionStatement(projectId, firstCommit.sha, firstSmell, SmellCategory.PRESENCE); verify(smellQueries).smellCategoryInsertionStatement(projectId, firstCommit.sha, firstSmell, SmellCategory.INTRODUCTION); verify(smellQueries).smellCategoryInsertionStatement(projectId, secondCommit.sha, firstSmell, SmellCategory.PRESENCE); }
@Test public void handleCommitGap() throws QueryException { addSmell(firstCommit, firstSmell); addSmell(firstCommit, secondSmell); addSmell(thirdCommit, secondSmell); String gapCommitSha = "someSha"; mockGapCommit(gapCommitSha); mockEndCommit(thirdCommit.sha); getAnalysis().query(); debugSmellInsertions(); verify(persistence, times(3)).execute(any()); verify(smellQueries).smellInsertionStatement(projectId, firstSmell); verify(smellQueries, times(2)).smellInsertionStatement(projectId, secondSmell); verify(persistence, times(8)).addStatements(any()); verify(smellQueries).smellCategoryInsertionStatement(projectId, firstCommit.sha, firstSmell, SmellCategory.PRESENCE); verify(smellQueries).smellCategoryInsertionStatement(projectId, firstCommit.sha, firstSmell, SmellCategory.INTRODUCTION); verify(smellQueries).smellCategoryInsertionStatement(projectId, firstCommit.sha, secondSmell, SmellCategory.PRESENCE); verify(smellQueries).smellCategoryInsertionStatement(projectId, firstCommit.sha, secondSmell, SmellCategory.INTRODUCTION); verify(smellQueries).smellCategoryInsertionStatement(projectId, gapCommitSha, firstSmell, SmellCategory.REFACTOR); verify(smellQueries).smellCategoryInsertionStatement(projectId, gapCommitSha, secondSmell, SmellCategory.REFACTOR); verify(smellQueries).smellCategoryInsertionStatement(projectId, thirdCommit.sha, secondSmell, SmellCategory.PRESENCE); verify(smellQueries).smellCategoryInsertionStatement(projectId, thirdCommit.sha, secondSmell, SmellCategory.INTRODUCTION); }
@Test public void handleMultipleMissingCommits() throws QueryException { Commit anotherCommit = new Commit("thirdSha", 24); addSmell(firstCommit, firstSmell); addSmell(firstCommit, secondSmell); addSmell(anotherCommit, secondSmell); String gapCommitSha = "someSha"; mockGapCommit(gapCommitSha); mockEndCommit(anotherCommit.sha); getAnalysis().query(); debugSmellInsertions(); verify(persistence, times(3)).execute(any()); verify(smellQueries).smellInsertionStatement(projectId, firstSmell); verify(smellQueries, times(2)).smellInsertionStatement(projectId, secondSmell); verify(persistence, times(8)).addStatements(any()); verify(smellQueries).smellCategoryInsertionStatement(projectId, firstCommit.sha, firstSmell, SmellCategory.PRESENCE); verify(smellQueries).smellCategoryInsertionStatement(projectId, firstCommit.sha, firstSmell, SmellCategory.INTRODUCTION); verify(smellQueries).smellCategoryInsertionStatement(projectId, firstCommit.sha, secondSmell, SmellCategory.PRESENCE); verify(smellQueries).smellCategoryInsertionStatement(projectId, firstCommit.sha, secondSmell, SmellCategory.INTRODUCTION); verify(smellQueries).smellCategoryInsertionStatement(projectId, gapCommitSha, firstSmell, SmellCategory.REFACTOR); verify(smellQueries).smellCategoryInsertionStatement(projectId, gapCommitSha, secondSmell, SmellCategory.REFACTOR); verify(smellQueries).smellCategoryInsertionStatement(projectId, anotherCommit.sha, secondSmell, SmellCategory.PRESENCE); verify(smellQueries).smellCategoryInsertionStatement(projectId, anotherCommit.sha, secondSmell, SmellCategory.INTRODUCTION); }
@Test public void handleMissingGapCommit() throws QueryException { addSmell(firstCommit, firstSmell); addSmell(firstCommit, secondSmell); addSmell(thirdCommit, secondSmell); mockNoGapCommit(); mockEndCommit(thirdCommit.sha); getAnalysis().query(); debugSmellInsertions(); verify(persistence, times(2)).execute(any()); verify(smellQueries).smellInsertionStatement(projectId, firstSmell); verify(smellQueries).smellInsertionStatement(projectId, secondSmell); verify(persistence, times(6)).addStatements(any()); verify(smellQueries).smellCategoryInsertionStatement(projectId, firstCommit.sha, firstSmell, SmellCategory.PRESENCE); verify(smellQueries).smellCategoryInsertionStatement(projectId, firstCommit.sha, firstSmell, SmellCategory.INTRODUCTION); verify(smellQueries).smellCategoryInsertionStatement(projectId, firstCommit.sha, secondSmell, SmellCategory.PRESENCE); verify(smellQueries).smellCategoryInsertionStatement(projectId, firstCommit.sha, secondSmell, SmellCategory.PRESENCE); verify(smellQueries).smellCategoryInsertionStatement(projectId, thirdCommit.sha, secondSmell, SmellCategory.PRESENCE); verify(smellQueries).lostSmellCategoryInsertionStatement(projectId, firstSmell, SmellCategory.REFACTOR, secondCommit.ordinal, thirdCommit.ordinal); }
@Test public void handleRenamedSmell() throws QueryException { ArgumentCaptor<Smell> smellCaptor = ArgumentCaptor.forClass(Smell.class); addSmell(firstCommit, firstSmell); addSmell(secondCommit, secondSmell); Smell expectedSecondSmell = mockSmellRenamed(secondCommit, secondSmell, firstSmell); mockSmellId(expectedSecondSmell); mockEndCommit(secondCommit.sha); getAnalysis().query(); debugSmellInsertions(); verify(persistence, times(2)).execute(any()); verify(smellQueries).smellInsertionStatement(projectId, firstSmell); verify(smellQueries, times(2)).smellInsertionStatement(eq(projectId), smellCaptor.capture()); Smell renamed = smellCaptor.getAllValues().get(1); assertEquals(expectedSecondSmell, renamed); assertEquals(firstSmell, renamed.parent); verify(persistence, times(3)).addStatements(any()); verify(smellQueries).smellCategoryInsertionStatement(projectId, firstCommit.sha, firstSmell, SmellCategory.PRESENCE); verify(smellQueries).smellCategoryInsertionStatement(projectId, firstCommit.sha, firstSmell, SmellCategory.INTRODUCTION); verify(smellQueries).smellCategoryInsertionStatement(projectId, secondCommit.sha, expectedSecondSmell, SmellCategory.PRESENCE); }
@Test public void handleRenamedSmellMultipleCommits() throws QueryException { ArgumentCaptor<Smell> smellCaptor = ArgumentCaptor.forClass(Smell.class); addSmell(firstCommit, firstSmell); addSmell(secondCommit, secondSmell); addSmell(thirdCommit, secondSmell); Smell expectedSecondSmell = mockSmellRenamed(secondCommit, secondSmell, firstSmell); mockSmellId(expectedSecondSmell); mockSmellRenamed(thirdCommit, secondSmell, firstSmell); mockEndCommit(thirdCommit.sha); getAnalysis().query(); debugSmellInsertions(); verify(persistence, times(2)).execute(any()); verify(smellQueries).smellInsertionStatement(projectId, firstSmell); verify(smellQueries, times(2)).smellInsertionStatement(eq(projectId), smellCaptor.capture()); Smell renamed = smellCaptor.getAllValues().get(1); assertEquals(expectedSecondSmell, renamed); assertEquals(firstSmell, renamed.parent); verify(persistence, times(4)).addStatements(any()); verify(smellQueries).smellCategoryInsertionStatement(projectId, firstCommit.sha, firstSmell, SmellCategory.PRESENCE); verify(smellQueries).smellCategoryInsertionStatement(projectId, firstCommit.sha, firstSmell, SmellCategory.INTRODUCTION); verify(smellQueries).smellCategoryInsertionStatement(projectId, secondCommit.sha, expectedSecondSmell, SmellCategory.PRESENCE); verify(smellQueries).smellCategoryInsertionStatement(projectId, thirdCommit.sha, expectedSecondSmell, SmellCategory.PRESENCE); }
@Test public void handleFirstCommitIsNotTheFirstOrdinal() throws QueryException { addSmell(thirdCommit, firstSmell); mockGapCommit(firstCommit.sha); mockEndCommit(thirdCommit.sha); getAnalysis().query(); verify(persistence, times(1)).execute(any()); verify(smellQueries).smellInsertionStatement(projectId, firstSmell); verify(persistence, times(2)).addStatements(any()); verify(smellQueries).smellCategoryInsertionStatement(projectId, thirdCommit.sha, firstSmell, SmellCategory.PRESENCE); verify(smellQueries).smellCategoryInsertionStatement(projectId, thirdCommit.sha, firstSmell, SmellCategory.INTRODUCTION); }
@Test public void testRenamedSmellsBackToOriginal() throws QueryException { Commit A = new Commit("0-A", 0); Commit B = new Commit("0-B", 1); Commit C = new Commit("0-C", 2); Commit D = new Commit("0-D", 3); Commit E = new Commit("0-E", 4); Commit F = new Commit("0-F", 5); Commit G = new Commit("0-G", 6); addSmell(A, firstSmell); addSmell(B, secondSmell); addSmell(C, secondSmell); addSmell(D, firstSmell); addSmell(E, firstSmell); addSmell(F, firstSmell); addSmell(G, firstSmell); mockEndCommit(G.sha); Smell expectedSecondSmell = mockSmellRenamed(B, secondSmell, firstSmell); mockSmellRenamed(C, secondSmell, firstSmell); Smell expectedRenamedFirstSmell = mockSmellRenamed(D, firstSmell, secondSmell); mockSmellRenamed(E, firstSmell, secondSmell); mockSmellRenamed(F, firstSmell, secondSmell); mockSmellRenamed(G, firstSmell, secondSmell); mockSmellId(expectedSecondSmell); expectedRenamedFirstSmell.parent = expectedSecondSmell; mockSmellId(expectedRenamedFirstSmell); getAnalysis().query(); debugSmellInsertions(); verify(persistence, times(3)).execute(any()); verify(smellQueries).smellInsertionStatement(projectId, firstSmell); verify(smellQueries).smellInsertionStatement(projectId, expectedSecondSmell); verify(smellQueries).smellInsertionStatement(projectId, expectedRenamedFirstSmell); verify(persistence, times(8)).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, expectedSecondSmell, SmellCategory.PRESENCE); verify(smellQueries).smellCategoryInsertionStatement(projectId, C.sha, expectedSecondSmell, SmellCategory.PRESENCE); verify(smellQueries).smellCategoryInsertionStatement(projectId, D.sha, expectedRenamedFirstSmell, SmellCategory.PRESENCE); verify(smellQueries).smellCategoryInsertionStatement(projectId, E.sha, expectedRenamedFirstSmell, SmellCategory.PRESENCE); verify(smellQueries).smellCategoryInsertionStatement(projectId, F.sha, expectedRenamedFirstSmell, SmellCategory.PRESENCE); verify(smellQueries).smellCategoryInsertionStatement(projectId, G.sha, expectedRenamedFirstSmell, SmellCategory.PRESENCE); }