View Javadoc
1   /*
2    *    Copyright 2009-2022 the original author or authors.
3    *
4    *    Licensed under the Apache License, Version 2.0 (the "License");
5    *    you may not use this file except in compliance with the License.
6    *    You may obtain a copy of the License at
7    *
8    *       https://www.apache.org/licenses/LICENSE-2.0
9    *
10   *    Unless required by applicable law or agreed to in writing, software
11   *    distributed under the License is distributed on an "AS IS" BASIS,
12   *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *    See the License for the specific language governing permissions and
14   *    limitations under the License.
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  }