Created
January 22, 2016 16:07
-
-
Save siordache/3fd6d738ed599499751c to your computer and use it in GitHub Desktop.
Mocking method from Java abstract class
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 RegularPoly { | |
public double getLength() { | |
return Math.abs(System.identityHashCode(this)) % 100; | |
} | |
public abstract double getArea(); | |
} |
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 class Square extends RegularPoly { | |
@Override | |
public 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 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