Bin { @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Bin bin = (Bin) o; if (Double.compare(bin.capacity, capacity) != 0) return false; if (!items.equals(bin.items)) return false; return true; } Bin(double capacity);  Bin(double capacity, List<Item> items); List<Item> getItems(); void addItem(Item item); boolean canFit(Item item); double size(); boolean isOverflowing(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString();  }
@Test public void binsWithSameItemsInOrderAreEqual() { final List<Item> list = new ArrayList<Item>(3); final Item item1 = new Item("a", 1d); final Item item2 = new Item("b", 2d); final Item item3 = new Item("c", 3d); list.add(item1); list.add(item2); list.add(item3); final Bin bin1 = new Bin(10, list); final Bin bin2 = new Bin(10, list); final boolean binsAreEqual = bin1.equals(bin2); assertThat(binsAreEqual, is(true)); }
@Test public void binsWithSameItemsOutOfOrderAreNotEqual() { final Item item1 = new Item("a", 1d); final Item item2 = new Item("b", 2d); final Item item3 = new Item("c", 3d); final List<Item> list1 = new ArrayList<Item>(3); final List<Item> list2 = new ArrayList<Item>(3); list1.add(item1); list1.add(item2); list1.add(item3); list2.add(item2); list2.add(item3); list2.add(item1); final Bin bin1 = new Bin(10, list1); final Bin bin2 = new Bin(10, list2); final boolean binsAreEqual = bin1.equals(bin2); assertThat(binsAreEqual, is(false)); }
@Test public void binsWithDifferentItemsAreNotEqual() { final Item item1 = new Item("a", 1d); final Item item2 = new Item("b", 2d); final Item item3 = new Item("c", 3d); final List<Item> list1 = new ArrayList<Item>(2); final List<Item> list2 = new ArrayList<Item>(1); list1.add(item1); list1.add(item2); list2.add(item3); final Bin bin1 = new Bin(10, list1); final Bin bin2 = new Bin(10, list2); final boolean binsAreEqual = bin1.equals(bin2); assertThat(binsAreEqual, is(false)); }