GRECLIPSE
  1. GRECLIPSE
  2. GRECLIPSE-893

New Groovy JUnit Test case wizard problem generating methods to test static methods

    Details

    • Type: Bug Bug
    • Status: Resolved Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.1.0Release
    • Fix Version/s: 2.1.1Release
    • Component/s: None
    • Labels:
      None
    • Number of attachments :
      0

      Description

      Create a groovy class:

      package Y
      
      class X {
      	def foo() {
      		
      	}
      	def foo1(a) {
      		
      	}
      	def foo2(a,b) {
      		
      	}
      	def foo3(a,b,c) {
      		
      	}
      }
      

      Now invoke the New Groovy Test Case wizard and select the above class as the one to test. Click next and select the creation of the test methods.

      The resulting file will look like this. Notice that the last test method is outside the definition of XTest:

      package Y;
      import static org.junit.Assert.*;
      
      import java.lang.*;
      
      import org.junit.Test;
      
      class XTest4 {
      
      	@Test
      	public void testFoo() {
      		fail("Not yet implemented");
      	}
      
      	@Test
      	public void testFoo1() {
      		fail("Not yet implemented");
      	}
      
      	@Test
      	public void testFoo2() {
      		fail("Not yet implemented");
      	}
      }
      
      	@Test
      	public void testFoo3(){
      	fail("Not yet implemented");
      	}
      

        Activity

        Hide
        Andrew Eisenberg added a comment -

        The problem here looks like the end location of the testFoo2 method in the JDT model is incorrect. It is 246, but should be 244. More precisely, it is the length of the method that is off by 2. This must be coming from AntlrPluginParser somewhere.

        Show
        Andrew Eisenberg added a comment - The problem here looks like the end location of the testFoo2 method in the JDT model is incorrect. It is 246, but should be 244. More precisely, it is the length of the method that is off by 2. This must be coming from AntlrPluginParser somewhere.
        Hide
        Andrew Eisenberg added a comment -

        Yes. It looks like the source end location when translated from the Groovy MethodNode to the JDT compiler MethodDeclaration is too long by 1. It looks like we need to add a -1 in GroovyCompilationUnitDeclaration.fixupSourceLocationsForMethodDeclaration().

        Was:

        methodDeclaration.declarationSourceEnd = methodNode.getEnd();
        

        Now:

        methodDeclaration.declarationSourceEnd = methodNode.getEnd() - 1;
        

        Likely this wasn't discovered before because in most situations, the effect is not noticeable.

        I'll go run the tests to see if anything is broken.

        Show
        Andrew Eisenberg added a comment - Yes. It looks like the source end location when translated from the Groovy MethodNode to the JDT compiler MethodDeclaration is too long by 1. It looks like we need to add a -1 in GroovyCompilationUnitDeclaration.fixupSourceLocationsForMethodDeclaration(). Was: methodDeclaration.declarationSourceEnd = methodNode.getEnd(); Now: methodDeclaration.declarationSourceEnd = methodNode.getEnd() - 1; Likely this wasn't discovered before because in most situations, the effect is not noticeable. I'll go run the tests to see if anything is broken.
        Hide
        Andrew Eisenberg added a comment -

        Good...some broken tests. I think this means that our original assumptions about what the source locations should be were wrong.

        I also had to add a few extra -1s in corresponding places for fixupSourceLocationsForContructorDeclaration, fixupSourceLocationsForTypeDeclaration, and fixupSourceLocationsForFieldDeclaration.

        Show
        Andrew Eisenberg added a comment - Good...some broken tests. I think this means that our original assumptions about what the source locations should be were wrong. I also had to add a few extra -1s in corresponding places for fixupSourceLocationsForContructorDeclaration, fixupSourceLocationsForTypeDeclaration, and fixupSourceLocationsForFieldDeclaration.
        Hide
        Andrew Eisenberg added a comment -

        All tests now passing again. And wizard is working. Will commit shortly.

        Show
        Andrew Eisenberg added a comment - All tests now passing again. And wizard is working. Will commit shortly.

          People

          • Assignee:
            Andrew Eisenberg
            Reporter:
            Andrew Eisenberg
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: