MySQLComStmtExecuteExecutor implements QueryCommandExecutor { @Override public Collection<DatabasePacket<?>> execute() throws SQLException { if (ProxyContext.getInstance().getSchemaContexts().isCircuitBreak()) { throw new CircuitBreakException(); } BackendResponse backendResponse = databaseCommunicationEngine.execute(); return backendResponse instanceof QueryResponse ? processQuery((QueryResponse) backendResponse) : processUpdate((UpdateResponse) backendResponse); } MySQLComStmtExecuteExecutor(final MySQLComStmtExecutePacket packet, final BackendConnection backendConnection); @Override Collection<DatabasePacket<?>> execute(); @Override boolean next(); @Override MySQLPacket getQueryData();  }
@Test public void assertIsQueryResponse() throws NoSuchFieldException, SQLException { BackendConnection backendConnection = mock(BackendConnection.class); when(backendConnection.getSchemaName()).thenReturn("schema"); MySQLComStmtExecuteExecutor mysqlComStmtExecuteExecutor = new MySQLComStmtExecuteExecutor(mock(MySQLComStmtExecutePacket.class), backendConnection); FieldSetter.setField(mysqlComStmtExecuteExecutor, MySQLComStmtExecuteExecutor.class.getDeclaredField("databaseCommunicationEngine"), databaseCommunicationEngine); when(databaseCommunicationEngine.execute()).thenReturn(new QueryResponse(Collections.singletonList(mock(QueryHeader.class)))); mysqlComStmtExecuteExecutor.execute(); assertThat(mysqlComStmtExecuteExecutor.getResponseType(), is(ResponseType.QUERY)); }
@Test public void assertIsUpdateResponse() throws NoSuchFieldException, SQLException { BackendConnection backendConnection = mock(BackendConnection.class); when(backendConnection.getSchemaName()).thenReturn("schema"); MySQLComStmtExecuteExecutor mysqlComStmtExecuteExecutor = new MySQLComStmtExecuteExecutor(mock(MySQLComStmtExecutePacket.class), backendConnection); FieldSetter.setField(mysqlComStmtExecuteExecutor, MySQLComStmtExecuteExecutor.class.getDeclaredField("databaseCommunicationEngine"), databaseCommunicationEngine); when(databaseCommunicationEngine.execute()).thenReturn(new UpdateResponse()); mysqlComStmtExecuteExecutor.execute(); assertThat(mysqlComStmtExecuteExecutor.getResponseType(), is(ResponseType.UPDATE)); }