-
Notifications
You must be signed in to change notification settings - Fork 9
/
SettersInjectionOnSpySpec.groovy
46 lines (35 loc) · 1.17 KB
/
SettersInjectionOnSpySpec.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package com.blogspot.toomuchcoding.spock.subjcollabs
import spock.lang.Issue
import spock.lang.Specification
@Issue('#8')
class SettersInjectionOnSpySpec extends Specification {
public static final String TEST_METHOD_1 = "Test method 1"
@Collaborator SomeOtherClass someOtherClassInjected = Mock()
@Subject SomeClass systemUnderTestInjected = Spy()
SomeOtherClass someOtherClassPlain = Mock()
SomeClass systemUnderTestPlain = Spy()
def "should inject collaborator into subject without disrupting spy stubbing"() {
given:
someOtherClassInjected.getResult() >> 'mock called'
systemUnderTestInjected.throwException() >> {}
when:
def result = systemUnderTestInjected.collaborate()
then:
result == 'mock called'
}
class SomeClass {
SomeOtherClass collaborator
String collaborate() {
throwException()
return collaborator.getResult()
}
void throwException() {
throw new RuntimeException()
}
}
class SomeOtherClass {
def getResult() {
return 'SomeOtherClass called'
}
}
}