SmellDuplicationChecker { public Smell original(Smell instance, Commit commit, Commit previous) { logger.trace("==> Trying to guess original smell for: " + instance); int index = fileRenamings.indexOf(FileRenameEntry.fromSmell(instance, commit)); if (index > -1) { logger.trace(" ==> Guessing new original smell!"); return guessOriginalSmell(instance, previous, fileRenamings.get(index)); } logger.trace(" ==> No original smell found"); return null; } SmellDuplicationChecker(int projectId, Persistence persistence, QueryEngine queryEngine); Smell original(Smell instance, Commit commit, Commit previous); static final String QUALIFIED_NAME; }
@Test public void wrongCommitWillNotBeGuessed() { Smell instance = new Smell("MIM", "d.e.f", sameCommit.newFile); Commit commit = new Commit("anyothercommit", 1); SmellDuplicationChecker checker = getDuplicationChecker(); Smell original = checker.original(instance, commit, parent); assertNull(original); }
@Test public void wrongFileWillNotBeGuessed() { Smell instance = new Smell("MIM", "d.e.f", "anyFile"); Commit commit = new Commit(sameCommit.sha1, 1); SmellDuplicationChecker checker = getDuplicationChecker(); Smell original = checker.original(instance, commit, parent); assertNull(original); }
@Test public void parsingErrorWillNotBeGuessed() { Smell instance = new Smell("MIM", "method#a.b.d$myInnerClass$AnotherInnerClass", "anyOtherFile"); Commit commit = new Commit(sameCommit.sha1, 1); SmellDuplicationChecker checker = getDuplicationChecker(); Smell original = checker.original(instance, commit, parent); assertNull(original); }
@Test public void oldInstanceNameIsCorrectlyGuessedBothInnerClassAndMethod() { Smell instance = new Smell("MIM", "method#a.b.d$myInnerClass$AnotherInnerClass", fileRename.newFile); Commit commit = new Commit(sameCommit.sha1, 1); mockPreviousQualifiedName("a.b.c"); SmellDuplicationChecker checker = getDuplicationChecker(); Smell original = checker.original(instance, commit, parent); assertNotNull(original); assertEquals("method#a.b.c$myInnerClass$AnotherInnerClass", original.instance); assertEquals(fileRename.oldFile, original.file); }
@Test public void oldInstanceNameIsCorrectlyGuessedNoInnerClass() { Smell instance = new Smell("MIM", "method#d.e.f", sameOldFile.newFile); Commit commit = new Commit(sameOldFile.sha1, 1); mockPreviousQualifiedName("a.b.c"); SmellDuplicationChecker checker = getDuplicationChecker(); Smell original = checker.original(instance, commit, parent); assertNotNull(original); assertEquals("method#a.b.c", original.instance); assertEquals(sameOldFile.oldFile, original.file); }
@Test public void oldInstanceNameIsCorrectlyGuessedNoMethod() { Smell instance = new Smell("MIM", "d.e.f$myInnerClass$AnotherInnerClass", sameOldFile.newFile); Commit commit = new Commit(sameOldFile.sha1, 1); mockPreviousQualifiedName("a.b.c"); SmellDuplicationChecker checker = getDuplicationChecker(); Smell original = checker.original(instance, commit, parent); assertNotNull(original); assertEquals("a.b.c$myInnerClass$AnotherInnerClass", original.instance); assertEquals(sameOldFile.oldFile, original.file); }
@Test public void oldInstanceNameIsCorrectlyGuessedNoMethodNoInnerClass() { Smell instance = new Smell("MIM", "g.h.i", sameCommit.newFile); Commit commit = new Commit(sameCommit.sha1, 1); mockPreviousQualifiedName("d.e.f"); SmellDuplicationChecker checker = getDuplicationChecker(); Smell original = checker.original(instance, commit, parent); assertNotNull(original); assertEquals("d.e.f", original.instance); assertEquals(sameCommit.oldFile, original.file); }
@Test public void sameRenamingInAnotherIsTypeDependant() { Smell instance = new Smell("MIM", "d.e.f", sameCommit.newFile); Smell newInstanceFurtherCommit = new Smell("HMU", instance.instance, instance.file); Commit commit = new Commit(sameCommit.sha1, 1); SmellDuplicationChecker checker = getDuplicationChecker(); Smell original = checker.original(instance, commit, parent); Commit new_commit = new Commit("newSha", 2); Smell secondOriginal = checker.original(newInstanceFurtherCommit, new_commit, commit); assertNotNull(original); assertNull(secondOriginal); }
@Test public void sameRenamingBackAndForth() { String anotherSha = "commit_3"; addRenameEntry(new SmellDuplicationChecker.FileRenameEntry(anotherSha, sameCommit.newFile, sameCommit.oldFile)); Smell original = new Smell("MIM", "d.e.f", sameCommit.oldFile); Smell firstRename = new Smell("MIM", "g.h.i", sameCommit.newFile); Smell renameEqualToFirst = new Smell("MIM", original.instance, original.file); Commit commit = new Commit(sameCommit.sha1, 1); mockPreviousQualifiedName("d.e.f"); SmellDuplicationChecker checker = getDuplicationChecker(); Smell expectedOriginal = checker.original(firstRename, commit, parent); mockPreviousQualifiedName("g.h.i"); Commit new_commit = new Commit(anotherSha, 2); Smell expectedFirstRename = checker.original(renameEqualToFirst, new_commit, commit); assertNotNull(expectedOriginal); assertNotNull(expectedFirstRename); assertEquals(expectedOriginal, original); assertEquals(expectedFirstRename, firstRename); assertEquals(original, renameEqualToFirst); }
@Test public void java2groovyUpperFolder() { Smell instance = new Smell("MIM", "method#a.b.d$myInnerClass$AnotherInnerClass", j2gRename.newFile); Commit commit = new Commit(j2gRename.sha1, 1); mockPreviousQualifiedName("a.b.c"); SmellDuplicationChecker checker = getDuplicationChecker(); Smell original = checker.original(instance, commit, parent); assertNotNull(original); assertEquals("method#a.b.c$myInnerClass$AnotherInnerClass", original.instance); assertEquals(j2gRename.oldFile, original.file); }
@Test public void groovy2JavaUpperFolder() { Smell instance = new Smell("MIM", "method#a.b.d$myInnerClass$AnotherInnerClass", g2jRename.newFile); Commit commit = new Commit(g2jRename.sha1, 1); mockPreviousQualifiedName("a.b.c"); SmellDuplicationChecker checker = getDuplicationChecker(); Smell original = checker.original(instance, commit, parent); assertNotNull(original); assertEquals("method#a.b.c$myInnerClass$AnotherInnerClass", original.instance); assertEquals(g2jRename.oldFile, original.file); }