### Question:
CoapTcpPacketSerializer { public static CoapPacket deserialize(InetSocketAddress remoteAddress, InputStream inputStream) throws IOException, CoapException { return deserialize(remoteAddress, inputStream, true); }  static CoapPacket deserialize(InetSocketAddress remoteAddress, InputStream inputStream); static Optional<CoapPacket> deserializeIfEnoughData(InetSocketAddress remoteAddress, InputStream inputStream); static byte[] serialize(CoapPacket coapPacket); static void writeTo(OutputStream os, CoapPacket coapPacket);  }### Answer:
@Test(expected = IOException.class) public void inputStremException() throws CoapException, IOException { InputStream is = Mockito.mock(InputStream.class); when(is.read()).thenThrow(new IOException()); CoapTcpPacketSerializer.deserialize(null, is); }
@Test public void testToken() throws IOException, CoapException { ByteArrayOutputStream os = createRawPacketHeader(0, 8, null, Code.C201_CREATED.getCoapCode(), new byte[]{0, 1, 2, 3, 4, 5, 6, 7}); CoapPacket pkt = CoapTcpPacketSerializer.deserialize(null, new ByteArrayInputStream(os.toByteArray())); assertArrayEquals(new byte[]{0, 1, 2, 3, 4, 5, 6, 7}, pkt.getToken()); os = createRawPacketHeader(0, 9, null, Code.C201_CREATED.getCoapCode(), new byte[]{0, 1, 2, 3, 4, 5, 6, 7, 8}); byte[] rawData = os.toByteArray(); assertThatThrownBy(() -> CoapTcpPacketSerializer.deserialize(null, new ByteArrayInputStream(rawData)) ) .isExactlyInstanceOf(CoapMessageFormatException.class) .hasMessage("Token length invalid, should be in range 0..8"); }