@Test
public void testHandleDnsRequestEmptyPacket() throws Exception {

    UdpPacket.Builder payLoadBuilder = new UdpPacket.Builder()
            .srcPort(UdpPort.DOMAIN)
            .dstPort(UdpPort.DOMAIN)
            .srcAddr(InetAddress.getByAddress(new byte[]{8, 8, 4, 4}))
            .dstAddr(InetAddress.getByAddress(new byte[]{8, 8, 8, 8}))
            .correctChecksumAtBuild(true)
            .correctLengthAtBuild(true)
            .payloadBuilder(
                    new UnknownPacket.Builder()
                            .rawData(new byte[0])
            );
    IpPacket ipOutPacket = new IpV4Packet.Builder()
            .version(IpVersion.IPV4)
            .tos(IpV4Rfc791Tos.newInstance((byte) 0))
            .protocol(IpNumber.UDP)
            .srcAddr((Inet4Address) Inet4Address.getByAddress(new byte[]{8, 8, 4, 4}))
            .dstAddr((Inet4Address) Inet4Address.getByAddress(new byte[]{8, 8, 8, 8}))
            .correctChecksumAtBuild(true)
            .correctLengthAtBuild(true)
            .payloadBuilder(payLoadBuilder)
            .build();
    dnsPacketProxy.handleDnsRequest(ipOutPacket.getRawData());
    assertNotNull(mockEventLoop.lastOutgoing);
    assertEquals(0, mockEventLoop.lastOutgoing.getLength());
    assertEquals(Inet4Address.getByAddress(new byte[]{8, 8, 8, 8}), mockEventLoop.lastOutgoing.getAddress());
    assertNull(mockEventLoop.lastResponse);
    // Check the same thing with one upstream DNS server configured.
    tinySetUp();
    dnsPacketProxy.upstreamDnsServers.add(Inet4Address.getByAddress(new byte[]{1, 1, 1, 2}));
    dnsPacketProxy.handleDnsRequest(ipOutPacket.getRawData());
    assertNull(mockEventLoop.lastOutgoing);
    assertNull(mockEventLoop.lastResponse);
    // Check the same thing with enough upstream DNS servers configured.
    tinySetUp();
    for (byte i = 2; i < 9; i++)
        dnsPacketProxy.upstreamDnsServers.add(Inet4Address.getByAddress(new byte[]{1, 1, 1, i}));
    dnsPacketProxy.handleDnsRequest(ipOutPacket.getRawData());
    assertNotNull(mockEventLoop.lastOutgoing);
    assertEquals(0, mockEventLoop.lastOutgoing.getLength());
    assertEquals(Inet4Address.getByAddress(new byte[]{1, 1, 1, 8}), mockEventLoop.lastOutgoing.getAddress());
    assertNull(mockEventLoop.lastResponse);
}