title: How to apply a Hamcrest matcher to the property of a class under test?
body: <p>Is there a way to build a combined Hamcrest matcher which tests an object and the property of this object? - pseudo code:</p>
  
  <pre><code>both(
    instanceof(MultipleFailureException.class)
  ).and(
    // pseudo code starts
    adapt(
      new Adapter&lt;MultipleFailureException, Iterable&lt;Throwable&gt;()
      {
        public Iterable&lt;Throwable&gt; getAdapter(MultipleFailureException item)
        {
          return item.getFailures();
        }
      }, 
      // pseudo code ends
      everyItem(instanceOf(IllegalArgumentException.class))
    )
  )
  </code></pre>
  
  <p>Background: I have a JUnit test, which iterates over a collection of dynamic objects. Each object is expected to throw an exception when processed. The exceptions are collected. The test is expected to end with a MultipleFailureException containing a collection of these thrown exceptions:</p>
  
  <pre><code>protected final ExpectedException expectation = ExpectedException.none();
  protected final ErrorCollector collector = new ErrorCollector();
  
  @Rule
  public RuleChain exceptionRules = RuleChain.outerRule(expectation).around(collector);
  
  @Test
  public void testIllegalEnumConstant()
  {
    expectation.expect(/* pseudo code from above */);
    for (Object object : ILLEGAL_OBJECTS)
    {
      try
      {
        object.processWithThrow();
      }
      catch (Throwable T)
      {
        collector.addError(T);
      }
    }
  }
  </code></pre>