5
5
6
6
import java .sql .ResultSetMetaData ;
7
7
8
- import static org .junit .Assert .assertEquals ;
9
- import static org .junit .Assert .assertNotNull ;
10
8
import static org .junit .Assert .assertEquals ;
11
9
import static org .mockito .ArgumentMatchers .any ;
12
- import static org .mockito .ArgumentMatchers .anyInt ;
13
- import static org .mockito .ArgumentMatchers .anyString ;
14
10
import static org .mockito .ArgumentMatchers .eq ;
15
11
import static org .mockito .Mockito .mock ;
16
12
import static org .mockito .Mockito .times ;
@@ -24,8 +20,15 @@ public void getParsedDatabaseStatement_cachesSqlStatement() {
24
20
DatabaseStatementParser mockParser = mock (DatabaseStatementParser .class );
25
21
CachingDatabaseStatementParser cache = new CachingDatabaseStatementParser (mockParser );
26
22
23
+ when (mockParser .getParsedDatabaseStatement (any (), eq ("sql" ), any ())).thenReturn (new ParsedDatabaseStatement ("tablename" , "select" , true ));
24
+
25
+ // Initial call will cache the result
27
26
ParsedDatabaseStatement statement = cache .getParsedDatabaseStatement (mock (DatabaseVendor .class ), "sql" , mock (ResultSetMetaData .class ));
28
27
verify (mockParser , times (1 )).getParsedDatabaseStatement (any (), eq ("sql" ), any ());
28
+
29
+ // Subsequent calls will retrieve the value from the cache and not call the databaseStatementParser again
30
+ assertEquals (statement , cache .getParsedDatabaseStatement (mock (DatabaseVendor .class ), "sql" , mock (ResultSetMetaData .class )));
31
+ verify (mockParser , times (1 )).getParsedDatabaseStatement (any (), eq ("sql" ), any ());
29
32
}
30
33
31
34
@ Test
@@ -34,4 +37,4 @@ public void getParsedDatabaseStatement_withNullStatement_returnsUnparseableState
34
37
CachingDatabaseStatementParser cache = new CachingDatabaseStatementParser (mockParser );
35
38
assertEquals (DatabaseStatementParser .UNPARSEABLE_STATEMENT , cache .getParsedDatabaseStatement (mock (DatabaseVendor .class ), null , null ));
36
39
}
37
- }
40
+ }
0 commit comments