@Test public void returnsEmptyIfUserAgentStringCannotBeParsed() { assertThat(ProtocolAwareExceptionMapper.parseProtocolVersionFromUserAgentHeader( ImmutableList.of("I don't know what a user agent is!"))) .isEmpty(); }
@VisibleForTesting static Optional<String> parseProtocolVersionFromUserAgentHeader(@Nonnull List<String> userAgentHeader) { return userAgentHeader .stream() .map(UserAgents::tryParse) .map(UserAgent::informational) .flatMap(List::stream) .filter(agent -> agent.name().equals(AtlasDbRemotingConstants.ATLASDB_HTTP_CLIENT)) .findFirst() .map(UserAgent.Agent::version); }
ProtocolAwareExceptionMapper implements ExceptionMapper<E> { @VisibleForTesting static Optional<String> parseProtocolVersionFromUserAgentHeader(@Nonnull List<String> userAgentHeader) { return userAgentHeader .stream() .map(UserAgents::tryParse) .map(UserAgent::informational) .flatMap(List::stream) .filter(agent -> agent.name().equals(AtlasDbRemotingConstants.ATLASDB_HTTP_CLIENT)) .findFirst() .map(UserAgent.Agent::version); } }
ProtocolAwareExceptionMapper implements ExceptionMapper<E> { @VisibleForTesting static Optional<String> parseProtocolVersionFromUserAgentHeader(@Nonnull List<String> userAgentHeader) { return userAgentHeader .stream() .map(UserAgents::tryParse) .map(UserAgent::informational) .flatMap(List::stream) .filter(agent -> agent.name().equals(AtlasDbRemotingConstants.ATLASDB_HTTP_CLIENT)) .findFirst() .map(UserAgent.Agent::version); }  }
ProtocolAwareExceptionMapper implements ExceptionMapper<E> { @VisibleForTesting static Optional<String> parseProtocolVersionFromUserAgentHeader(@Nonnull List<String> userAgentHeader) { return userAgentHeader .stream() .map(UserAgents::tryParse) .map(UserAgent::informational) .flatMap(List::stream) .filter(agent -> agent.name().equals(AtlasDbRemotingConstants.ATLASDB_HTTP_CLIENT)) .findFirst() .map(UserAgent.Agent::version); }  @Override Response toResponse(E exception); }
ProtocolAwareExceptionMapper implements ExceptionMapper<E> { @VisibleForTesting static Optional<String> parseProtocolVersionFromUserAgentHeader(@Nonnull List<String> userAgentHeader) { return userAgentHeader .stream() .map(UserAgents::tryParse) .map(UserAgent::informational) .flatMap(List::stream) .filter(agent -> agent.name().equals(AtlasDbRemotingConstants.ATLASDB_HTTP_CLIENT)) .findFirst() .map(UserAgent.Agent::version); }  @Override Response toResponse(E exception);  }