Created
October 9, 2015 08:40
-
-
Save PiotrZakrzewski/82556a95d6635c799050 to your computer and use it in GitHub Desktop.
Example of mocking a method of a Groovy class.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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