PostgreSQLComParseExecutor implements CommandExecutor { @Override public Collection<DatabasePacket<?>> execute() { if (!packet.getSql().isEmpty()) { SQLStatement sqlStatement = ProxyContext.getInstance().getSchemaContexts().getSqlParserEngine().parse(packet.getSql(), true); binaryStatementRegistry.register(packet.getStatementId(), packet.getSql(), sqlStatement.getParameterCount(), packet.getBinaryStatementParameterTypes()); } return Collections.singletonList(new PostgreSQLParseCompletePacket()); } PostgreSQLComParseExecutor(final PostgreSQLComParsePacket packet, final BackendConnection backendConnection); @Override Collection<DatabasePacket<?>> execute();  }
@Test public void assertNewInstance() throws NoSuchFieldException, IllegalAccessException { when(parsePacket.getSql()).thenReturn("sql"); when(parsePacket.getStatementId()).thenReturn("2"); when(backendConnection.getConnectionId()).thenReturn(1); Field schemaContexts = ProxyContext.getInstance().getClass().getDeclaredField("schemaContexts"); schemaContexts.setAccessible(true); schemaContexts.set(ProxyContext.getInstance(), new StandardSchemaContexts(getSchemas(), mockSQLParserEngine(), mock(ExecutorKernel.class), new Authentication(), new ConfigurationProperties(new Properties()), new MySQLDatabaseType())); BinaryStatementRegistry.getInstance().register(1); PostgreSQLComParseExecutor actual = new PostgreSQLComParseExecutor(parsePacket, backendConnection); assertThat(actual.execute().iterator().next(), instanceOf(PostgreSQLParseCompletePacket.class)); }
@Test public void assertGetSqlWithNull() { when(parsePacket.getSql()).thenReturn(""); when(backendConnection.getConnectionId()).thenReturn(1); PostgreSQLComParseExecutor actual = new PostgreSQLComParseExecutor(parsePacket, backendConnection); assertThat(actual.execute().iterator().next(), instanceOf(PostgreSQLParseCompletePacket.class)); }