@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");
}