From 9ab6db353e8fbe7a7b40b0c04b9ee9689c383d98 Mon Sep 17 00:00:00 2001 From: tsantalis Date: Sat, 6 Aug 2022 08:45:53 -0400 Subject: [PATCH] Added tests for anonymous class locators --- .../util/CodeElementLocatorTest.java | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/src/test/java/org/codetracker/util/CodeElementLocatorTest.java b/src/test/java/org/codetracker/util/CodeElementLocatorTest.java index 7d95a8fc76f..d403af1abd9 100644 --- a/src/test/java/org/codetracker/util/CodeElementLocatorTest.java +++ b/src/test/java/org/codetracker/util/CodeElementLocatorTest.java @@ -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(); @@ -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); + } + } }