PostgreSQLCommandExecutorFactory { public static CommandExecutor newInstance(final PostgreSQLCommandPacketType commandPacketType, final PostgreSQLCommandPacket commandPacket, final BackendConnection backendConnection) { log.debug("Execute packet type: {}, value: {}", commandPacketType, commandPacket); switch (commandPacketType) { case QUERY: return new PostgreSQLComQueryExecutor((PostgreSQLComQueryPacket) commandPacket, backendConnection); case PARSE: return new PostgreSQLComParseExecutor((PostgreSQLComParsePacket) commandPacket, backendConnection); case BIND: return new PostgreSQLComBindExecutor((PostgreSQLComBindPacket) commandPacket, backendConnection); case DESCRIBE: return new PostgreSQLComDescribeExecutor(); case EXECUTE: return new PostgreSQLComExecuteExecutor(); case SYNC: return new PostgreSQLComSyncExecutor(); case TERMINATE: return new PostgreSQLComTerminationExecutor(); default: return new PostgreSQLUnsupportedCommandExecutor(); } }  static CommandExecutor newInstance(final PostgreSQLCommandPacketType commandPacketType, final PostgreSQLCommandPacket commandPacket, final BackendConnection backendConnection);  }
@Test public void assertNewInstance() { BackendConnection backendConnection = mock(BackendConnection.class); when(backendConnection.getSchemaName()).thenReturn("schema"); Collection<InputOutput> inputOutputs = Arrays.asList( new InputOutput(PostgreSQLCommandPacketType.QUERY, PostgreSQLComQueryPacket.class, PostgreSQLComQueryExecutor.class), new InputOutput(PostgreSQLCommandPacketType.PARSE, PostgreSQLComParsePacket.class, PostgreSQLComParseExecutor.class), new InputOutput(PostgreSQLCommandPacketType.BIND, PostgreSQLComBindPacket.class, PostgreSQLComBindExecutor.class), new InputOutput(PostgreSQLCommandPacketType.DESCRIBE, null, PostgreSQLComDescribeExecutor.class), new InputOutput(PostgreSQLCommandPacketType.EXECUTE, null, PostgreSQLComExecuteExecutor.class), new InputOutput(PostgreSQLCommandPacketType.SYNC, null, PostgreSQLComSyncExecutor.class), new InputOutput(PostgreSQLCommandPacketType.TERMINATE, null, PostgreSQLComTerminationExecutor.class), new InputOutput(PostgreSQLCommandPacketType.CLOSE, null, PostgreSQLUnsupportedCommandExecutor.class) ); for (InputOutput inputOutput : inputOutputs) { Class<? extends PostgreSQLCommandPacket> commandPacketClass = inputOutput.commandPacketClass; if (null == commandPacketClass) { commandPacketClass = PostgreSQLCommandPacket.class; } CommandExecutor actual = PostgreSQLCommandExecutorFactory.newInstance(inputOutput.commandPacketType, mock(commandPacketClass), mock(BackendConnection.class)); assertThat(actual, instanceOf(inputOutput.resultClass)); } }