title: HashSet in unit tests
body: <p>I have a bunch of methods returning HashSet. I would like my unit test to check the state of these objects i.e confirm that <code>someObject.getName() == "foobar"</code>. </p>
  
  <p>However the hashset iterator order is not guaranteed so my unit tests fail some times. How do I write unit tests for something like this?</p>
  
  <p>Eg:</p>
  
  <pre><code>@Test
      public void testRowsToBeRead(){
          HashSet&lt;SomeObject&gt; rows = new SomeObject().read();
          assertEquals(19, rows.size());
  
          for(SomeObject r:rows){
              //How do I confirm contents?
          }
      }
  </code></pre>
  
  <p>I think I might have accepted an answer too soon.</p>
  
  <p>The problem I now have is that I have implemented the equals method, which checks only for 2 fields in the object per design (it is mimicking a DB table).
  However in my unit test, I want to check for all fields like description etc which is not in my equals. So if 2 of fields get swapped and these fields are not in my equals implementation, then the unit test gives a false positive.</p>