Skip to content

Instantly share code, notes, and snippets.

@siordache
Last active August 29, 2015 14:25
Show Gist options
  • Save siordache/2113afe4e381a005c4b8 to your computer and use it in GitHub Desktop.
Save siordache/2113afe4e381a005c4b8 to your computer and use it in GitHub Desktop.
Spock specification for testing partial mocking of abstract classes
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
}
}
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