Class CollectorTester<T,​A,​R>


  • @Beta
    @GwtCompatible
    public final class CollectorTester<T,​A,​R>
    extends java.lang.Object
    Tester for Collector implementations.

    Example usage:

     CollectorTester.of(Collectors.summingInt(Integer::parseInt))
         .expectCollects(3, "1", "2")
         .expectCollects(10, "1", "4", "3", "2")
         .expectCollects(5, "-3", "0", "8");
     
    Since:
    21.0
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      (package private) static class  CollectorTester.CollectStrategy
      Different orderings for combining the elements of an input array, which must all produce the same result.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.stream.Collector<T,​A,​R> collector  
      private java.util.function.BiPredicate<? super R,​? super R> equivalence  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private CollectorTester​(java.util.stream.Collector<T,​A,​R> collector, java.util.function.BiPredicate<? super R,​? super R> equivalence)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void assertEquivalent​(R expected, R actual)  
      private void doExpectCollects​(R expectedResult, java.util.List<T> inputs)  
      CollectorTester<T,​A,​R> expectCollects​(R expectedResult, T... inputs)
      Verifies that the specified expected result is always produced by collecting the specified inputs, regardless of how the elements are divided.
      static <T,​A,​R>
      CollectorTester<T,​A,​R>
      of​(java.util.stream.Collector<T,​A,​R> collector)
      Creates a CollectorTester for the specified Collector.
      static <T,​A,​R>
      CollectorTester<T,​A,​R>
      of​(java.util.stream.Collector<T,​A,​R> collector, java.util.function.BiPredicate<? super R,​? super R> equivalence)
      Creates a CollectorTester for the specified Collector.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • collector

        private final java.util.stream.Collector<T,​A,​R> collector
      • equivalence

        private final java.util.function.BiPredicate<? super R,​? super R> equivalence
    • Constructor Detail

      • CollectorTester

        private CollectorTester​(java.util.stream.Collector<T,​A,​R> collector,
                                java.util.function.BiPredicate<? super R,​? super R> equivalence)
    • Method Detail

      • of

        public static <T,​A,​R> CollectorTester<T,​A,​R> of​(java.util.stream.Collector<T,​A,​R> collector)
        Creates a CollectorTester for the specified Collector. The result of the Collector will be compared to the expected value using Object.equals.
      • of

        public static <T,​A,​R> CollectorTester<T,​A,​R> of​(java.util.stream.Collector<T,​A,​R> collector,
                                                                                java.util.function.BiPredicate<? super R,​? super R> equivalence)
        Creates a CollectorTester for the specified Collector. The result of the Collector will be compared to the expected value using the specified equivalence.
      • expectCollects

        @SafeVarargs
        public final CollectorTester<T,​A,​R> expectCollects​(R expectedResult,
                                                                       T... inputs)
        Verifies that the specified expected result is always produced by collecting the specified inputs, regardless of how the elements are divided.
      • doExpectCollects

        private void doExpectCollects​(R expectedResult,
                                      java.util.List<T> inputs)
      • assertEquivalent

        private void assertEquivalent​(R expected,
                                      R actual)