CustomerComparator implements Comparator<Customer> { public int compare(Customer o1, Customer o2) { if (sort == Sort.NAME) { return o1.getName().compareToIgnoreCase(o2.getName()); } else { return o1.getCode().compareToIgnoreCase(o2.getCode()); } } CustomerComparator();  CustomerComparator(Sort sort); int compare(Customer o1, Customer o2);  }
@Test public void testCompare() { Customer c1 = new Customer(); c1.setName("aa"); Customer c2 = new Customer(); c2.setName("bb"); assertEquals(-1, new CustomerComparator().compare(c1, c2)); }