Last active
August 29, 2015 14:25
-
-
Save siordache/2113afe4e381a005c4b8 to your computer and use it in GitHub Desktop.
Spock specification for testing partial mocking of abstract classes
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 PartialMockingAbstractClasses extends Specification { | |
def "Square with stubbed getLength()"() { | |
given: | |
Square square = Spy() { | |
2 * getLength() >> 3 | |
} | |
when: | |
def area = square.area | |
then: | |
area == 9 | |
} | |
} |
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 abstract class Square { | |
public abstract double getLength(); | |
public double getArea() { | |
return getLength() * getLength(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment