title: How to check that a List contains only certain unrelated class types using junit's assertThat?
body: <p>Would appreciate some help with hamcrest and junit matchers... :)</p>
  
  <p>I'm using junit-4.11.jar and hamcrest-core-1.3.jar on Eclipse Kepler with sun's jdk 1.6.0_30.</p>
  
  <p>I have a class that holds an instance of any unknown type like so:</p>
  
  <pre><code>class UnknownClassHolder {
      private Class&lt;?&gt; clazz;
      public Class&lt;?&gt; getClazz() {
          return clazz;
      } 
      public void setClazz(Class&lt;?&gt; clazz) {
          this.clazz = clazz;
      }
  }
  </code></pre>
  
  <p>clazz can be any class.</p>
  
  <p>I want to my junit test to be something like this:</p>
  
  <pre><code>class UnknownClassHolderTest {
      @Test
      public void test() {
  
      ArrayList&lt;UnknownClassHolder&gt; list = new ArrayList&lt;UnknownClassHolder&gt;();
  
      UnknownClassHolder x = new UnknownClassHolder();
      //lets add an Integer
      x.setClazz(Integer.class);
      list.add(x);
  
      UnknownClassHolder y = new UnknownClassHolder();
      //lets add a vector
      y.setClazz(Vector.class);
      list.add(y);
  
      //now check that we added an Integer or a Vector using assertThat
      for (UnknownClassHolder u: list) {
          assertThat(u.getClazz(), anyOf(isA(Integer.class), isA(Vector.class))));
      }
  }
  }
  </code></pre>
  
  <p>Junit's assertThat doesn't like this. It doesn't compile due to Integer &amp; Vector Types not being related to each other via sub/super classes:</p>
  
  <pre><code>The method assertThat(T, Matcher&lt;? super T&gt;) in the type Assert is not applicable for the arguments (Class&lt;capture#1-of ?&gt;, AnyOf&lt;Vector&gt;)
  </code></pre>
  
  <p>Is there a more succinct way to do this other than:</p>
  
  <pre><code>assertThat(u.getClazz().getName(), either(is(Integer.class.getName())).or(is(Vector.class.getName())));
  </code></pre>
  
  <p>Is there a particular reason for using <code>Matcher&lt;? super T&gt;</code> rather than <code>Matcher&lt;?&gt;</code> in the <code>org.hamcrest.MatcherAssert.assertThat(...)</code> method?</p>
  
  <p>Thanks.</p>