groovy
  1. groovy
  2. GROOVY-3720

MockFor and StubFor call unsupported method in ProxyGenerator for creation of instances of Abstract classes

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.7-beta-1
    • Fix Version/s: 1.6.5, 1.7-beta-2
    • Component/s: None
    • Labels:
      None
    • Environment:
      Windows XP Professional Version 5.1.2600 Service Pack 2 Build 2600
    • Testcase included:
      yes
    • Number of attachments :
      0

      Description

      public abstract class MyNode {

      }

      @Test
      public void testCreateStubNode()

      { def stubNodeContext = new StubFor(MyNode) assertNotNull(stubNodeContext.proxyInstance()) }

      @Test
      public void testCreateStubNodeDelegate()

      { def stubNodeContext = new StubFor(MyNode) assertNotNull(stubNodeContext.proxyDelegateInstance()) }

      @Test
      public void testCreateMockNode()

      { def mockNodeContext = new MockFor(MyNode) assertNotNull(mockNodeContext.proxyInstance()) }

      @Test
      public void testCreateMockNodeDelegate()

      { def mockNodeContext = new MockFor(MyNode) assertNotNull(mockNodeContext.proxyDelegateInstance()) }

      In any case (and with a non-empty Abstract class such as import javax.media.j3d.Node) the result is:

      groovy.lang.MissingMethodException: No signature of method: groovy.util.ProxyGenerator.instantiateAggregateFromBaseClass() is applicable for argument types: (java.lang.Class, null) values: [class MyNode, null]

      Which appears to be absolutely true: the ProxyGenerator only has these 3 method signatures, none of which have the Class as the 1st argument (save the single parameter version)...

      instantiateAggregateFromBaseClass(Class)
      instantiateAggregateFromBaseClass(Map, Class)
      instantiateAggregateFromBaseClass(Closure, Class)

        Activity

        Hide
        Roshan Dawrani added a comment - - edited

        An additional test case below, which must also go through after the fix:

        import groovy.mock.interceptor.*
        
        class AnotherNodeTest extends GroovyTestCase {
        
        	void testCreateStubNode() {
        		def stubNodeContext = new StubFor(AnotherNode) 
        		assertNotNull stubNodeContext.proxyInstance()
        	}
        
            void testCreateStubNodeDelegate() {
                def stubNodeContext = new StubFor(AnotherNode) 
                assertNotNull stubNodeContext.proxyDelegateInstance()
            }
            
            void testCreateMockNode() {
                def mockNodeContext = new MockFor(AnotherNode) 
        
                assertNotNull mockNodeContext.proxyInstance()
                assertNotNull mockNodeContext.proxyDelegateInstance()
            }
        
            void testCreateMockNodeDelegate() {
                def mockNodeContext = new MockFor(AnotherNode) 
        
                assertNotNull mockNodeContext.proxyInstance()
                assertNotNull mockNodeContext.proxyDelegateInstance()
            }
        }
        
        abstract class BaseNode {
            abstract m1()
        }
        abstract class AnotherNode extends BaseNode {
        	abstract m2()
        }
        
        Show
        Roshan Dawrani added a comment - - edited An additional test case below, which must also go through after the fix: import groovy.mock.interceptor.* class AnotherNodeTest extends GroovyTestCase { void testCreateStubNode() { def stubNodeContext = new StubFor(AnotherNode) assertNotNull stubNodeContext.proxyInstance() } void testCreateStubNodeDelegate() { def stubNodeContext = new StubFor(AnotherNode) assertNotNull stubNodeContext.proxyDelegateInstance() } void testCreateMockNode() { def mockNodeContext = new MockFor(AnotherNode) assertNotNull mockNodeContext.proxyInstance() assertNotNull mockNodeContext.proxyDelegateInstance() } void testCreateMockNodeDelegate() { def mockNodeContext = new MockFor(AnotherNode) assertNotNull mockNodeContext.proxyInstance() assertNotNull mockNodeContext.proxyDelegateInstance() } } abstract class BaseNode { abstract m1() } abstract class AnotherNode extends BaseNode { abstract m2() }
        Hide
        Roshan Dawrani added a comment -

        Fixed.

        Show
        Roshan Dawrani added a comment - Fixed.

          People

          • Assignee:
            Roshan Dawrani
            Reporter:
            Geoff Sindel
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: