@@ -10,6 +10,7 @@ import org.mockito.Mockito.verify
10
10
import java.sql.Connection
11
11
import java.sql.PreparedStatement
12
12
import java.sql.Statement
13
+ import javax.sql.DataSource
13
14
14
15
class DbSetupBuilderTest {
15
16
@@ -31,9 +32,8 @@ class DbSetupBuilderTest {
31
32
}
32
33
33
34
@Test
34
- fun `should execute an operation` () {
35
- dbSetup {
36
- destination = mockDestination
35
+ fun `should execute an operation with the binder configuration specified as property` () {
36
+ dbSetup(to = mockDestination) {
37
37
binderConfiguration = mockConfig
38
38
execute(mockOperation)
39
39
}.launch()
@@ -42,26 +42,37 @@ class DbSetupBuilderTest {
42
42
}
43
43
44
44
@Test
45
- fun `should use the default binder configuration if not set` () {
46
- dbSetup {
47
- destination = mockDestination
45
+ fun `should execute an operation with the binder configuration specified as argument` () {
46
+ dbSetup(to = mockDestination, binderConfiguration = mockConfig) {
48
47
execute(mockOperation)
49
48
}.launch()
50
49
51
- verify(mockOperation).execute(mockConnection, DefaultBinderConfiguration . INSTANCE )
50
+ verify(mockOperation).execute(mockConnection, mockConfig )
52
51
}
53
52
54
- @Test(expected = IllegalStateException ::class )
55
- fun `should throw if destination not set` () {
56
- dbSetup {
53
+ @Test
54
+ fun `should execute an operation with a DataSource specified as argument` () {
55
+ val mockDataSource = mock<DataSource >()
56
+ whenever(mockDataSource.connection).thenReturn(mockConnection)
57
+ dbSetup(to = mockDataSource, binderConfiguration = mockConfig) {
57
58
execute(mockOperation)
58
59
}.launch()
60
+
61
+ verify(mockOperation).execute(mockConnection, mockConfig)
62
+ }
63
+
64
+ @Test
65
+ fun `should use the default binder configuration if not set` () {
66
+ dbSetup(to = mockDestination) {
67
+ execute(mockOperation)
68
+ }.launch()
69
+
70
+ verify(mockOperation).execute(mockConnection, DefaultBinderConfiguration .INSTANCE )
59
71
}
60
72
61
73
@Test
62
74
fun `should delete all from one table` () {
63
- dbSetup {
64
- destination = mockDestination
75
+ dbSetup(to = mockDestination) {
65
76
deleteAllFrom(" user" )
66
77
}.launch()
67
78
@@ -70,8 +81,7 @@ class DbSetupBuilderTest {
70
81
71
82
@Test
72
83
fun `should delete all from multiple tables passed as vararg` () {
73
- dbSetup {
74
- destination = mockDestination
84
+ dbSetup(to = mockDestination) {
75
85
deleteAllFrom(" country" , " user" )
76
86
}.launch()
77
87
@@ -81,8 +91,7 @@ class DbSetupBuilderTest {
81
91
82
92
@Test
83
93
fun `should delete all from multiple tables passed as list` () {
84
- dbSetup {
85
- destination = mockDestination
94
+ dbSetup(to = mockDestination) {
86
95
deleteAllFrom(listOf (" country" , " user" ))
87
96
}.launch()
88
97
@@ -92,8 +101,7 @@ class DbSetupBuilderTest {
92
101
93
102
@Test
94
103
fun `should truncate one table` () {
95
- dbSetup {
96
- destination = mockDestination
104
+ dbSetup(to = mockDestination) {
97
105
truncate(" user" )
98
106
}.launch()
99
107
@@ -102,8 +110,7 @@ class DbSetupBuilderTest {
102
110
103
111
@Test
104
112
fun `should truncate multiple tables passed as vararg` () {
105
- dbSetup {
106
- destination = mockDestination
113
+ dbSetup(to = mockDestination) {
107
114
truncate(" country" , " user" )
108
115
}.launch()
109
116
@@ -113,8 +120,7 @@ class DbSetupBuilderTest {
113
120
114
121
@Test
115
122
fun `should truncate multiple tables passed as list` () {
116
- dbSetup {
117
- destination = mockDestination
123
+ dbSetup(to = mockDestination) {
118
124
truncate(listOf (" country" , " user" ))
119
125
}.launch()
120
126
@@ -125,8 +131,7 @@ class DbSetupBuilderTest {
125
131
@Test
126
132
fun `should execute one sql statement` () {
127
133
val query = " update foo where bar = 1"
128
- dbSetup {
129
- destination = mockDestination
134
+ dbSetup(to = mockDestination) {
130
135
sql(query)
131
136
}.launch()
132
137
@@ -137,8 +142,7 @@ class DbSetupBuilderTest {
137
142
fun `should execute multiple sql statements passed as vararg` () {
138
143
val query1 = " update foo where bar = 1"
139
144
val query2 = " update baz where qux = 1"
140
- dbSetup {
141
- destination = mockDestination
145
+ dbSetup(to = mockDestination) {
142
146
sql(query1, query2)
143
147
}.launch()
144
148
@@ -150,8 +154,7 @@ class DbSetupBuilderTest {
150
154
fun `should execute multiple sql statements passed as list` () {
151
155
val query1 = " update foo where bar = 1"
152
156
val query2 = " update baz where qux = 1"
153
- dbSetup {
154
- destination = mockDestination
157
+ dbSetup(to = mockDestination) {
155
158
sql(listOf (query1, query2))
156
159
}.launch()
157
160
@@ -165,9 +168,7 @@ class DbSetupBuilderTest {
165
168
whenever(mockConnection.prepareStatement(" insert into user (id, name) values (?, ?)" ))
166
169
.thenReturn(mockPreparedStatement)
167
170
168
- dbSetup {
169
- destination = mockDestination
170
-
171
+ dbSetup(to = mockDestination) {
171
172
insertInto(" user" ) {
172
173
columns(" id" , " name" )
173
174
values(1 , " John" )
0 commit comments