@Test public void write_does_not_do_anything_with_state_if_msg_is_HttpResponse_but_state_is_null() throws Exception { // given HttpResponse msgMock = mock(HttpResponse.class); doReturn(null).when(stateAttrMock).get(); // when handler.write(ctxMock, msgMock, promiseMock); // then verifyNoMoreInteractions(stateMock); }
@Test public void write_calls_setActualResponseObject_on_state_if_msg_is_HttpResponse() throws Exception { // given HttpResponse msgMock = mock(HttpResponse.class); // when handler.write(ctxMock, msgMock, promiseMock); // then verify(stateMock).setActualResponseObject(msgMock); }
@Test public void write_adds_to_finalContentLength_if_msg_is_HttpContent_and_finalContentLength_is_not_null() throws Exception { // given HttpContent msgMock = mock(HttpContent.class); ByteBuf contentMock = mock(ByteBuf.class); int contentBytes = (int)(Math.random() * 10000); doReturn(contentMock).when(msgMock).content(); doReturn(contentBytes).when(contentMock).readableBytes(); int initialFinalContentLengthValue = (int)(Math.random() * 10000); responseInfo.setFinalContentLength((long)initialFinalContentLengthValue); assertThat(responseInfo.getFinalContentLength()).isEqualTo(initialFinalContentLengthValue); // when handler.write(ctxMock, msgMock, promiseMock); // then assertThat(responseInfo.getFinalContentLength()).isEqualTo(initialFinalContentLengthValue + contentBytes); }
@Test public void write_sets_finalContentLength_if_msg_is_HttpContent_and_finalContentLength_is_null() throws Exception { // given HttpContent msgMock = mock(HttpContent.class); ByteBuf contentMock = mock(ByteBuf.class); int contentBytes = (int)(Math.random() * 10000); doReturn(contentMock).when(msgMock).content(); doReturn(contentBytes).when(contentMock).readableBytes(); assertThat(responseInfo.getFinalContentLength()).isNull(); // when handler.write(ctxMock, msgMock, promiseMock); // then assertThat(responseInfo.getFinalContentLength()).isEqualTo(contentBytes); }
@Test public void write_does_nothing_to_finalContentLength_if_msg_is_HttpContent_but_state_is_null() throws Exception { // given HttpContent msgMock = mock(HttpContent.class); ByteBuf contentMock = mock(ByteBuf.class); int contentBytes = (int)(Math.random() * 10000); doReturn(contentMock).when(msgMock).content(); doReturn(contentBytes).when(contentMock).readableBytes(); doReturn(null).when(stateAttrMock).get(); assertThat(responseInfo.getFinalContentLength()).isNull(); // when handler.write(ctxMock, msgMock, promiseMock); // then assertThat(responseInfo.getFinalContentLength()).isNull(); }
@Test public void write_does_nothing_to_finalContentLength_if_msg_is_HttpContent_but_responseInfo_is_null() throws Exception { // given HttpContent msgMock = mock(HttpContent.class); ByteBuf contentMock = mock(ByteBuf.class); int contentBytes = (int)(Math.random() * 10000); doReturn(contentMock).when(msgMock).content(); doReturn(contentBytes).when(contentMock).readableBytes(); doReturn(null).when(stateMock).getResponseInfo(); assertThat(responseInfo.getFinalContentLength()).isNull(); // when handler.write(ctxMock, msgMock, promiseMock); // then assertThat(responseInfo.getFinalContentLength()).isNull(); } }