-
Notifications
You must be signed in to change notification settings - Fork 9
/
ConstructorInjectionSeveralConstructorsNoCollaboratorsSpec.groovy
executable file
·64 lines (44 loc) · 1.55 KB
/
ConstructorInjectionSeveralConstructorsNoCollaboratorsSpec.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
package com.blogspot.toomuchcoding.spock.subjcollabs
import spock.lang.Specification
class ConstructorInjectionSeveralConstructorsNoCollaboratorsSpec extends Specification {
public static final String TEST_METHOD_1 = "Test method 1"
String string = "string"
Integer integer = 10
SomeOtherClass someOtherClassNotToBeInjected = Mock()
SomeOtherClass someOtherClass = Mock()
@Subject
SomeClass systemUnderTest
def "should inject all fields into subject"() {
given:
someOtherClassNotToBeInjected.someMethod() >> TEST_METHOD_1
when:
String firstResult = systemUnderTest.someOtherClass.someMethod()
then:
firstResult == TEST_METHOD_1
systemUnderTest.someOtherClass == someOtherClassNotToBeInjected
systemUnderTest.string == TEST_METHOD_1
systemUnderTest.integer == integer
}
class SomeClass {
SomeOtherClass someOtherClass
String string
Integer integer
SomeClass(SomeOtherClass someOtherClass) {
this.someOtherClass = someOtherClass
}
SomeClass(SomeOtherClass someOtherClass, String string) {
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"
}
}
}