Java Code Examples for com.nike.internal.util.Pair#getValue()

The following examples show how to use com.nike.internal.util.Pair#getValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AccessLogger.java    From riposte with Apache License 2.0 6 votes vote down vote up
/**
 * Converts the given key/value pair to a string. By default this converts nulls to hyphens '-' and then joins the
 * key and value with an equals sign between '='. So for example a key of foo and value of bar would be returned as
 * foo=bar. A key of foo and null value would be returned as foo=-
 */
protected @NotNull String formatAdditionPairForLogMessage(@Nullable Pair<String, String> pair) {
    if (pair == null) {
        return "-";
    }

    String key = pair.getKey();
    String value = pair.getValue();

    if (key == null) {
        key = "-";
    }

    if (value == null) {
        value = "-";
    }

    return key + "=" + value;
}
 
Example 2
Source File: HttpChannelInitializerTest.java    From riposte with Apache License 2.0 4 votes vote down vote up
@Test
public void initChannel_adds_HttpServerCodec_with_config_values_coming_from_httpRequestDecoderConfig() {
    // given
    HttpChannelInitializer hci = basicHttpChannelInitializerNoUtilityHandlers();
    HttpRequestDecoderConfig configWithCustomValues = new HttpRequestDecoderConfig() {
        @Override
        public int maxInitialLineLength() {
            return 123;
        }

        @Override
        public int maxHeaderSize() {
            return 456;
        }

        @Override
        public int maxChunkSize() {
            return 789;
        }
    };
    Whitebox.setInternalState(hci, "httpRequestDecoderConfig", configWithCustomValues);

    // when
    hci.initChannel(socketChannelMock);

    // then
    ArgumentCaptor<ChannelHandler> channelHandlerArgumentCaptor = ArgumentCaptor.forClass(ChannelHandler.class);
    verify(channelPipelineMock, atLeastOnce()).addLast(anyString(), channelHandlerArgumentCaptor.capture());
    List<ChannelHandler> handlers = channelHandlerArgumentCaptor.getAllValues();
    Pair<Integer, HttpServerCodec> httpServerCodecHandlerPair = findChannelHandler(handlers, HttpServerCodec.class);

    Assertions.assertThat(httpServerCodecHandlerPair).isNotNull();

    HttpServerCodec httpServerCodecHandler = httpServerCodecHandlerPair.getValue();
    HttpRequestDecoder decoderHandler = (HttpRequestDecoder) Whitebox.getInternalState(httpServerCodecHandler, "inboundHandler");
    int actualMaxInitialLineLength = extractField(extractField(decoderHandler, "lineParser"), "maxLength");
    int actualMaxHeaderSize = extractField(extractField(decoderHandler, "headerParser"), "maxLength");
    int actualMaxChunkSize = extractField(decoderHandler, "maxChunkSize");

    Assertions.assertThat(actualMaxInitialLineLength).isEqualTo(configWithCustomValues.maxInitialLineLength());
    Assertions.assertThat(actualMaxHeaderSize).isEqualTo(configWithCustomValues.maxHeaderSize());
    Assertions.assertThat(actualMaxChunkSize).isEqualTo(configWithCustomValues.maxChunkSize());
}