Created
July 23, 2015 00:45
-
-
Save siordache/74c77618e4caceac94e9 to your computer and use it in GitHub Desktop.
Spock specification for testing partial mocking of interfaces with default methods
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
public interface ISquare { | |
double getLength(); | |
default double getArea() { | |
return getLength() * getLength(); | |
} | |
} |
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
import spock.lang.Specification | |
class PartialMockingInterfacesWithDefaultMethods extends Specification { | |
def "ISquare with stubbed getLength()"() { | |
given: | |
ISquare square = Spy() { | |
2 * getLength() >> 3 | |
} | |
when: | |
def area = square.area | |
then: | |
area == 9 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment