### Question:
ServerParser { public static void encodePacket(Packet packet, boolean supportsBinary, Parser.EncodeCallback callback) { if (packet.data instanceof byte[]) { encodeByteArray(packet, supportsBinary, callback); } else { String encoded = String.valueOf(packets.get(packet.type)); if (null != packet.data) { encoded += String.valueOf(packet.data); } ((Parser.EncodeCallback<String>) callback).call(encoded); } } private  ServerParser(); static void encodePacket(Packet packet, boolean supportsBinary, Parser.EncodeCallback callback); static void encodePayload(List<Packet<?>> packets, boolean supportsBinary, Parser.EncodeCallback callback); @SuppressWarnings("Duplicates") static void encodePayloadAsBinary(List<Packet<?>> packets, Parser.EncodeCallback<byte[]> callback); static Packet decodePacket(Object data); static void decodePayload(Object data, Parser.DecodePayloadCallback callback); @SuppressWarnings("WeakerAccess")
    static final int PROTOCOL; }### Answer:
@Test public void testEncodePacket_string() { final Packet<String> packet = new Packet<>(Packet.MESSAGE); packet.data = "Hello World"; ServerParser.encodePacket(packet, false, data -> { String result = runScriptAndGetOutput("src/test/resources/testEncodePacket_string.js", packet.data, String.class); assertEquals(result, data); }); packet.data = "Engine.IO"; ServerParser.encodePacket(packet, false, data -> { String result = runScriptAndGetOutput("src/test/resources/testEncodePacket_string.js", packet.data, String.class); assertEquals(result, data); }); }
@Test public void testEncodePacket_binary() { final Packet<byte[]> packet = new Packet<>(Packet.MESSAGE); packet.data = new byte[] { 1, 2, 3, 4, 5 }; ServerParser.encodePacket(packet, true, data -> { byte[] result = runScriptAndGetOutput("src/test/resources/testEncodePacket_binary.js", packet.data, byte[].class); assertArrayEquals(result, (byte[]) data); }); }
@Test public void testEncodePacket_base64() { final Packet<byte[]> packet = new Packet<>(Packet.MESSAGE); packet.data = new byte[] { 1, 2, 3, 4, 5 }; ServerParser.encodePacket(packet, false, data -> { String result = runScriptAndGetOutput("src/test/resources/testEncodePacket_base64.js", packet.data, String.class); assertEquals(result, data); }); }