@Test @SuppressWarnings("ReturnValueIgnored") public void testValidateArgument() { final Predicate<Integer> isOdd = num -> num % 2 == 1; final UnaryOperator<List<Integer>> testFn = nums -> AgentParser.validateArgument(nums, isOdd, n -> n + " is expected to be odd"); testFn.apply(ImmutableList.of(1, 3, 5, 7)); exception.expect(IllegalArgumentException.class); testFn.apply(ImmutableList.of(1, 3, 5, 7, 8)); }
@VisibleForTesting protected static <T> List<T> validateArgument(List<T> list, Predicate<T> predicate, Function<T, String> msgFn) { final Optional<T> firstInvalid = list.stream() .filter(predicate.negate()) .findAny(); if (firstInvalid.isPresent()) { throw new IllegalArgumentException(firstInvalid.map(msgFn).get()); } return list; }
AgentParser extends ServiceParser { @VisibleForTesting protected static <T> List<T> validateArgument(List<T> list, Predicate<T> predicate, Function<T, String> msgFn) { final Optional<T> firstInvalid = list.stream() .filter(predicate.negate()) .findAny(); if (firstInvalid.isPresent()) { throw new IllegalArgumentException(firstInvalid.map(msgFn).get()); } return list; } }
AgentParser extends ServiceParser { @VisibleForTesting protected static <T> List<T> validateArgument(List<T> list, Predicate<T> predicate, Function<T, String> msgFn) { final Optional<T> firstInvalid = list.stream() .filter(predicate.negate()) .findAny(); if (firstInvalid.isPresent()) { throw new IllegalArgumentException(firstInvalid.map(msgFn).get()); } return list; } AgentParser(final String... args); }
AgentParser extends ServiceParser { @VisibleForTesting protected static <T> List<T> validateArgument(List<T> list, Predicate<T> predicate, Function<T, String> msgFn) { final Optional<T> firstInvalid = list.stream() .filter(predicate.negate()) .findAny(); if (firstInvalid.isPresent()) { throw new IllegalArgumentException(firstInvalid.map(msgFn).get()); } return list; } AgentParser(final String... args); AgentConfig getAgentConfig(); }
AgentParser extends ServiceParser { @VisibleForTesting protected static <T> List<T> validateArgument(List<T> list, Predicate<T> predicate, Function<T, String> msgFn) { final Optional<T> firstInvalid = list.stream() .filter(predicate.negate()) .findAny(); if (firstInvalid.isPresent()) { throw new IllegalArgumentException(firstInvalid.map(msgFn).get()); } return list; } AgentParser(final String... args); AgentConfig getAgentConfig();  }