PostgreSQLCommandPacketFactory { public static PostgreSQLCommandPacket newInstance( final PostgreSQLCommandPacketType commandPacketType, final PostgreSQLPacketPayload payload, final int connectionId) throws SQLException { switch (commandPacketType) { case QUERY: return new PostgreSQLComQueryPacket(payload); case PARSE: return new PostgreSQLComParsePacket(payload); case BIND: return new PostgreSQLComBindPacket(payload, connectionId); case DESCRIBE: return new PostgreSQLComDescribePacket(payload); case EXECUTE: return new PostgreSQLComExecutePacket(payload); case SYNC: return new PostgreSQLComSyncPacket(payload); case TERMINATE: return new PostgreSQLComTerminationPacket(payload); default: return new PostgreSQLUnsupportedCommandPacket(commandPacketType.getValue()); } }  static PostgreSQLCommandPacket newInstance(
            final PostgreSQLCommandPacketType commandPacketType, final PostgreSQLPacketPayload payload, final int connectionId);  }
@Test public void assertNewInstanceWithQueryComPacket() throws SQLException { assertThat(PostgreSQLCommandPacketFactory.newInstance(PostgreSQLCommandPacketType.QUERY, payload, 1), instanceOf(PostgreSQLComQueryPacket.class)); }
@Test public void assertNewInstanceWithParseComPacket() throws SQLException { when(payload.readInt4()).thenReturn(1); when(payload.readStringNul()).thenReturn("stat-id"); when(payload.readStringNul()).thenReturn("SELECT * FROM t_order"); when(payload.readInt2()).thenReturn(0); assertThat(PostgreSQLCommandPacketFactory.newInstance(PostgreSQLCommandPacketType.PARSE, payload, 1), instanceOf(PostgreSQLComParsePacket.class)); }
@Test public void assertNewInstanceWithBindComPacket() throws SQLException { when(payload.readInt4()).thenReturn(1); when(payload.readStringNul()).thenReturn("stat-id"); when(payload.readStringNul()).thenReturn("SELECT * FROM t_order"); when(payload.readInt2()).thenReturn(0); BinaryStatementRegistry.getInstance().register(1); assertThat(PostgreSQLCommandPacketFactory.newInstance(PostgreSQLCommandPacketType.BIND, payload, 1), instanceOf(PostgreSQLComBindPacket.class)); }
@Test public void assertNewInstanceWithDescribeComPacket() throws SQLException { assertThat(PostgreSQLCommandPacketFactory.newInstance(PostgreSQLCommandPacketType.DESCRIBE, payload, 1), instanceOf(PostgreSQLComDescribePacket.class)); }
@Test public void assertNewInstanceWithExecuteComPacket() throws SQLException { assertThat(PostgreSQLCommandPacketFactory.newInstance(PostgreSQLCommandPacketType.EXECUTE, payload, 1), instanceOf(PostgreSQLComExecutePacket.class)); }
@Test public void assertNewInstanceWithSyncComPacket() throws SQLException { assertThat(PostgreSQLCommandPacketFactory.newInstance(PostgreSQLCommandPacketType.SYNC, payload, 1), instanceOf(PostgreSQLComSyncPacket.class)); }
@Test public void assertNewInstanceWithTerminationComPacket() throws SQLException { assertThat(PostgreSQLCommandPacketFactory.newInstance(PostgreSQLCommandPacketType.TERMINATE, payload, 1), instanceOf(PostgreSQLComTerminationPacket.class)); }
@Test public void assertNewInstanceWithUnsupportedComPacket() throws SQLException { assertThat(PostgreSQLCommandPacketFactory.newInstance(PostgreSQLCommandPacketType.PORTAL_SUSPENDED, payload, 1), instanceOf(PostgreSQLUnsupportedCommandPacket.class)); }