@Test
public void should_fail_with_invalid_request() throws Exception {

    //missing previous blocks
    assertThatThrownBy(() ->
            bwReq.appendBlock(newCoapPacket(LOCAL_5683).block1Req(2, BlockSize.S_512, false).payload(new byte[512]).get().build())
    ).isExactlyInstanceOf(CoapRequestEntityIncomplete.class);
    //size too large for defined capabilities
    assertThatThrownBy(() ->
            bwReq.appendBlock(newCoapPacket(LOCAL_5683).size1(11_000).block1Req(0, BlockSize.S_512, true).payload(new byte[512]).get().build())
    ).isExactlyInstanceOf(CoapRequestEntityTooLarge.class);
    //payload size does not match block size
    assertCodeException(Code.C413_REQUEST_ENTITY_TOO_LARGE, () ->
            bwReq.appendBlock(newCoapPacket(LOCAL_5683).block1Req(0, BlockSize.S_512, true).payload(new byte[100]).get().build())
    );
    //no payload
    assertCodeException(Code.C400_BAD_REQUEST, () ->
            bwReq.appendBlock(newCoapPacket(LOCAL_5683).block1Req(0, BlockSize.S_512, true).get().build())
    );
    //last block and payload size larger that block size
    assertCodeException(Code.C400_BAD_REQUEST, () ->
            bwReq.appendBlock(newCoapPacket(LOCAL_5683).block1Req(2, BlockSize.S_512, false).payload(new byte[600]).get().build())
    );
}