/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.shardingsphere.infra.executor.sql.execute.result.query.impl.driver.jdbc.metadata;

import org.junit.Before;
import org.junit.Test;

import java.sql.ResultSetMetaData;
import java.sql.SQLException;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public final class JDBCQueryResultMetaDataTest {
    
    private JDBCQueryResultMetaData queryResultMetaData;
    
    @Before
    public void setUp() throws SQLException {
        queryResultMetaData = new JDBCQueryResultMetaData(mockResultSetMetaData());
    }
    
    private ResultSetMetaData mockResultSetMetaData() throws SQLException {
        ResultSetMetaData result = mock(ResultSetMetaData.class);
        when(result.getColumnCount()).thenReturn(1);
        when(result.getColumnName(1)).thenReturn("order_id");
        when(result.getColumnLabel(1)).thenReturn("oid");
        when(result.getColumnTypeName(1)).thenReturn("INT");
        return result;
    }
    
    @Test
    public void assertGetColumnCount() throws SQLException {
        assertThat(queryResultMetaData.getColumnCount(), is(1));
    }
    
    @Test
    public void assertGetColumnName() throws SQLException {
        assertThat(queryResultMetaData.getColumnName(1), is("order_id"));
    }
    
    @Test
    public void assertGetColumnLabel() throws SQLException {
        assertThat(queryResultMetaData.getColumnLabel(1), is("oid"));
    }
    
    @Test
    public void assertGetColumnTypeName() throws SQLException {
        assertThat(queryResultMetaData.getColumnTypeName(1), is("INT"));
    }
}

@@ -1011,16 +1011,39 @@
 ception;
+%0Aimport java.sql.Types;
 %0A%0Aimport
@@ -1845,24 +1845,445 @@
 urn(%22INT%22);%0A
+        when(result.getTableName(1)).thenReturn(%22order%22);%0A        when(result.getColumnType(1)).thenReturn(Types.INTEGER);%0A        when(result.getColumnDisplaySize(1)).thenReturn(10);%0A        when(result.getScale(1)).thenReturn(0);%0A        when(result.isSigned(1)).thenReturn(true);%0A        when(result.isNullable(1)).thenReturn(ResultSetMetaData.columnNoNulls);%0A        when(result.isAutoIncrement(1)).thenReturn(true);%0A
         retu
@@ -2824,32 +2824,32 @@
  SQLException %7B%0A
-
         assertTh
@@ -2911,10 +2911,1044 @@
 ;%0A    %7D%0A
+    %0A    @Test%0A    public void assertGetTableName() throws SQLException %7B%0A        assertThat(queryResultMetaData.getTableName(1), is(%22order%22));%0A    %7D%0A    %0A    @Test%0A    public void assertGetColumnType() throws SQLException %7B%0A        assertThat(queryResultMetaData.getColumnType(1), is(Types.INTEGER));%0A    %7D%0A    %0A    @Test%0A    public void assertGetColumnLength() throws SQLException %7B%0A        assertThat(queryResultMetaData.getColumnLength(1), is(10));%0A    %7D%0A    %0A    @Test%0A    public void assertGetDecimals() throws SQLException %7B%0A        assertThat(queryResultMetaData.getDecimals(1), is(0));%0A    %7D%0A    %0A    @Test%0A    public void assertIsSigned() throws SQLException %7B%0A        assertThat(queryResultMetaData.isSigned(1), is(true));%0A    %7D%0A    %0A    @Test%0A    public void assertIsNotNull() throws SQLException %7B%0A        assertThat(queryResultMetaData.isNotNull(1), is(true));%0A    %7D%0A    %0A    @Test%0A    public void assertIsAutoIncrement() throws SQLException %7B%0A        assertThat(queryResultMetaData.isAutoIncrement(1), is(true));%0A    %7D%0A
 %7D%0A

Add more test case for JDBCQueryResultMetaData (#8428)