@Test public void insertSe_matched() throws Exception { doReturn(new ReaderEvent("", "", ReaderEvent.EventType.SE_MATCHED, null)) .when(r) .processSeInserted(); waitForInsert.onActivate(); waitForInsert.onEvent(AbstractObservableLocalReader.InternalEvent.SE_INSERTED); Thread.sleep(WAIT); verify(r, times(1)).switchState(WAIT_FOR_SE_PROCESSING); }
@Override public void onEvent(AbstractObservableLocalReader.InternalEvent event) { if (logger.isTraceEnabled()) { logger.trace( "[{}] onEvent => Event {} received in currentState {}", reader.getName(), event, state); } switch (event) { case SE_INSERTED: ReaderEvent seEvent = this.reader.processSeInserted(); if (seEvent != null) { switchState(MonitoringState.WAIT_FOR_SE_PROCESSING); reader.notifyObservers(seEvent); } else { if (logger.isTraceEnabled()) { logger.trace("[{}] onEvent => Inserted SE hasn't matched", reader.getName()); } switchState(MonitoringState.WAIT_FOR_SE_REMOVAL); } break; case STOP_DETECT: switchState(MonitoringState.WAIT_FOR_START_DETECTION); break; case SE_REMOVED: if (reader.getPollingMode() == ObservableReader.PollingMode.REPEATING) { switchState(MonitoringState.WAIT_FOR_SE_INSERTION); } else { switchState(MonitoringState.WAIT_FOR_START_DETECTION); } break; default: logger.warn( "[{}] Ignore => Event {} received in currentState {}", reader.getName(), event, state); break; } }
WaitForSeInsertion extends AbstractObservableState { @Override public void onEvent(AbstractObservableLocalReader.InternalEvent event) { if (logger.isTraceEnabled()) { logger.trace( "[{}] onEvent => Event {} received in currentState {}", reader.getName(), event, state); } switch (event) { case SE_INSERTED: ReaderEvent seEvent = this.reader.processSeInserted(); if (seEvent != null) { switchState(MonitoringState.WAIT_FOR_SE_PROCESSING); reader.notifyObservers(seEvent); } else { if (logger.isTraceEnabled()) { logger.trace("[{}] onEvent => Inserted SE hasn't matched", reader.getName()); } switchState(MonitoringState.WAIT_FOR_SE_REMOVAL); } break; case STOP_DETECT: switchState(MonitoringState.WAIT_FOR_START_DETECTION); break; case SE_REMOVED: if (reader.getPollingMode() == ObservableReader.PollingMode.REPEATING) { switchState(MonitoringState.WAIT_FOR_SE_INSERTION); } else { switchState(MonitoringState.WAIT_FOR_START_DETECTION); } break; default: logger.warn( "[{}] Ignore => Event {} received in currentState {}", reader.getName(), event, state); break; } } }
WaitForSeInsertion extends AbstractObservableState { @Override public void onEvent(AbstractObservableLocalReader.InternalEvent event) { if (logger.isTraceEnabled()) { logger.trace( "[{}] onEvent => Event {} received in currentState {}", reader.getName(), event, state); } switch (event) { case SE_INSERTED: ReaderEvent seEvent = this.reader.processSeInserted(); if (seEvent != null) { switchState(MonitoringState.WAIT_FOR_SE_PROCESSING); reader.notifyObservers(seEvent); } else { if (logger.isTraceEnabled()) { logger.trace("[{}] onEvent => Inserted SE hasn't matched", reader.getName()); } switchState(MonitoringState.WAIT_FOR_SE_REMOVAL); } break; case STOP_DETECT: switchState(MonitoringState.WAIT_FOR_START_DETECTION); break; case SE_REMOVED: if (reader.getPollingMode() == ObservableReader.PollingMode.REPEATING) { switchState(MonitoringState.WAIT_FOR_SE_INSERTION); } else { switchState(MonitoringState.WAIT_FOR_START_DETECTION); } break; default: logger.warn( "[{}] Ignore => Event {} received in currentState {}", reader.getName(), event, state); break; } } WaitForSeInsertion(AbstractObservableLocalReader reader);  WaitForSeInsertion(
      AbstractObservableLocalReader reader,
      AbstractMonitoringJob monitoringJob,
      ExecutorService executorService); }
WaitForSeInsertion extends AbstractObservableState { @Override public void onEvent(AbstractObservableLocalReader.InternalEvent event) { if (logger.isTraceEnabled()) { logger.trace( "[{}] onEvent => Event {} received in currentState {}", reader.getName(), event, state); } switch (event) { case SE_INSERTED: ReaderEvent seEvent = this.reader.processSeInserted(); if (seEvent != null) { switchState(MonitoringState.WAIT_FOR_SE_PROCESSING); reader.notifyObservers(seEvent); } else { if (logger.isTraceEnabled()) { logger.trace("[{}] onEvent => Inserted SE hasn't matched", reader.getName()); } switchState(MonitoringState.WAIT_FOR_SE_REMOVAL); } break; case STOP_DETECT: switchState(MonitoringState.WAIT_FOR_START_DETECTION); break; case SE_REMOVED: if (reader.getPollingMode() == ObservableReader.PollingMode.REPEATING) { switchState(MonitoringState.WAIT_FOR_SE_INSERTION); } else { switchState(MonitoringState.WAIT_FOR_START_DETECTION); } break; default: logger.warn( "[{}] Ignore => Event {} received in currentState {}", reader.getName(), event, state); break; } } WaitForSeInsertion(AbstractObservableLocalReader reader);  WaitForSeInsertion(
      AbstractObservableLocalReader reader,
      AbstractMonitoringJob monitoringJob,
      ExecutorService executorService); @Override void onEvent(AbstractObservableLocalReader.InternalEvent event); }
WaitForSeInsertion extends AbstractObservableState { @Override public void onEvent(AbstractObservableLocalReader.InternalEvent event) { if (logger.isTraceEnabled()) { logger.trace( "[{}] onEvent => Event {} received in currentState {}", reader.getName(), event, state); } switch (event) { case SE_INSERTED: ReaderEvent seEvent = this.reader.processSeInserted(); if (seEvent != null) { switchState(MonitoringState.WAIT_FOR_SE_PROCESSING); reader.notifyObservers(seEvent); } else { if (logger.isTraceEnabled()) { logger.trace("[{}] onEvent => Inserted SE hasn't matched", reader.getName()); } switchState(MonitoringState.WAIT_FOR_SE_REMOVAL); } break; case STOP_DETECT: switchState(MonitoringState.WAIT_FOR_START_DETECTION); break; case SE_REMOVED: if (reader.getPollingMode() == ObservableReader.PollingMode.REPEATING) { switchState(MonitoringState.WAIT_FOR_SE_INSERTION); } else { switchState(MonitoringState.WAIT_FOR_START_DETECTION); } break; default: logger.warn( "[{}] Ignore => Event {} received in currentState {}", reader.getName(), event, state); break; } } WaitForSeInsertion(AbstractObservableLocalReader reader);  WaitForSeInsertion(
      AbstractObservableLocalReader reader,
      AbstractMonitoringJob monitoringJob,
      ExecutorService executorService); @Override void onEvent(AbstractObservableLocalReader.InternalEvent event);  }