CourseMeetingCompareByRoomAndStreetAddress implements
               Comparator<CourseMeeting> { @Override public int compare(CourseMeeting cm1, CourseMeeting cm2) { if(cm1 == cm2) return 0; if(null == cm1) return -1; if(null == cm2) return +1; if(cm1.getLocation() == cm2.getLocation()) return 0; if(null == cm1.getLocation()) return -1; if(null == cm2.getLocation()) return +1; if(!(cm1.getLocation().getRoom() == cm2.getLocation().getRoom())) { if(null == cm1.getLocation().getRoom()) return -1; if(null == cm2.getLocation().getRoom()) return +1; return (cm1.getLocation().getRoom().compareTo(cm2.getLocation().getRoom())); } else { if(cm1.getLocation().getStreetAddress() == cm2.getLocation().getStreetAddress()) return 0; if(null == cm1.getLocation().getStreetAddress()) return -1; if(null == cm2.getLocation().getStreetAddress()) return +1; return (cm1.getLocation().getStreetAddress().compareTo(cm2.getLocation().getStreetAddress())); } }  @Override int compare(CourseMeeting cm1, CourseMeeting cm2);  }
@Test public void testCompareNullCourseMeetings() { CourseMeeting senCM = null; CourseMeeting colinCM = null; assertEquals("They are not equal",0, new CourseMeetingCompareByRoomAndStreetAddress().compare(senCM,colinCM)); }
@Test public void testCompareNullCourseMeetingWithNonNull() { CourseMeeting senCM = null; CourseMeeting mikeCM = new CourseMeeting(); assertEquals("They are not equal",-1, new CourseMeetingCompareByRoomAndStreetAddress().compare(senCM,mikeCM)); assertEquals("They are not equal",+1, new CourseMeetingCompareByRoomAndStreetAddress().compare(mikeCM,senCM)); }
@Test public void testCompareCourseMeetingsSame() { CourseMeeting cm1 = new CourseMeeting(); CourseMeeting cm2 = new CourseMeeting(); Location location1 = new Location(); location1.setDisplayName("Van Hise"); location1.setRoom("207"); location1.setStreetAddress("1305 Linden Drive"); cm1.setLocation(location1); Location location2 = new Location(); location2.setDisplayName("Van Hise"); location2.setRoom("207"); location2.setStreetAddress("1305 Linden Drive"); cm2.setLocation(location2); assertEquals("They are not equal",0, new CourseMeetingCompareByRoomAndStreetAddress().compare(cm1,cm2)); }
@Test public void testCompareCourseMeetingsSameLocationDifferentRoom() { CourseMeeting cm1 = new CourseMeeting(); CourseMeeting cm2 = new CourseMeeting(); Location location1 = new Location(); location1.setDisplayName("Van Hise"); location1.setRoom("207"); location1.setStreetAddress("1305 Linden Drive"); cm1.setLocation(location1); Location location2 = new Location(); location2.setDisplayName("Van Hise"); location2.setRoom("307"); location2.setStreetAddress("1305 Linden Drive"); cm2.setLocation(location2); assertEquals("They are not equal",-1, new CourseMeetingCompareByRoomAndStreetAddress().compare(cm1,cm2)); assertEquals("They are not equal",+1, new CourseMeetingCompareByRoomAndStreetAddress().compare(cm2,cm1)); }
@Test public void testCompareCourseMeetingsSameOneLocationNullBothWays() { CourseMeeting cm1 = new CourseMeeting(); CourseMeeting cm2 = new CourseMeeting(); Location location1 = new Location(); location1.setDisplayName("Van Hise"); location1.setRoom("207"); location1.setStreetAddress("1305 Linden Drive"); cm1.setLocation(location1); Location location2 = new Location(); location2.setDisplayName("Van Hise"); location2.setRoom("307"); location2.setStreetAddress("1305 Linden Drive"); assertEquals("They are not equal",-1, new CourseMeetingCompareByRoomAndStreetAddress().compare(cm2,cm1)); assertEquals("They are not equal",+1, new CourseMeetingCompareByRoomAndStreetAddress().compare(cm1,cm2)); }
@Test public void testCompareCourseMeetingsSameStreetAddressDifferent() { CourseMeeting cm1 = new CourseMeeting(); CourseMeeting cm2 = new CourseMeeting(); Location location1 = new Location(); location1.setDisplayName("Van Hise"); location1.setRoom("207"); location1.setStreetAddress("1305 Linden Drive"); cm1.setLocation(location1); Location location2 = new Location(); location2.setDisplayName("Van Hise"); location2.setRoom("207"); location2.setStreetAddress("1306 Linden Drive"); cm2.setLocation(location2); assertEquals("They are not equal",+1, new CourseMeetingCompareByRoomAndStreetAddress().compare(cm2,cm1)); assertEquals("They are not equal",-1, new CourseMeetingCompareByRoomAndStreetAddress().compare(cm1,cm2)); }
@Test public void testCompareCourseMeetingsSameStreetAddressDifferentFirstNull() { CourseMeeting cm1 = new CourseMeeting(); CourseMeeting cm2 = new CourseMeeting(); Location location1 = new Location(); location1.setDisplayName("Van Hise"); location1.setRoom("207"); location1.setStreetAddress(null); cm1.setLocation(location1); Location location2 = new Location(); location2.setDisplayName("Van Hise"); location2.setRoom("207"); location2.setStreetAddress("1305 Linden Drive"); cm2.setLocation(location2); assertEquals("They are not equal",-1, new CourseMeetingCompareByRoomAndStreetAddress().compare(cm1,cm2)); }
@Test public void testCompareCourseMeetingsSameStreetAddressDifferentSecondNull() { CourseMeeting cm1 = new CourseMeeting(); CourseMeeting cm2 = new CourseMeeting(); Location location1 = new Location(); location1.setDisplayName("Van Hise"); location1.setRoom("207"); location1.setStreetAddress("1305 Linden Drive"); cm1.setLocation(location1); Location location2 = new Location(); location2.setDisplayName("Van Hise"); location2.setRoom("207"); location2.setStreetAddress(null); cm2.setLocation(location2); assertEquals("They are not equal",+1, new CourseMeetingCompareByRoomAndStreetAddress().compare(cm1,cm2)); }
@Test public void testCompareCourseMeetingsSameRoomNull() { CourseMeeting cm1 = new CourseMeeting(); CourseMeeting cm2 = new CourseMeeting(); Location location1 = new Location(); location1.setDisplayName("Van Hise"); location1.setRoom("207"); location1.setStreetAddress("1305 Linden Drive"); cm1.setLocation(location1); Location location2 = new Location(); location2.setDisplayName("Van Hise"); location2.setStreetAddress("1306 Linden Drive"); cm2.setLocation(location2); assertEquals("They are not equal",-1, new CourseMeetingCompareByRoomAndStreetAddress().compare(cm2,cm1)); assertEquals("They are not equal",+1, new CourseMeetingCompareByRoomAndStreetAddress().compare(cm1,cm2)); }