Skip to content

Instantly share code, notes, and snippets.

@siordache
Created July 23, 2015 00:45
Show Gist options
  • Save siordache/74c77618e4caceac94e9 to your computer and use it in GitHub Desktop.
Save siordache/74c77618e4caceac94e9 to your computer and use it in GitHub Desktop.
Spock specification for testing partial mocking of interfaces with default methods
public interface ISquare {
double getLength();
default double getArea() {
return getLength() * getLength();
}
}
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