title: Asserting that a Set contains objects with methods that return given values
body: <p>Class A has a method, getId(), which returns a String.</p>
  
  <p>Class B has a method, getCollection(), that returns a Collection (the order is undefined)</p>
  
  <p>I want my test to validate that the returned collection contains instances of A, who each return expected values for getId()</p>
  
  <pre><code>public interface A {
      String getId ();
  }
  
  public interface B {
      Collection&lt;A&gt; getCollection ();
  }
  
  public class BTest {
  
      @Test
      public void test () {
          B b = ( ... )
          Collection&lt;A&gt; collection = b.getCollection();
          assertEquals(3, collection.size());
  
          String expId1 = "id1";
          String expId2 = "id2";
          String expId3 = "id3";
  
          // There should be 3 A's in this collection, each returning
          // one of the expected values in their getId()
      }
  
  }
  </code></pre>
  
  <p>I can only think of something that would be really inelegant here. I'm currently using JUnit/Hamcrest/Mockito. If the nicest solution means library, that's not a problem</p>