-
Notifications
You must be signed in to change notification settings - Fork 9
/
PropertiesInjectionSpec.groovy
executable file
·52 lines (35 loc) · 1.28 KB
/
PropertiesInjectionSpec.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
47
48
49
50
package com.blogspot.toomuchcoding.spock.subjcollabs
import spock.lang.Specification
class PropertiesInjectionSpec extends Specification {
public static final String TEST_METHOD_1 = "Test method 1"
public static final String TEST_METHOD_2 = "Test method 2"
@Collaborator
SomeOtherClass someOtherClassToBeInjected = Mock()
@Collaborator
SomeOtherClass someOtherClass = Mock()
@Subject
SomeClass systemUnderTest
def "should inject collaborator into subject via properties"() {
given:
someOtherClass.someMethod() >> TEST_METHOD_1
someOtherClassToBeInjected.someMethod() >> TEST_METHOD_2
when:
String firstResult = systemUnderTest.someOtherClass.someMethod()
String secondResult = systemUnderTest.someOtherClassToBeInjected.someMethod()
then:
firstResult == TEST_METHOD_1
systemUnderTest.someOtherClass == someOtherClass
and:
secondResult == TEST_METHOD_2
systemUnderTest.someOtherClassToBeInjected == someOtherClassToBeInjected
}
class SomeClass {
private SomeOtherClass someOtherClass
private SomeOtherClass someOtherClassToBeInjected
}
class SomeOtherClass {
String someMethod() {
"Some other class"
}
}
}