@@ -0,0 +1,3921 @@
+/*%0A * Licensed to the Apache Software Foundation (ASF) under one or more%0A * contributor license agreements.  See the NOTICE file distributed with%0A * this work for additional information regarding copyright ownership.%0A * The ASF licenses this file to You under the Apache License, Version 2.0%0A * (the %22License%22); you may not use this file except in compliance with%0A * the License.  You may obtain a copy of the License at%0A *%0A *     http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0Apackage org.apache.shardingsphere.proxy.frontend.postgresql;%0A%0Aimport org.apache.shardingsphere.db.protocol.postgresql.packet.generic.PostgreSQLErrorResponsePacket;%0Aimport org.junit.Test;%0Aimport org.postgresql.util.PSQLException;%0Aimport org.postgresql.util.PSQLState;%0Aimport org.postgresql.util.ServerErrorMessage;%0A%0Aimport java.lang.reflect.Field;%0Aimport java.util.Map;%0A%0Aimport static org.hamcrest.CoreMatchers.is;%0Aimport static org.junit.Assert.assertThat;%0Aimport static org.mockito.Mockito.mock;%0Aimport static org.mockito.Mockito.when;%0A%0Apublic final class PostgreSQLErrPacketFactoryTest %7B%0A    %0A    @Test%0A    public void assertPSQLExceptionWithServerErrorMessageNotNull() throws NoSuchFieldException, IllegalAccessException %7B%0A        ServerErrorMessage serverErrorMessage = mock(ServerErrorMessage.class);%0A        when(serverErrorMessage.getSeverity()).thenReturn(%22severity%22);%0A        when(serverErrorMessage.getSQLState()).thenReturn(%22sqlState%22);%0A        when(serverErrorMessage.getMessage()).thenReturn(%22message%22);%0A        when(serverErrorMessage.getPosition()).thenReturn(1);%0A        PostgreSQLErrorResponsePacket actual = PostgreSQLErrPacketFactory.newInstance(new PSQLException(serverErrorMessage));%0A        Field packetField = PostgreSQLErrorResponsePacket.class.getDeclaredField(%22fields%22);%0A        packetField.setAccessible(true);%0A        Map%3CCharacter, String%3E fields = (Map%3CCharacter, String%3E) packetField.get(actual);%0A        assertThat(fields.get(PostgreSQLErrorResponsePacket.FIELD_TYPE_SEVERITY), is(%22severity%22));%0A        assertThat(fields.get(PostgreSQLErrorResponsePacket.FIELD_TYPE_CODE), is(%22sqlState%22));%0A        assertThat(fields.get(PostgreSQLErrorResponsePacket.FIELD_TYPE_MESSAGE), is(%22message%22));%0A        assertThat(fields.get(PostgreSQLErrorResponsePacket.FIELD_TYPE_POSITION), is(%221%22));%0A    %7D%0A    %0A    @Test%0A    public void assertPSQLExceptionWithServerErrorMessageIsNull() throws NoSuchFieldException, IllegalAccessException %7B%0A        PostgreSQLErrorResponsePacket actual = PostgreSQLErrPacketFactory.newInstance(new PSQLException(%22psqlEx%22, PSQLState.UNEXPECTED_ERROR, new Exception(%22test%22)));%0A        Field packetField = PostgreSQLErrorResponsePacket.class.getDeclaredField(%22fields%22);%0A        packetField.setAccessible(true);%0A        Map%3CCharacter, String%3E fields = (Map%3CCharacter, String%3E) packetField.get(actual);%0A        assertThat(fields.get(PostgreSQLErrorResponsePacket.FIELD_TYPE_CODE), is(PSQLState.UNEXPECTED_ERROR.getState()));%0A        assertThat(fields.get(PostgreSQLErrorResponsePacket.FIELD_TYPE_MESSAGE), is(%22psqlEx%22));%0A    %7D%0A    %0A    @Test%0A    public void assertRuntimeException() throws NoSuchFieldException, IllegalAccessException %7B%0A        PostgreSQLErrorResponsePacket actual = PostgreSQLErrPacketFactory.newInstance(new RuntimeException(%22test%22));%0A        Field packetField = PostgreSQLErrorResponsePacket.class.getDeclaredField(%22fields%22);%0A        packetField.setAccessible(true);%0A        Map%3CCharacter, String%3E fields = (Map%3CCharacter, String%3E) packetField.get(actual);%0A        assertThat(fields.get(PostgreSQLErrorResponsePacket.FIELD_TYPE_MESSAGE), is(%22test%22));%0A    %7D%0A%7D%0A

add test case for PostgreSQLErrorResponsePacket (#7415)