Groovy mocks with abstract methods

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

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

      

But I am getting a runtime error because I am not implementing the abstract method. If I am trying to create a layout, why would I need to use an abstract method?

thank you jeff

+2


source to share


1 answer


By mocking the use of a map, you are instantiating a Parameter type and therefore 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

      

+3


source







All Articles