@Test(expected = IllegalStateException.class)
public void failWhenIOExceptionWhenWriting() throws Exception {

    OutputStream outputStream = mock(OutputStream.class);
    doThrow(new IOException()).when(outputStream).write(any());
    new CoapPacket(null).writeTo(outputStream);
}