-
Notifications
You must be signed in to change notification settings - Fork 9
/
ConstructorInjectionSeveralConstructorsSeveralCollaboratorsSpec.groovy
executable file
·72 lines (52 loc) · 1.8 KB
/
ConstructorInjectionSeveralConstructorsSeveralCollaboratorsSpec.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package com.blogspot.toomuchcoding.spock.subjcollabs
import com.blogspot.toomuchcoding.spock.subjcollabs.Collaborator
import com.blogspot.toomuchcoding.spock.subjcollabs.Subject
import spock.lang.Specification
class ConstructorInjectionSeveralConstructorsSeveralCollaboratorsSpec extends Specification {
public static final String TEST_METHOD_1 = "Test method 1"
@Collaborator
String string = "string"
@Collaborator
Integer integer = 10
SomeOtherClass someOtherClassNotToBeInjected = Mock()
@Collaborator
SomeOtherClass someOtherClass = Mock()
@Subject
SomeClass systemUnderTest
def "should inject collaborators into subject"() {
given:
someOtherClass.someMethod() >> TEST_METHOD_1
when:
String firstResult = systemUnderTest.someOtherClass.someMethod()
then:
firstResult == TEST_METHOD_1
systemUnderTest.someOtherClass == someOtherClass
systemUnderTest.string == string
systemUnderTest.integer == integer
}
class SomeClass {
SomeOtherClass someOtherClass
String string
Integer integer
SomeClass(SomeOtherClass someOtherClass) {
this.integer = integer
this.string = string
this.someOtherClass = someOtherClass
}
SomeClass(SomeOtherClass someOtherClass, String string) {
this.integer = integer
this.string = string
this.someOtherClass = someOtherClass
}
SomeClass(SomeOtherClass someOtherClass, String string, Integer integer) {
this.integer = integer
this.string = string
this.someOtherClass = someOtherClass
}
}
class SomeOtherClass {
String someMethod() {
"Some other class"
}
}
}