private static void assertChangeEvents(Collection<PortChangeEvent> earlyEvents,Collection<PortChangeEvent> lateEvents,Collection<PortChangeEvent> anytimeEvents,Collection<PortChangeEvent> actualEvents){
  String inputDesc=String.format("earlyEvents=%s, lateEvents=%s, " + "anytimeEvents=%s, actualEvents=%s",earlyEvents.toString(),lateEvents.toString(),anytimeEvents.toString(),actualEvents.toString());
  Collection<PortChangeEvent> early=new ArrayList<PortChangeEvent>(earlyEvents);
  Collection<PortChangeEvent> late=new ArrayList<PortChangeEvent>(lateEvents);
  Collection<PortChangeEvent> any=new ArrayList<PortChangeEvent>(anytimeEvents);
  for (  PortChangeEvent ev : early) {
    assertFalse("Test setup error. Early and late overlap",late.contains(ev));
    assertFalse("Test setup error. Early and anytime overlap",any.contains(ev));
  }
  for (  PortChangeEvent ev : late) {
    assertFalse("Test setup error. Late and early overlap",early.contains(ev));
    assertFalse("Test setup error. Late and any overlap",any.contains(ev));
  }
  for (  PortChangeEvent ev : any) {
    assertFalse("Test setup error. Anytime and early overlap",early.contains(ev));
    assertFalse("Test setup error. Anytime and late overlap",late.contains(ev));
  }
  for (  PortChangeEvent a : actualEvents) {
    if (early.remove(a)) {
      continue;
    }
    if (any.remove(a)) {
      continue;
    }
    if (late.remove(a)) {
      if (!early.isEmpty()) {
        fail(a + " is in late list, but haven't seen all required " + "early events. "+ inputDesc);
      }
 else {
        continue;
      }
    }
    fail(a + " was not expected. " + inputDesc);
  }
  if (!early.isEmpty())   fail("Elements left in early: " + early + ". "+ inputDesc);
  if (!late.isEmpty())   fail("Elements left in late: " + late + ". "+ inputDesc);
  if (!any.isEmpty())   fail("Elements left in any: " + any + ". "+ inputDesc);
}

private static void assertChangeEvents ( Collection < PortChangeEvent > earlyEvents , Collection < PortChangeEvent > lateEvents , Collection < PortChangeEvent > anytimeEvents , Collection < PortChangeEvent > actualEvents ) { String inputDesc = String . format ( "earlyEvents=%s, lateEvents=%s, " + "anytimeEvents=%s, actualEvents=%s" , earlyEvents . toString ( ) , lateEvents . toString ( ) , anytimeEvents . toString ( ) , actualEvents . toString ( ) ) ; Collection < PortChangeEvent > early = new ArrayList < PortChangeEvent > ( earlyEvents ) ; Collection < PortChangeEvent > late = new ArrayList < PortChangeEvent > ( lateEvents ) ; Collection < PortChangeEvent > any = new ArrayList < PortChangeEvent > ( anytimeEvents ) ; for ( PortChangeEvent ev : early ) { assertFalse ( "Test setup error. Early and late overlap" , late . contains ( ev ) ) ; assertFalse ( "Test setup error. Early and anytime overlap" , any . contains ( ev ) ) ; } for ( PortChangeEvent ev : late ) { assertFalse ( "Test setup error. Late and early overlap" , early . contains ( ev ) ) ; assertFalse ( "Test setup error. Late and any overlap" , any . contains ( ev ) ) ; } for ( PortChangeEvent ev : any ) { assertFalse ( "Test setup error. Anytime and early overlap" , early . contains ( ev ) ) ; assertFalse ( "Test setup error. Anytime and late overlap" , late . contains ( ev ) ) ; } for ( PortChangeEvent a : actualEvents ) { if ( early . remove ( a ) ) { continue ; } if ( any . remove ( a ) ) { continue ; } if ( late . remove ( a ) ) { if ( ! early . isEmpty ( ) ) { fail ( a + " is in late list, but haven't seen all required " + "early events. " + inputDesc ) ; } else { continue ; } } fail ( a + " was not expected. " + inputDesc ) ; } if ( ! early . isEmpty ( ) ) fail ( "Elements left in early: " + early + ". " + inputDesc ) ; if ( ! late . isEmpty ( ) ) fail ( "Elements left in late: " + late + ". " + inputDesc ) ; if ( ! any . isEmpty ( ) ) fail ( "Elements left in any: " + any + ". " + inputDesc ) ; }
assert that the expected portchangeevents have been recevied , asserting the expected ordering . all events in earlyevents have to appear in actualevents before any event in lateevent appears . events in anytimeevents can appear at any given time . earlyevents , lateevents , and anytimeevents must be mutually exclusive ( their intersection must be none ) and their union must contain all elements from actualevents
