Itinerary implements Serializable { public boolean isExpected(HandlingEvent event) { if (legs.isEmpty()) { return true; } if (event.getType() == HandlingEvent.Type.RECEIVE) { Leg leg = legs.get(0); return (leg.getLoadLocation().equals(event.getLocation())); } if (event.getType() == HandlingEvent.Type.LOAD) { for (Leg leg : legs) { if (leg.getLoadLocation().sameIdentityAs(event.getLocation()) && leg.getVoyage().sameIdentityAs(event.getVoyage())) { return true; } } return false; } if (event.getType() == HandlingEvent.Type.UNLOAD) { for (Leg leg : legs) { if (leg.getUnloadLocation().equals(event.getLocation()) && leg.getVoyage().equals(event.getVoyage())) { return true; } } return false; } if (event.getType() == HandlingEvent.Type.CLAIM) { Leg leg = getLastLeg(); return (leg.getUnloadLocation().equals(event.getLocation())); } return true; } Itinerary();  Itinerary(List<Leg> legs); List<Leg> getLegs(); boolean isExpected(HandlingEvent event); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); static final Itinerary EMPTY_ITINERARY; }
@Test public void testCargoOnTrack() { TrackingId trackingId = new TrackingId("CARGO1"); RouteSpecification routeSpecification = new RouteSpecification( SampleLocations.SHANGHAI, SampleLocations.GOTHENBURG, new Date()); Cargo cargo = new Cargo(trackingId, routeSpecification); Itinerary itinerary = new Itinerary(Arrays.asList(new Leg(voyage, SampleLocations.SHANGHAI, SampleLocations.ROTTERDAM, new Date(), new Date()), new Leg(voyage, SampleLocations.ROTTERDAM, SampleLocations.GOTHENBURG, new Date(), new Date()))); HandlingEvent event = new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.RECEIVE, SampleLocations.SHANGHAI); assertTrue(itinerary.isExpected(event)); event = new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.LOAD, SampleLocations.SHANGHAI, voyage); assertTrue(itinerary.isExpected(event)); event = new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.UNLOAD, SampleLocations.ROTTERDAM, voyage); assertTrue(itinerary.isExpected(event)); event = new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.LOAD, SampleLocations.ROTTERDAM, voyage); assertTrue(itinerary.isExpected(event)); event = new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.UNLOAD, SampleLocations.GOTHENBURG, voyage); assertTrue(itinerary.isExpected(event)); event = new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.CLAIM, SampleLocations.GOTHENBURG); assertTrue(itinerary.isExpected(event)); event = new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.CUSTOMS, SampleLocations.GOTHENBURG); assertTrue(itinerary.isExpected(event)); event = new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.RECEIVE, SampleLocations.HANGZOU); assertFalse(itinerary.isExpected(event)); event = new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.LOAD, SampleLocations.ROTTERDAM, wrongVoyage); assertFalse(itinerary.isExpected(event)); event = new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.UNLOAD, SampleLocations.HELSINKI, wrongVoyage); assertFalse(itinerary.isExpected(event)); event = new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.CLAIM, SampleLocations.ROTTERDAM); assertFalse(itinerary.isExpected(event)); }