-
-
Save mhaligowski/42d2b54c0fbd65e95d9d to your computer and use it in GitHub Desktop.
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
package io.mhlg.spock.test | |
class SuperDuperService { | |
def superDuperUrl | |
def doTheMagic() { | |
superDuperUrl.text | |
} | |
} |
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
package io.mhlg.spock.test | |
import spock.lang.Specification | |
import javax.swing.JTextField | |
class SuperDuperServiceSpec extends Specification { | |
def "should do the magic with groovy mock"() { | |
given: | |
def mockUrl = GroovyMock(URL) | |
def expectedString = "whoaaa, it works!" | |
mockUrl.text >> expectedString | |
def testObj = new SuperDuperService(superDuperObjectWithText: mockUrl) | |
when: | |
def result = testObj.doTheMagic() | |
then: | |
1 * mockUrl.text | |
result == expectedString | |
} | |
def "should do the magic with plain mock"() { | |
given: | |
def aMock = Mock(JTextField) | |
def expectedString = "whoaaa, it works!" | |
aMock.text >> expectedString | |
def testObj = new SuperDuperService(superDuperObjectWithText: aMock) | |
when: | |
def result = testObj.doTheMagic() | |
then: | |
1 * aMock.text | |
result == expectedString | |
} | |
def "should do the magic with plain mock [CORRECTLY]"() { | |
given: | |
def aMock = Mock(JTextField) | |
def testObj = new SuperDuperService(superDuperObjectWithText: aMock) | |
when: | |
def result = testObj.doTheMagic() | |
then: | |
1 * aMock.text >> "whoaaa, it works!" | |
result == "whoaaa, it works!" | |
} | |
def "should do the magic with groovy mock [CORRECTLY]"() { | |
given: | |
def mockUrl = GroovyMock(URL) | |
def expectedString = "whoaaa, it works!" | |
def testObj = new SuperDuperService(superDuperObjectWithText: mockUrl) | |
when: | |
def result = testObj.doTheMagic() | |
then: | |
1 * mockUrl.text >> expectedString | |
and: | |
result == expectedString | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment