views:

94

answers:

1

I have a Java object called Parameter and I'm trying to mock it using groovy. Parameter is an abstract class with 1 abstract method. It also has a non-abstract method called getName(). I'm trying to mock it as follows in Groovy:

 def p1 = [name:{"p1Name"}] as Parameter

But I get a runtime error because I don't implement the abstract method. If I'm trying to create a mock, why would I need to implement the abstract method?

thanks, Jeff

+2  A: 

By mocking using the map you are creating an instance of type Parameter and so it must implement any abstract methods of the Parameter class.

abstract class Parameter {
  abstract String getOtherName() 
  String getName() { return "test" }
}

def p1 = [name:{"p1Name"}, getOtherName:{""}] as Parameter
John Wagenleitner
I originally expected this to behave like easymock's class extension, but I since realized it won't. Thank you.
Jeff Storey