ResponsePacketBuilder { public static Collection<DatabasePacket<?>> buildQueryResponsePackets(final QueryResponse queryResponse) { Collection<DatabasePacket<?>> result = new LinkedList<>(); int sequenceId = 0; List<QueryHeader> queryHeader = queryResponse.getQueryHeaders(); result.add(new MySQLFieldCountPacket(++sequenceId, queryHeader.size())); for (QueryHeader each : queryHeader) { result.add(new MySQLColumnDefinition41Packet(++sequenceId, getColumnFieldDetailFlag(each), each.getSchema(), each.getTable(), each.getTable(), each.getColumnLabel(), each.getColumnName(), each.getColumnLength(), MySQLColumnType.valueOfJDBCType(each.getColumnType()), each.getDecimals())); } result.add(new MySQLEofPacket(++sequenceId)); return result; }  static Collection<DatabasePacket<?>> buildQueryResponsePackets(final QueryResponse queryResponse); static Collection<DatabasePacket<?>> buildUpdateResponsePackets(final UpdateResponse updateResponse);  }
@Test public void assertBuildQueryResponsePackets() { QueryHeader queryHeader1 = new QueryHeader("schema1", "table1", "columnLabel1", "columnName1", 4, 5, 6, false, true, false, true); QueryHeader queryHeader2 = new QueryHeader("schema2", "table2", "columnLabel2", "columnName2", 7, 8, 9, false, true, true, true); List<QueryHeader> queryHeaders = Arrays.asList(new QueryHeader[]{queryHeader1, queryHeader2}); QueryResponse queryResponse = new QueryResponse(queryHeaders); Collection<DatabasePacket<?>> actual = ResponsePacketBuilder.buildQueryResponsePackets(queryResponse); assertThat(actual.stream().findAny().get(), anyOf(instanceOf(MySQLFieldCountPacket.class), instanceOf(MySQLColumnDefinition41Packet.class), instanceOf(MySQLEofPacket.class))); }