ProjectAssignmentAggregateComparator implements Comparator<AssignmentAggregateReportElement>, Serializable { public int compare(AssignmentAggregateReportElement o1, AssignmentAggregateReportElement o2) { int compare = 0; switch (sortType) { case SORT_ON_PROJECT: compare = compareOnProject(o1, o2); break; case SORT_ON_CUSTOMER: compare = o1.getProjectAssignment().getProject().getCustomer().getName() .compareToIgnoreCase(o2.getProjectAssignment().getProject().getCustomer().getName()); if (compare == 0) { compare = compareOnProject(o1, o2); } break; } return compare; } ProjectAssignmentAggregateComparator(int sortType); int compare(AssignmentAggregateReportElement o1, AssignmentAggregateReportElement o2); static final int SORT_ON_CUSTOMER; static final int SORT_ON_PROJECT; }
@Test public void testCompareProject() { int x = new ProjectAssignmentAggregateComparator(ProjectAssignmentAggregateComparator.SORT_ON_PROJECT).compare(a1, a2); assertTrue(x < 0); }
@Test public void testCompareCustomer() { int x = new ProjectAssignmentAggregateComparator(ProjectAssignmentAggregateComparator.SORT_ON_CUSTOMER).compare(a1, a2); assertTrue(x < 0); }