title: How to test the identity and an associativity constraints of a java-8 custom Collector
body: <p>I have written a custom Collector for Java 8. Its aggregator is a Map containing a pair of lists:</p>
  
  <pre><code>    @Override
      public Supplier&lt;Map&lt;Boolean, List&lt;Object&gt;&gt;&gt; supplier() {
          return () -&gt; {
              Map&lt;Boolean, List&lt;Object&gt;&gt; map = new HashMap&lt;&gt;(2);
              map.put(false, new ArrayList&lt;&gt;());
              map.put(true, new ArrayList&lt;&gt;());
              return map;
          };
      }
  </code></pre>
  
  <p>so I think its combiner is this:</p>
  
  <pre><code>    @Override
      public BinaryOperator&lt;Map&lt;Boolean, List&lt;Object&gt;&gt;&gt; combiner() {
          return (a, b) -&gt; {
              a.get(false).addAll(b.get(false));
              a.get(true).addAll(b.get(true));
              return a;
          };
      }
  </code></pre>
  
  <p>I would like to test the Collector to make sure that if and when it processes a stream in parallel, the result is correct.</p>
  
  <p>How can I write a unit test that exercises this?</p>
  
  <p>Of course I can write a test that calls the <code>combiner</code> directly, but that's not what I want. I want evidence it works in the context of collecting.</p>
  
  <p>The Javadoc for <code>Collector</code> says:</p>
  
  <blockquote>
    <p>To ensure that sequential and parallel executions produce equivalent results, the collector functions must satisfy an identity and an associativity constraints.</p>
  </blockquote>
  
  <p>Could I achieve confidence in my Collector by testing these constraints? How?</p>