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
def "Should pass expected parameter to method"() { | |
given: | |
Service service = Mock() | |
def person = new Person("Paweł", "Stawicki") | |
when: | |
service.method(person) | |
then: | |
1 * service.method({ | |
it.firstname == "Peter" && it.surname == "Stawicki" | |
}) | |
} |
Too few invocations for: 1 * service.method({ it.firstname == "Peter" && it.surname == "Stawicki" }) (0 invocations) Unmatched invocations (ordered by similarity): 1 * service.method(eu.vegasoft.spocktest.validateparam.Person@40f892a4)Sometimes we want to validate also parameter passed to the mock method. We can do it like this:
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
def "Should pass expected parameter method and validate it"() { | |
given: | |
Service service = Mock() | |
def person = new Person("Paweł", "Stawicki") | |
when: | |
service.method(person) | |
then: | |
1 * service.method(_) >> {Person p -> | |
assert p.firstname == "Peter" | |
assert p.surname == "Stawicki" | |
} | |
} |
Condition not satisfied: p.firstname == "Peter" | | | | Paweł false | 3 differences (40% similarity) | P(aw)e(ł) | P(et)e(r) eu.vegasoft.spocktest.validateparam.Person@34b23d12
No comments:
Post a Comment