groovy mocks with abstract methods
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 meth开发者_JAVA百科od 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
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
精彩评论