@Test(expected = IOException.class)
public void outputStremException() throws CoapException, IOException {

    OutputStream os = Mockito.mock(OutputStream.class);
    doThrow(new IOException()).when(os).write(any());
    CoapPacket cp = new CoapPacket(null, null, "", null);
    CoapTcpPacketSerializer.writeTo(os, cp);
}