| 12 | import static org.junit.Assert.fail; |
| 13 | |
| 14 | @RunWith(JUnit4.class) |
| 15 | public class Helpers { |
| 16 | |
| 17 | private static Parser.Encoder encoder = new IOParser.Encoder(); |
| 18 | |
| 19 | public static void test(final Packet obj) { |
| 20 | encoder.encode(obj, new Parser.Encoder.Callback() { |
| 21 | @Override |
| 22 | public void call(Object[] encodedPackets) { |
| 23 | Parser.Decoder decoder = new IOParser.Decoder(); |
| 24 | decoder.onDecoded(new Parser.Decoder.Callback() { |
| 25 | @Override |
| 26 | public void call(Packet packet) { |
| 27 | assertPacket(packet, obj); |
| 28 | } |
| 29 | }); |
| 30 | decoder.add((String)encodedPackets[0]); |
| 31 | } |
| 32 | }); |
| 33 | } |
| 34 | |
| 35 | public static void testDecodeError(final String errorMessage) { |
| 36 | Parser.Decoder decoder = new IOParser.Decoder(); |
| 37 | try { |
| 38 | decoder.add(errorMessage); |
| 39 | fail(); |
| 40 | } catch (DecodingException e) {} |
| 41 | } |
| 42 | |
| 43 | @SuppressWarnings("unchecked") |
| 44 | public static void testBin(final Packet obj) { |
| 45 | final Object originalData = obj.data; |
| 46 | encoder.encode(obj, new Parser.Encoder.Callback() { |
| 47 | @Override |
| 48 | public void call(Object[] encodedPackets) { |
| 49 | Parser.Decoder decoder = new IOParser.Decoder(); |
| 50 | decoder.onDecoded(new Parser.Decoder.Callback() { |
| 51 | @Override |
| 52 | public void call(Packet packet) { |
| 53 | obj.data = originalData; |
| 54 | obj.attachments = -1; |
| 55 | assertPacket(packet, obj); |
| 56 | } |
| 57 | }); |
| 58 | |
| 59 | for (Object packet : encodedPackets) { |
| 60 | if (packet instanceof String) { |
| 61 | decoder.add((String)packet); |
| 62 | } else if (packet instanceof byte[]) { |
| 63 | decoder.add((byte[])packet); |
| 64 | } |
| 65 | } |
| 66 | } |
| 67 | }); |
| 68 | } |
| 69 | |
| 70 | public static void assertPacket(Packet expected, Packet actual) { |
| 71 | assertThat(actual.type, is(expected.type)); |
nothing calls this directly
no outgoing calls
no test coverage detected