Uploaded image for project: 'NetBeans'
  1. NetBeans
  2. NETBEANS-4842

Go To Source broken with JUnit5 (and Gradle)

    XMLWordPrintableJSON

    Details

      Description

      JUnit4 and TestNG logs tested method names like:

      testResults.MainTest > testA
      

      However, JUnit5 adds the method's parameters, like this:

      testResults.SecondaryTest > testA()
      
      testResults.SecondaryTest > testB()
      
      testResults.SecondaryTest > [1] 1, 2
      

      The last one is a result of using

      @ParametrizedTest
      @MethodSource("generate")
      public void testC(String a, String b) {
             // do something clever
          }
      

      Such method names are not understood by the "Go To Source" functionality.

      For gradle projects a quick work-around may be the following change to clean method names:

      --- a/java/gradle.java/src/org/netbeans/modules/gradle/java/api/output/LocationOpener.java
      +++ b/java/gradle.java/src/org/netbeans/modules/gradle/java/api/output/LocationOpener.java
      @@ -80,7 +80,18 @@ public final class LocationOpener {
               }
           }
       
      -   private int getMethodLine(final FileObject fo, final String methodName) {
      +   private static String stripMethodParams(String methodNameWithParams) {
      +        final int paramsIndex = methodNameWithParams.indexOf("(");
      +        String cleanName = methodNameWithParams;
      +        if (paramsIndex > 0) {
      +            cleanName = methodNameWithParams.substring(0, paramsIndex);
      +        }
      +        return cleanName;
      +    }
      +
      +    private int getMethodLine(final FileObject fo, final String methodNameWithParams) {
      +        String methodName = stripMethodParams(methodNameWithParams);
               final int[] line = new int[1];
               JavaSource javaSource = JavaSource.forFileObject(fo);
               if (javaSource != null) {
      
      

      Certainly, it'd much better if the LocationOpener became able interpret and distinguish parameters and thus able navigate between overloaded methods as well.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                lkishalmi Laszlo Kishalmi
                Reporter:
                ratcashdev Ratcash Developer
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 0.5h
                  0.5h