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.assertj.core.api.Assertions.assertThat;
19 import static org.mockito.Mockito.when;
20
21 import java.sql.Array;
22
23 import org.apache.ibatis.logging.Log;
24 import org.junit.jupiter.api.BeforeEach;
25 import org.junit.jupiter.api.Test;
26 import org.junit.jupiter.api.extension.ExtendWith;
27 import org.mockito.Mock;
28 import org.mockito.junit.jupiter.MockitoExtension;
29
30 @ExtendWith(MockitoExtension.class)
31 class BaseJdbcLoggerTest {
32
33 @Mock
34 Log log;
35 @Mock
36 Array array;
37 private BaseJdbcLogger logger;
38
39 @BeforeEach
40 void setUp() {
41 logger = new BaseJdbcLogger(log, 1) {
42 };
43 }
44
45 @Test
46 void shouldDescribePrimitiveArrayParameter() throws Exception {
47 logger.setColumn("1", array);
48 when(array.getArray()).thenReturn(new int[] { 1, 2, 3 });
49 assertThat(logger.getParameterValueString()).startsWith("[1, 2, 3]");
50 }
51
52 @Test
53 void shouldDescribeObjectArrayParameter() throws Exception {
54 logger.setColumn("1", array);
55 when(array.getArray()).thenReturn(new String[] { "one", "two", "three" });
56 assertThat(logger.getParameterValueString()).startsWith("[one, two, three]");
57 }
58 }