### Question:
BlockWiseTransfer { int updateWithFirstBlock(CoapPacket coapPacket) { return updateWithFirstBlock(coapPacket, capabilities.getOrDefault(coapPacket.getRemoteAddress())); } BlockWiseTransfer(CoapTcpCSMStorage capabilities);   }### Answer:
@Test public void should_set_first_block_header_for_request() { capabilities.put(LOCAL_5683, new CoapTcpCSM(512, true)); CoapPacket coap = newCoapPacket(LOCAL_5683).payload(new byte[2000]).post().build(); assertEquals(1, bwt.updateWithFirstBlock(coap)); assertEquals(2000, coap.headers().getSize1().intValue()); assertEquals(new BlockOption(0, BlockSize.S_512, true), coap.headers().getBlock1Req()); assertNull(coap.headers().getSize2Res()); assertNull(coap.headers().getBlock2Res()); assertEquals(512, coap.getPayload().length); }
@Test public void should_set_first_block_header_for_request_bert() { capabilities.put(LOCAL_5683, new CoapTcpCSM(3300, true)); CoapPacket coap = newCoapPacket(LOCAL_5683).payload(new byte[5000]).post().build(); assertEquals(2, bwt.updateWithFirstBlock(coap)); assertEquals(5000, coap.headers().getSize1().intValue()); assertEquals(new BlockOption(0, BlockSize.S_1024_BERT, true), coap.headers().getBlock1Req()); assertNull(coap.headers().getSize2Res()); assertNull(coap.headers().getBlock2Res()); assertEquals(2048, coap.getPayload().length); }
@Test public void should_set_first_block_header_for_observation() { capabilities.put(LOCAL_5683, new CoapTcpCSM(512, true)); CoapPacket coap = newCoapPacket(LOCAL_5683).payload(new byte[2000]).ack(Code.C205_CONTENT).build(); assertEquals(1, bwt.updateWithFirstBlock(coap)); assertEquals(2000, coap.headers().getSize2Res().intValue()); assertEquals(new BlockOption(0, BlockSize.S_512, true), coap.headers().getBlock2Res()); assertNull(coap.headers().getSize1()); assertNull(coap.headers().getBlock1Req()); assertEquals(512, coap.getPayload().length); }