Java Reference
In-Depth Information
Klingons are a bit different:
interface Klingon {
def annoy()
def fight()
def howlAtDeath()
}
Tribbles annoy Klingons. Klingons also fight and howlAtDeath , [ 23 ] two methods
that aren't needed here. To test the Tribble class, I need to create mock objects for both
the Vulcan and Klingon classes, set their expectations appropriately, and test that the
tribble behaves appropriately around each.
23 Klingons in Star Trek: The Next Generation howl at death. They didn't in the original series, as far as I know.
Let me show the tests one by one. First I'll check to see that the feed method works prop-
erly:
def "feed a tribble, get more tribbles"() {
when:
def result = tribble.feed()
then:
result.size() == 11
result. every {
it instanceof Tribble
}
}
The when block invokes the feed method. The then block checks that there are 11 ele-
ments in the returned collection and that each is a tribble. There's nothing new or unusual
about this test. Moving on to the test for reacting to Vulcans, however, I need to mock the
Vulcan interface. [ 24 ]
24 When I mock a Vulcan, I feel like Dr. McCoy.
def "reacts well to Vulcans"() {
Vulcan spock = Mock()
when:
String reaction = tribble.react(spock)
then:
reaction == "purr, purr"
 
 
Search WWH ::




Custom Search