Skip to content

Instantly share code, notes, and snippets.

@PiotrZakrzewski
Created October 9, 2015 08:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PiotrZakrzewski/82556a95d6635c799050 to your computer and use it in GitHub Desktop.
Save PiotrZakrzewski/82556a95d6635c799050 to your computer and use it in GitHub Desktop.
Example of mocking a method of a Groovy class.
class SampleService {
def methodA() {
methodB()
}
def methodB() {
return "real method"
}
}
def mock = [methodB: {-> return "mock!" }] as SampleService
assert "mock!" == mock.methodA()
assert "real method" == new SampleService().methodA()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment