1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.ibatis.logging.jdbc;
17
18 import static org.mockito.Mockito.verify;
19 import static org.mockito.Mockito.when;
20
21 import java.sql.ResultSet;
22 import java.sql.ResultSetMetaData;
23 import java.sql.SQLException;
24 import java.sql.Types;
25
26 import org.apache.ibatis.logging.Log;
27 import org.junit.jupiter.api.Test;
28 import org.junit.jupiter.api.extension.ExtendWith;
29 import org.mockito.Mock;
30 import org.mockito.junit.jupiter.MockitoExtension;
31
32 @ExtendWith(MockitoExtension.class)
33 class ResultSetLoggerTest {
34
35 @Mock
36 private ResultSet rs;
37
38 @Mock
39 private Log log;
40
41 @Mock
42 private ResultSetMetaData metaData;
43
44 private void setup(int type) throws SQLException {
45 when(rs.next()).thenReturn(true);
46 when(rs.getMetaData()).thenReturn(metaData);
47 when(metaData.getColumnCount()).thenReturn(1);
48 when(metaData.getColumnType(1)).thenReturn(type);
49 when(metaData.getColumnLabel(1)).thenReturn("ColumnName");
50 when(log.isTraceEnabled()).thenReturn(true);
51 ResultSet resultSet = ResultSetLogger.newInstance(rs, log, 1);
52 resultSet.next();
53 }
54
55 @Test
56 void shouldNotPrintBlobs() throws SQLException {
57 setup(Types.LONGNVARCHAR);
58 verify(log).trace("<== Columns: ColumnName");
59 verify(log).trace("<== Row: <<BLOB>>");
60 }
61
62 @Test
63 void shouldPrintVarchars() throws SQLException {
64 when(rs.getString(1)).thenReturn("value");
65 setup(Types.VARCHAR);
66 verify(log).trace("<== Columns: ColumnName");
67 verify(log).trace("<== Row: value");
68 }
69
70 }