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