1
1
/*
2
- * Copyright 2002-2019 the original author or authors.
2
+ * Copyright 2002-2021 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
47
47
* @author Thomas Risberg
48
48
* @author Kiril Nugmanov
49
49
*/
50
- public class SimpleJdbcCallTests {
50
+ class SimpleJdbcCallTests {
51
51
52
- private Connection connection ;
52
+ private final Connection connection = mock ( Connection . class ) ;
53
53
54
- private DatabaseMetaData databaseMetaData ;
54
+ private final DatabaseMetaData databaseMetaData = mock ( DatabaseMetaData . class ) ;
55
55
56
- private DataSource dataSource ;
56
+ private final DataSource dataSource = mock ( DataSource . class ) ;
57
57
58
- private CallableStatement callableStatement ;
58
+ private final CallableStatement callableStatement = mock ( CallableStatement . class ) ;
59
59
60
60
61
61
@ BeforeEach
62
- public void setUp () throws Exception {
63
- connection = mock (Connection .class );
64
- databaseMetaData = mock (DatabaseMetaData .class );
65
- dataSource = mock (DataSource .class );
66
- callableStatement = mock (CallableStatement .class );
62
+ void setUp () throws Exception {
67
63
given (connection .getMetaData ()).willReturn (databaseMetaData );
68
64
given (dataSource .getConnection ()).willReturn (connection );
69
65
}
70
66
71
67
72
68
@ Test
73
- public void testNoSuchStoredProcedure () throws Exception {
69
+ void noSuchStoredProcedure () throws Exception {
74
70
final String NO_SUCH_PROC = "x" ;
75
71
SQLException sqlException = new SQLException ("Syntax error or access violation exception" , "42000" );
76
72
given (databaseMetaData .getDatabaseProductName ()).willReturn ("MyDB" );
@@ -81,8 +77,8 @@ public void testNoSuchStoredProcedure() throws Exception {
81
77
given (connection .prepareCall ("{call " + NO_SUCH_PROC + "()}" )).willReturn (callableStatement );
82
78
SimpleJdbcCall sproc = new SimpleJdbcCall (dataSource ).withProcedureName (NO_SUCH_PROC );
83
79
try {
84
- assertThatExceptionOfType (BadSqlGrammarException .class ). isThrownBy (() ->
85
- sproc .execute ())
80
+ assertThatExceptionOfType (BadSqlGrammarException .class )
81
+ . isThrownBy (() -> sproc .execute ())
86
82
.withCause (sqlException );
87
83
}
88
84
finally {
@@ -92,7 +88,7 @@ public void testNoSuchStoredProcedure() throws Exception {
92
88
}
93
89
94
90
@ Test
95
- public void testUnnamedParameterHandling () throws Exception {
91
+ void unnamedParameterHandling () throws Exception {
96
92
final String MY_PROC = "my_proc" ;
97
93
SimpleJdbcCall sproc = new SimpleJdbcCall (dataSource ).withProcedureName (MY_PROC );
98
94
// Shouldn't succeed in adding unnamed parameter
@@ -101,7 +97,7 @@ public void testUnnamedParameterHandling() throws Exception {
101
97
}
102
98
103
99
@ Test
104
- public void testAddInvoiceProcWithoutMetaDataUsingMapParamSource () throws Exception {
100
+ void addInvoiceProcWithoutMetaDataUsingMapParamSource () throws Exception {
105
101
initializeAddInvoiceWithoutMetaData (false );
106
102
SimpleJdbcCall adder = new SimpleJdbcCall (dataSource ).withProcedureName ("add_invoice" );
107
103
adder .declareParameters (
@@ -117,7 +113,7 @@ public void testAddInvoiceProcWithoutMetaDataUsingMapParamSource() throws Except
117
113
}
118
114
119
115
@ Test
120
- public void testAddInvoiceProcWithoutMetaDataUsingArrayParams () throws Exception {
116
+ void addInvoiceProcWithoutMetaDataUsingArrayParams () throws Exception {
121
117
initializeAddInvoiceWithoutMetaData (false );
122
118
SimpleJdbcCall adder = new SimpleJdbcCall (dataSource ).withProcedureName ("add_invoice" );
123
119
adder .declareParameters (
@@ -131,7 +127,7 @@ public void testAddInvoiceProcWithoutMetaDataUsingArrayParams() throws Exception
131
127
}
132
128
133
129
@ Test
134
- public void testAddInvoiceProcWithMetaDataUsingMapParamSource () throws Exception {
130
+ void addInvoiceProcWithMetaDataUsingMapParamSource () throws Exception {
135
131
initializeAddInvoiceWithMetaData (false );
136
132
SimpleJdbcCall adder = new SimpleJdbcCall (dataSource ).withProcedureName ("add_invoice" );
137
133
Number newId = adder .executeObject (Number .class , new MapSqlParameterSource ()
@@ -143,7 +139,7 @@ public void testAddInvoiceProcWithMetaDataUsingMapParamSource() throws Exception
143
139
}
144
140
145
141
@ Test
146
- public void testAddInvoiceProcWithMetaDataUsingArrayParams () throws Exception {
142
+ void addInvoiceProcWithMetaDataUsingArrayParams () throws Exception {
147
143
initializeAddInvoiceWithMetaData (false );
148
144
SimpleJdbcCall adder = new SimpleJdbcCall (dataSource ).withProcedureName ("add_invoice" );
149
145
Number newId = adder .executeObject (Number .class , 1103 , 3 );
@@ -153,7 +149,7 @@ public void testAddInvoiceProcWithMetaDataUsingArrayParams() throws Exception {
153
149
}
154
150
155
151
@ Test
156
- public void testAddInvoiceFuncWithoutMetaDataUsingMapParamSource () throws Exception {
152
+ void addInvoiceFuncWithoutMetaDataUsingMapParamSource () throws Exception {
157
153
initializeAddInvoiceWithoutMetaData (true );
158
154
SimpleJdbcCall adder = new SimpleJdbcCall (dataSource ).withFunctionName ("add_invoice" );
159
155
adder .declareParameters (
@@ -169,7 +165,7 @@ public void testAddInvoiceFuncWithoutMetaDataUsingMapParamSource() throws Except
169
165
}
170
166
171
167
@ Test
172
- public void testAddInvoiceFuncWithoutMetaDataUsingArrayParams () throws Exception {
168
+ void addInvoiceFuncWithoutMetaDataUsingArrayParams () throws Exception {
173
169
initializeAddInvoiceWithoutMetaData (true );
174
170
SimpleJdbcCall adder = new SimpleJdbcCall (dataSource ).withFunctionName ("add_invoice" );
175
171
adder .declareParameters (
@@ -183,7 +179,7 @@ public void testAddInvoiceFuncWithoutMetaDataUsingArrayParams() throws Exception
183
179
}
184
180
185
181
@ Test
186
- public void testAddInvoiceFuncWithMetaDataUsingMapParamSource () throws Exception {
182
+ void addInvoiceFuncWithMetaDataUsingMapParamSource () throws Exception {
187
183
initializeAddInvoiceWithMetaData (true );
188
184
SimpleJdbcCall adder = new SimpleJdbcCall (dataSource ).withFunctionName ("add_invoice" );
189
185
Number newId = adder .executeFunction (Number .class , new MapSqlParameterSource ()
@@ -192,38 +188,36 @@ public void testAddInvoiceFuncWithMetaDataUsingMapParamSource() throws Exception
192
188
assertThat (newId .intValue ()).isEqualTo (4 );
193
189
verifyAddInvoiceWithMetaData (true );
194
190
verify (connection , atLeastOnce ()).close ();
195
-
196
191
}
197
192
198
193
@ Test
199
- public void testAddInvoiceFuncWithMetaDataUsingArrayParams () throws Exception {
194
+ void addInvoiceFuncWithMetaDataUsingArrayParams () throws Exception {
200
195
initializeAddInvoiceWithMetaData (true );
201
196
SimpleJdbcCall adder = new SimpleJdbcCall (dataSource ).withFunctionName ("add_invoice" );
202
197
Number newId = adder .executeFunction (Number .class , 1103 , 3 );
203
198
assertThat (newId .intValue ()).isEqualTo (4 );
204
199
verifyAddInvoiceWithMetaData (true );
205
200
verify (connection , atLeastOnce ()).close ();
206
-
207
201
}
208
202
209
203
@ Test
210
- public void testCorrectFunctionStatement () throws Exception {
204
+ void correctFunctionStatement () throws Exception {
211
205
initializeAddInvoiceWithMetaData (true );
212
206
SimpleJdbcCall adder = new SimpleJdbcCall (dataSource ).withFunctionName ("add_invoice" );
213
207
adder .compile ();
214
208
verifyStatement (adder , "{? = call ADD_INVOICE(?, ?)}" );
215
209
}
216
210
217
211
@ Test
218
- public void testCorrectFunctionStatementNamed () throws Exception {
212
+ void correctFunctionStatementNamed () throws Exception {
219
213
initializeAddInvoiceWithMetaData (true );
220
214
SimpleJdbcCall adder = new SimpleJdbcCall (dataSource ).withNamedBinding ().withFunctionName ("add_invoice" );
221
215
adder .compile ();
222
216
verifyStatement (adder , "{? = call ADD_INVOICE(AMOUNT => ?, CUSTID => ?)}" );
223
217
}
224
218
225
219
@ Test
226
- public void testCorrectProcedureStatementNamed () throws Exception {
220
+ void correctProcedureStatementNamed () throws Exception {
227
221
initializeAddInvoiceWithMetaData (false );
228
222
SimpleJdbcCall adder = new SimpleJdbcCall (dataSource ).withNamedBinding ().withProcedureName ("add_invoice" );
229
223
adder .compile ();
0 commit comments