title: How to use assertThat Contains any order method for list comparison in Junit (java)
body: <p>I want to test <code>ShipmentEntityBO</code> method using <code>assertThat &amp; Contains</code> any order. The below test function is not working since list has returned the object. Please advise me.</p>
  
  <pre><code>public class ShipmentEntityBO {
      public void addShipmentEntityToList(List&lt;ShipmentEntity&gt; shipmentEntityList,String shipmentDetails) {
          String splited[] = shipmentDetails.split(",");
          shipmentEntityList.add(new ShipmentEntity(new Integer(splited[0]), splited[1],
                      splited[2], new Long(splited[3]), splited[4]));
      }
  }
  </code></pre>
  
  <p><strong>Junit code</strong></p>
  
  <pre><code>import java.util.ArrayList;
  import java.util.Arrays;
  import org.junit.Before;
  import org.junit.Test;
  import static org.hamcrest.CoreMatchers.equalTo;
  import static org.hamcrest.CoreMatchers.is;
  import static org.hamcrest.MatcherAssert.assertThat;
  import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
  import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder;
  import static org.hamcrest.collection.IsIterableContainingInOrder.contains;
  
  public class Junit {
  
      ShipmentEntityBO shipmentEntityBO;
  
      @Before
      public void createObjectForShipmentEntity() {
          shipmentEntityBO = new ShipmentEntityBO();  
      }
  
      @Test
      public void testListofShipmentEntity() {
          ArrayList&lt;ShipmentEntity&gt; list = new ArrayList&lt;ShipmentEntity&gt;();
          String details = "101,pavi,12345,8500,Toronto";
          shipmentEntityBO.addShipmentEntityToList(list, details);
          assertThat(list,containsInAnyOrder("Toronto","pavi",101,"12345",8500)); 
      }
  }
  </code></pre>