VpnWatchdog { void sendPacket() throws AdVpnThread.VpnNetworkException { if (!enabled) return; Log.d(TAG, "sendPacket: Sending packet, poll timeout is " + pollTimeout); DatagramPacket outPacket = new DatagramPacket(new byte[0], 0, 0 , target, 53); try { DatagramSocket socket = newDatagramSocket(); socket.send(outPacket); socket.close(); lastPacketSent = System.currentTimeMillis(); } catch (IOException e) { throw new AdVpnThread.VpnNetworkException("Received exception", e); } }    }
@Test public void testSendPacket() throws Exception { watchdog.lastPacketSent = 0; watchdog.sendPacket(); assertNotEquals(0, watchdog.lastPacketSent); }
@Test(expected = AdVpnThread.VpnNetworkException.class) public void testSendPacket_error() throws Exception { doThrow(new IOException("Cannot send")).when(mockSocket).send(any(DatagramPacket.class)); watchdog.lastPacketSent = 0; watchdog.sendPacket(); }