@Test public void followPathEventIssuerType() { final MovingRoadUser user = new TestRoadUser(); model.addObjectAt(user, SW); final ListenerEventHistory list = new ListenerEventHistory(); model.getEventAPI().addListener(list, RoadEventType.MOVE); assertTrue(list.getHistory().isEmpty()); model.followPath(user, newLinkedList(asList(SW, SE, NE, NW)), TimeLapseFactory.create(0, 10)); assertEquals(1, list.getHistory().size()); assertEquals(RoadEventType.MOVE, list.getHistory().get(0).getEventType()); assertEquals(model, list.getHistory().get(0).getIssuer()); }
@Override public void afterTick(TimeLapse timeLapse) { assertThat(leh.getEventTypeHistory()).containsExactly( ClockEventType.STARTED); } });
/** * Tests that STOPPED event is dispatched when an exception occurs. */ @Test public void testStoppedEventOnException() { final ListenerEventHistory history = new ListenerEventHistory(); getModel().getEventAPI().addListener(history, Clock.ClockEventType.STOPPED); getModel().register(new TickListener() { @Override public void tick(TimeLapse timeLapse) { if (timeLapse.getStartTime() >= 300) { throw new IllegalStateException("Test"); } } @Override public void afterTick(TimeLapse timeLapse) {} }); boolean failure = false; try { getModel().start(); } catch (final IllegalStateException e) { assertThat(e.getMessage()).isEqualTo("Test"); assertThat(history.getEventTypeHistory()).containsExactly( ClockEventType.STOPPED); failure = true; } assertThat(failure).isTrue(); }
ListenerEventHistory history = new ListenerEventHistory(); graph1.getEventAPI().addListener(history); graph1.merge(graph2); history.getEventTypeHistory()); assertEquals(2, history.getHistory().size()); assertEquals( new GraphEvent(ADD_CONNECTION, graph1, Connection.create(a, c, Optional.<ConnectionData>absent())), history .getHistory().get(0)); assertEquals( new GraphEvent(ADD_CONNECTION, graph1, Connection.create(c, a, Optional.<ConnectionData>absent())), history .getHistory().get(1));
@Test public void testTransition() { final ListenerEventHistory history = new ListenerEventHistory(); fsm.getEventAPI() .addListener(history, StateMachine.StateMachineEvent.values()); history.clear(); fsm.handle(Events.SPEZIAL, SPECIAL_CONTEXT); assertEquals(startState, fsm.getCurrentState()); assertEquals(2, history.getHistory().size()); assertTrue(((StateTransitionEvent) history.getHistory().get(0)) .equalTo(startState, Events.SPEZIAL, specialState)); assertTrue(((StateTransitionEvent) history.getHistory().get(1)) .equalTo(specialState, Events.START, startState)); assertFalse(((StateTransitionEvent) history.getHistory().get(1)) .equalTo(startState, Events.START, startState)); assertFalse(((StateTransitionEvent) history.getHistory().get(1)) .equalTo(specialState, Events.PAUSE, startState)); assertFalse(((StateTransitionEvent) history.getHistory().get(1)) .equalTo(specialState, Events.START, specialState));
@Before public void setup() { l1 = new ListenerEventHistory(); l2 = new ListenerEventHistory(); l3 = new ListenerEventHistory(); dispatcher = new EventDispatcher(EVENT1, EVENT2, EVENT3); api = dispatcher.getPublicEventAPI(); }
/** * Tests that the same device is used again upon re-registering. */ @Test public void testRegisterUnregistered() { final ListenerEventHistory leh = new ListenerEventHistory(); model.getEventAPI().addListener(leh, EventTypes.ADD_COMM_USER, EventTypes.REMOVE_COMM_USER); final CommDevice originalDevice = agent1.device(); assertThat(model.contains(agent1)).isTrue(); model.unregister(agent1); assertThat(model.contains(agent1)).isFalse(); assertThat(leh.getEventTypeHistory()).containsExactly(REMOVE_COMM_USER) .inOrder(); model.register(agent1); assertThat(model.contains(agent1)).isTrue(); final CommDevice newDevice = agent1.device(); assertThat(originalDevice).isSameAs(newDevice); assertThat(leh.getEventTypeHistory()).containsExactly(REMOVE_COMM_USER, ADD_COMM_USER) .inOrder(); newDevice.broadcast(Contents.HELLO_WORLD); }
final ListenerEventHistory eventHistory = new ListenerEventHistory(); solvers.get(0).solve(SolveArgs.create()); verify(clock, times(1)).switchToRealTime(); assertThat(eventHistory.getHistory()).isEmpty(); verify(clock, times(1)).switchToSimulatedTime(); assertThat(eventHistory.getEventTypeHistory()) .containsExactly(EventType.NEW_SCHEDULE); assertThat(solvers.get(0).isScheduleUpdated()).isTrue();
assertFalse(dispatcher.containsListener(l2, OTHER_EVENT1)); dispatcher.removeListener(new ListenerEventHistory());
ListenerEventHistory history = new ListenerEventHistory(); ListenableGraph<LengthData> graph = new ListenableGraph<>( new MultimapGraph<LengthData>()); assertEquals(asList(ADD_CONNECTION), history.getEventTypeHistory()); history.getEventTypeHistory()); assertEquals( asList(ADD_CONNECTION, ADD_CONNECTION, ADD_CONNECTION, ADD_CONNECTION), history.getEventTypeHistory()); asList(ADD_CONNECTION, ADD_CONNECTION, ADD_CONNECTION, ADD_CONNECTION, REMOVE_CONNECTION), history.getEventTypeHistory()); asList(ADD_CONNECTION, ADD_CONNECTION, ADD_CONNECTION, ADD_CONNECTION, REMOVE_CONNECTION, CHANGE_CONNECTION_DATA), history.getEventTypeHistory()); REMOVE_CONNECTION, CHANGE_CONNECTION_DATA, REMOVE_CONNECTION, REMOVE_CONNECTION, REMOVE_CONNECTION), history.getEventTypeHistory());
@Test public void moveToEventIssuerType() { final MovingRoadUser user = new TestRoadUser(); model.addObjectAt(user, SW); final ListenerEventHistory list = new ListenerEventHistory(); model.getEventAPI().addListener(list, RoadEventType.MOVE); assertTrue(list.getHistory().isEmpty()); model.moveTo(user, NW, TimeLapseFactory.create(0, 10)); assertEquals(1, list.getHistory().size()); assertEquals(RoadEventType.MOVE, list.getHistory().get(0).getEventType()); assertEquals(model, list.getHistory().get(0).getIssuer()); }
@Override public void tick(TimeLapse timeLapse) { intervals.add(Range.openClosed(timeLapse.getStartTime(), timeLapse.getEndTime())); assertThat(leh.getEventTypeHistory()).containsExactly( ClockEventType.STARTED); }
final ListenerEventHistory leh = new ListenerEventHistory(); getModel().getEventAPI().addListener(leh, ClockEventType.values()); assertThat(leh.getEventTypeHistory()).isEmpty(); getModel().start(); assertThat(intervals).hasSize(2); Range.openClosed(model.getTickLength(), model.getTickLength() * 2)) .inOrder(); assertThat(leh.getEventTypeHistory()).containsExactly( ClockEventType.STARTED, ClockEventType.STOPPED);
/** * Test event dispatching. */ @Test public void testEvent() { final ListenerEventHistory history = new ListenerEventHistory(); model.getEventAPI().addListener(history, EventTypes.ADD_COMM_USER); final CommUser agent6 = new RangedAgent(new Point(6, 6), 4); model.register(agent6); assertEquals(1, history.getHistory().size()); assertTrue(history.getHistory().get(0) instanceof CommModelEvent); final CommModelEvent event = (CommModelEvent) history.getHistory().get(0); assertSame(agent6, event.getUser()); assertSame(model, event.getIssuer()); assertSame(agent6, model.getUsersAndDevices().inverse().get(event.getDevice())); }
assertEquals(asList(), l1.getEventTypeHistory()); assertEquals(asList(EVENT2), l2.getEventTypeHistory()); assertEquals(asList(EVENT2), l3.getEventTypeHistory()); assertEquals(asList(), l1.getEventTypeHistory()); assertEquals(asList(EVENT2), l2.getEventTypeHistory()); assertEquals(asList(EVENT2, EVENT3), l3.getEventTypeHistory()); assertEquals(asList(EVENT1), l1.getEventTypeHistory()); assertEquals(asList(EVENT2, EVENT1), l2.getEventTypeHistory()); assertEquals(asList(EVENT2, EVENT3, EVENT1), l3.getEventTypeHistory()); assertEquals(asList(EVENT1), l1.getEventTypeHistory()); assertEquals(asList(EVENT2, EVENT1), l2.getEventTypeHistory()); assertEquals(asList(EVENT2, EVENT3, EVENT1, EVENT3), l3.getEventTypeHistory());
getModel().switchToSimulatedTime(); assertThat(getModel().getClockMode()).isEqualTo(ClockMode.SIMULATED); final ListenerEventHistory history = new ListenerEventHistory(); getModel().getEventAPI().addListener(history, ImmutableSet.<Enum<?>>builder() assertThat(history.getEventTypeHistory()).containsExactly( ClockEventType.STARTED, RtClockEventType.SWITCH_TO_SIM_TIME,
final ListenerEventHistory history = new ListenerEventHistory(); fsm.getEventAPI() .addListener(history, StateMachine.StateMachineEvent.values()); assertTrue(stopState.onEntryHistory().isEmpty()); assertTrue(stopState.onExitHistory().isEmpty()); assertTrue(history.getHistory().isEmpty()); assertEquals(1, stopState.onEntryHistory().size()); assertEquals(1, stopState.onExitHistory().size()); assertEquals(1, history.getHistory().size()); assertEquals( new StateTransitionEvent<>(fsm, stopState, Events.RECURSIVE, stopState), history.getHistory().get(0)); } else { assertTrue(stopState.onEntryHistory().isEmpty()); assertTrue(stopState.onExitHistory().isEmpty()); assertTrue(history.getHistory().isEmpty());
assertThat(history.getEventTypeHistory()).containsExactly( ClockEventType.STARTED, RtClockEventType.SWITCH_TO_SIM_TIME); assertThat(history.getEventTypeHistory()).containsExactly( ClockEventType.STARTED, RtClockEventType.SWITCH_TO_SIM_TIME); } else { assertThat(history.getEventTypeHistory()).containsExactly( ClockEventType.STARTED, RtClockEventType.SWITCH_TO_SIM_TIME, assertThat(getModel().getClockMode()).isEqualTo(ClockMode.SIMULATED); if (timeLapse.getTime() == 100000) { assertThat(history.getEventTypeHistory()).containsExactly( ClockEventType.STARTED, RtClockEventType.SWITCH_TO_SIM_TIME); } else { assertThat(history.getEventTypeHistory()).containsExactly( ClockEventType.STARTED, RtClockEventType.SWITCH_TO_SIM_TIME, assertThat(getModel().getClockMode()).isEqualTo(ClockMode.REAL_TIME); if (timeLapse.getTime() == 100100) { assertThat(history.getEventTypeHistory()).containsExactly( ClockEventType.STARTED, RtClockEventType.SWITCH_TO_SIM_TIME, RtClockEventType.SWITCH_TO_REAL_TIME); } else { assertThat(history.getEventTypeHistory()).containsExactly( ClockEventType.STARTED, RtClockEventType.SWITCH_TO_SIM_TIME,
/** * Test starting and stopping time. */ @Test public void testStartStop() { final LimitingTickListener ltl = new LimitingTickListener(getModel(), 3); final ListenerEventHistory leh = new ListenerEventHistory(); getModel().getEventAPI().addListener(leh, ClockEventType.values()); getModel().register(ltl); getModel().start(); assertEquals(3 * getModel().getTickLength(), getModel().getCurrentTime()); getModel().start(); assertEquals(6 * getModel().getTickLength(), getModel().getCurrentTime()); assertThat(leh.getEventTypeHistory()).isEqualTo( asList( ClockEventType.STARTED, ClockEventType.STOPPED, ClockEventType.STARTED, ClockEventType.STOPPED)); }
final ListenerEventHistory leh = new ListenerEventHistory(); d.stateMachine.getEventAPI().addListener(leh, StateMachineEvent.STATE_TRANSITION); assertEquals(0, leh.getHistory().size()); assertFalse(d.gotoState.destination.isPresent()); assertFalse(d.gotoState.prevDestination.isPresent()); tick(5, 6); assertEquals(d.gotoState, d.stateMachine.getCurrentState()); assertEquals(1, leh.getHistory().size()); assertEquals(p1, d.gotoState.getDestination()); assertFalse(d.gotoState.prevDestination.isPresent()); final StateTransitionEvent<StateEvent, RouteFollowingVehicle> ev1 = (StateTransitionEvent<StateEvent, RouteFollowingVehicle>) leh .getHistory().get(0); assertEquals(DefaultEvent.GOTO, ev1.trigger); assertEquals(d.waitState, ev1.previousState); assertEquals(2, leh.getHistory().size()); @SuppressWarnings("unchecked") final StateTransitionEvent<StateEvent, RouteFollowingVehicle> ev2 = (StateTransitionEvent<StateEvent, RouteFollowingVehicle>) leh .getHistory().get(1); assertEquals(DefaultEvent.REROUTE, ev2.trigger); assertEquals(d.gotoState, ev2.previousState); assertEquals(p1, d.gotoState.getPreviousDestination()); } else {