Spock how to mock a method of the same class for a Java class

Viewed 6617

I have a Java class

class MyClass {
  void methodA() {  
         //something 
  }
  void methodB() { 
         //something else 
  }
}

I wanted to unit test methodA but methodA depends on methodB. I have gone through the spock documentation but I am not able to find how to handle this scenario. What should I do?

Note I was not able to find an answer for this so I am self-answering this question on stackoverflow which is allowed as per stackoverlfow's self-answering policy. Added this note to avoid confusion for those who are not aware of the self-answering policy so do not remove.

4 Answers
Related