Mocking method from Java abstract class

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Mocking method from Java abstract class

newtogroovy
I have some legacy Java code that I am writing Specs for.  Many methods are defined on AbstractClass similar to this:

public abstract class AbstractClass {

   public String myMethod() {
      return doSomething();
   }
}

public class ConcreteClass extends AbstractClass {
   //code
}
   

In my Spec I return a mockConcreteClass and need to do this:

1 * mockConcreteClass.myMethod() >> mockOtherObject

However, I don't think Spock will handle this case as the method is declared on the abstract class.

Am I missing something?

If not, could someone explain could someone give me some pointers on how to extend Spock to handle this?

Thanks!

--
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/spockframework.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Mocking method from Java abstract class

Serban Iordache
Use Spy instead of Mock. See this gist.


On Friday, January 22, 2016 at 3:56:38 PM UTC+1, newtogroovy wrote:
I have some legacy Java code that I am writing Specs for.  Many methods are defined on AbstractClass similar to this:

public abstract class AbstractClass {

   public String myMethod() {
      return doSomething();
   }
}

public class ConcreteClass extends AbstractClass {
   //code
}
   

In my Spec I return a mockConcreteClass and need to do this:

1 * mockConcreteClass.myMethod() >> mockOtherObject

However, I don't think Spock will handle this case as the method is declared on the abstract class.

Am I missing something?

If not, could someone explain could someone give me some pointers on how to extend Spock to handle this?

Thanks!

--
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/spockframework.
For more options, visit https://groups.google.com/d/optout.
Loading...