java - How to stub method returning Long in Spock? -
i have been trying stub method returning long null. there way this?
interface clock { long currenttimemillis(); } def "stub method returning long"() { clock clock = mock(clock) clock.currenttimemillis() >> 1 when: long currenttime = clock.currenttimemillis() then: currenttime == 1 1 * clock.currenttimemillis() } def "mock method returning longs"() { clock clock = mock(clock) clock.currenttimemillis() >>> [1, 2, 3] when: long currenttime = clock.currenttimemillis() then: currenttime == 1 1 * clock.currenttimemillis() }
in both tests i'm getting following error:
condition not satisfied: currenttime == 1 | | null false
when both mock , record behavior, should defined below.
here's how works:
@grab('org.spockframework:spock-core:0.7-groovy-2.0') @grab('cglib:cglib-nodep:3.1') import spock.lang.* class test extends specification { def "stub method returning long"() { given: clock clock = mock(clock) when: long currenttime = clock.currenttimemillis() then: currenttime == 1 1 * clock.currenttimemillis() >> 1 } def "mock method returning longs"() { given: clock clock = mock(clock) when: long currenttime = clock.currenttimemillis() then: currenttime == 1 1 * clock.currenttimemillis() >>> [1, 2, 3] } } interface clock { long currenttimemillis(); }
Comments
Post a Comment