Skip to content

Instantly share code, notes, and snippets.

@siordache
Created January 22, 2016 16:07
Show Gist options
  • Save siordache/3fd6d738ed599499751c to your computer and use it in GitHub Desktop.
Save siordache/3fd6d738ed599499751c to your computer and use it in GitHub Desktop.
Mocking method from Java abstract class
public abstract class RegularPoly {
public double getLength() {
return Math.abs(System.identityHashCode(this)) % 100;
}
public abstract double getArea();
}
public class Square extends RegularPoly {
@Override
public double getArea() {
return getLength() * getLength();
}
}
import spock.lang.Specification
class SquareSpec extends Specification {
def "should correctly compute area"() {
given:
Square square = Spy()
when:
def area = square.area
then:
2 * square.getLength() >> 10
area == 100
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment