Skip to content

Commit

Permalink
Added tests for anonymous class locators
Browse files Browse the repository at this point in the history
  • Loading branch information
tsantalis committed Aug 6, 2022
1 parent d6d2d35 commit 9ab6db3
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/test/java/org/codetracker/util/CodeElementLocatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ public void testInnerClassCatchExceptionLocator() throws Exception {
Assert.assertEquals(codeElement.getClass(), Variable.class);
}
}

@Test
public void testInnerClassEnumConstantLocator() throws Exception {
GitService gitService = new GitServiceImpl();
Expand All @@ -283,4 +284,52 @@ public void testInnerClassEnumConstantLocator() throws Exception {
Assert.assertEquals(codeElement.getClass(), Attribute.class);
}
}

@Test
public void testAnonymousClassAttributeLocator() throws Exception {
GitService gitService = new GitServiceImpl();
final String filePath = "src/main/java/com/puppycrawl/tools/checkstyle/gui/TreeTable.java";
final String commitId = "119fd4fb33bef9f5c66fc950396669af842c21a3";
final String name = "serialVersionUID";
final int lineNumber = 104;
try (Repository repository = gitService.cloneIfNotExists(FOLDER_TO_CLONE + "checkstyle\\checkstyle",
"https://github.com/checkstyle/checkstyle.git")){
CodeElementLocator locator = new CodeElementLocator(repository, commitId, filePath, name, lineNumber);
CodeElement codeElement = locator.locate();
Assert.assertNotNull(codeElement);
Assert.assertEquals(codeElement.getClass(), Attribute.class);
}
}

@Test
public void testAnonymousClassMethodLocator() throws Exception {
GitService gitService = new GitServiceImpl();
final String filePath = "src/main/java/com/puppycrawl/tools/checkstyle/gui/TreeTable.java";
final String commitId = "119fd4fb33bef9f5c66fc950396669af842c21a3";
final String name = "actionPerformed";
final int lineNumber = 107;
try (Repository repository = gitService.cloneIfNotExists(FOLDER_TO_CLONE + "checkstyle\\checkstyle",
"https://github.com/checkstyle/checkstyle.git")){
CodeElementLocator locator = new CodeElementLocator(repository, commitId, filePath, name, lineNumber);
CodeElement codeElement = locator.locate();
Assert.assertNotNull(codeElement);
Assert.assertEquals(codeElement.getClass(), Method.class);
}
}

@Test
public void testAnonymousClassMethodParameterLocator() throws Exception {
GitService gitService = new GitServiceImpl();
final String filePath = "src/main/java/com/puppycrawl/tools/checkstyle/gui/TreeTable.java";
final String commitId = "119fd4fb33bef9f5c66fc950396669af842c21a3";
final String name = "event";
final int lineNumber = 107;
try (Repository repository = gitService.cloneIfNotExists(FOLDER_TO_CLONE + "checkstyle\\checkstyle",
"https://github.com/checkstyle/checkstyle.git")){
CodeElementLocator locator = new CodeElementLocator(repository, commitId, filePath, name, lineNumber);
CodeElement codeElement = locator.locate();
Assert.assertNotNull(codeElement);
Assert.assertEquals(codeElement.getClass(), Variable.class);
}
}
}

0 comments on commit 9ab6db3

Please sign in to comment.