7
7
import java .sql .SQLException ;
8
8
9
9
import static org .junit .jupiter .api .Assertions .assertEquals ;
10
- import static org .mockito .Mockito .mock ;
11
- import static org .mockito .Mockito .verify ;
10
+ import static org .mockito .Mockito .*;
12
11
13
12
public class DynamicParameterListTest {
14
13
15
14
@ Test
16
- void callWithThreeDifferentTypes () throws SQLException {
15
+ void call_with_three_different_types () throws SQLException {
17
16
18
17
CallableStatement mockedStatement = mock (CallableStatement .class );
19
18
OracleConnection mockedConn = mock (OracleConnection .class );
@@ -29,9 +28,31 @@ void callWithThreeDifferentTypes() throws SQLException {
29
28
assertEquals ("a_object_owner = ?, a_num_param = ?, a_num_array = ?" , parameterList .getSql ());
30
29
31
30
parameterList .setParamsStartWithIndex (mockedStatement , 5 );
31
+
32
32
verify (mockedStatement ).setString (5 , "MyOwner" );
33
33
verify (mockedStatement ).setInt (6 , 123 );
34
34
verify (mockedConn ).createOracleArray ("MY_NUM_ARR" , numArr );
35
35
verify (mockedStatement ).setArray (7 , null );
36
36
}
37
+
38
+ @ Test
39
+ void when_not_accept_empty_filter_empty_elements () throws SQLException {
40
+
41
+ CallableStatement mockedStatement = mock (CallableStatement .class );
42
+ OracleConnection mockedConn = mock (OracleConnection .class );
43
+
44
+ DynamicParameterList parameterList = DynamicParameterListBuilder .create ()
45
+ .onlyAddIfNotEmpty ()
46
+ .add ("a_object_owner" , (String )null )
47
+ .add ("a_num_param" , (Integer )null )
48
+ .add ("a_num_array" , new Object []{}, "MY_NUM_ARR" , mockedConn )
49
+ .build ();
50
+
51
+ assertEquals ("" , parameterList .getSql ());
52
+
53
+ parameterList .setParamsStartWithIndex (mockedStatement , 2 );
54
+
55
+ verifyNoMoreInteractions (mockedStatement );
56
+ verifyNoMoreInteractions (mockedConn );
57
+ }
37
58
}
0 commit comments