mbien commented on code in PR #4142:
URL: https://github.com/apache/netbeans/pull/4142#discussion_r884261162


##########
java/java.source.base/test/unit/src/org/netbeans/api/java/source/ElementUtilitiesTest.java:
##########
@@ -530,4 +536,42 @@ private void handleDecl() {
                 }.scan(controller.getCompilationUnit(), null);
             }}, true);
     }
+
+
+    public void testGetMembers() throws Exception {
+        prepareTest();
+        SourceUtilsTestUtil.setSourceLevel(testFO, "8");
+        TestUtilities.copyStringToFile(FileUtil.toFile(testFO),
+                "package test;" +
+                "public class A implements Runnable {" +
+                "    private final int FIELD1 = 0;" +
+                "    private final int FIELD2 = 1;" +
+                "    public void run() {}" +
+                "}");
+        SourceLevelQueryImpl.sourceLevel = "8";
+
+        JavaSource javaSource = JavaSource.forFileObject(testFO);
+        javaSource.runUserActionTask((CompilationController controller) -> {
+            controller.toPhase(JavaSource.Phase.RESOLVED);
+
+            ClassTree outerTree = 
(ClassTree)controller.getCompilationUnit().getTypeDecls().get(0);
+            TreePath outerPath = new TreePath(new 
TreePath(controller.getCompilationUnit()), outerTree);
+            TypeMirror mirror = controller.getTrees().getTypeMirror(outerPath);
+            assertNotNull(mirror);
+
+            ElementUtilities utils = controller.getElementUtilities();
+            Set<String> list = new HashSet<>();
+            utils.getMembers(mirror, null).forEach((e) -> 
list.add(e.toString()));
+
+            List<String> good = Arrays.asList("getClass()",
+                    "hashCode()", "equals(java.lang.Object)", "clone()", 
"toString()", "notify()",
+                    "notifyAll()", "wait(long)", "wait(long,int)", "wait()", 
"finalize()", "A()",
+                    "FIELD1", "FIELD2", "run()", "this", "super", "class");
+            assertEquals(good.size(), list.size());
+            assertTrue(list.containsAll(good));
+
+        }, true);
+    }

Review Comment:
   hi @jlahoda I don't want to steal your time from doing record patterns :) 
But would this be a good template to test `ElementUtilities.getMembers()`? 
Compiler phase RESOLVED is the correct phase?
   
   A LSP test fails after this optimization here is applied and those methods 
are not directly tested as far as I see. I want to reproduce it in a proper 
test instead of going through the high level 
`ServerTest.testSourceActionDelegateMethod` (i also have to rebuild everything 
to make the LSP code pick the changes up which is annoying/time consuming)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to