@Test
  public void testGetPosition() throws Exception {
    AlarmPoint underTest = createAlarm("testGetPosition");
    alarmSystem.addAlarmListener(this);
    AlarmHistory hist = underTest.history();
    underTest.trigger(AlarmPoint.TRIGGER_ACTIVATE);
    underTest.trigger(AlarmPoint.TRIGGER_DEACTIVATE);
    underTest.trigger(AlarmPoint.TRIGGER_ACTIVATE);
    underTest.trigger(AlarmPoint.TRIGGER_DEACTIVATE);
    underTest.trigger(AlarmPoint.TRIGGER_DEACTIVATE);
    underTest.trigger(AlarmPoint.TRIGGER_ACTIVATE);

    assertEquals(5, eventCounter);
    assertEquals(5, hist.allAlarmEvents().get().size());

    AlarmEvent event = hist.eventAt(-1);
    assertNull(event);
    event = hist.eventAt(5);
    assertNull(event);
    event = hist.eventAt(0);
    assertEquals("activation", event.systemName().get());
    event = hist.eventAt(1);
    assertEquals("deactivation", event.systemName().get());
    event = hist.eventAt(2);
    assertEquals("activation", event.systemName().get());
    event = hist.eventAt(3);
    assertEquals("deactivation", event.systemName().get());
    event = hist.eventAt(4);
    assertEquals("activation", event.systemName().get());
  }
  @Test
  public void testSetMaxSize() throws Exception {
    AlarmPoint underTest = createAlarm("testSetMaxSize");
    alarmSystem.addAlarmListener(this);
    AlarmHistory hist = underTest.history();
    assertEquals(0, hist.allAlarmEvents().get().size());
    underTest.trigger(AlarmPoint.TRIGGER_ACTIVATE);
    assertEquals(1, hist.allAlarmEvents().get().size());
    underTest.trigger(AlarmPoint.TRIGGER_DEACTIVATE);
    assertEquals(2, hist.allAlarmEvents().get().size());
    underTest.trigger(AlarmPoint.TRIGGER_ACTIVATE);
    assertEquals(3, hist.allAlarmEvents().get().size());
    underTest.trigger(AlarmPoint.TRIGGER_DEACTIVATE);
    assertEquals(4, hist.allAlarmEvents().get().size());

    int maxsize = hist.maxSize().get();
    assertEquals(30, maxsize);

    hist.maxSize()
        .set(3); // The Qi4j version doesn't intercept the maxSize().set() method and purge the old
    underTest.trigger(AlarmPoint.TRIGGER_ACTIVATE); // so we do another event to purge.
    assertEquals(3, hist.allAlarmEvents().get().size());

    hist.maxSize().set(0);
    underTest.trigger(AlarmPoint.TRIGGER_DEACTIVATE); // so we do another event to purge.
    assertEquals(0, hist.allAlarmEvents().get().size());
    underTest.trigger(AlarmPoint.TRIGGER_ACTIVATE);
    assertEquals(0, hist.allAlarmEvents().get().size());
    underTest.trigger(AlarmPoint.TRIGGER_DEACTIVATE);
    assertEquals(0, hist.allAlarmEvents().get().size());
    hist.maxSize().set(2);
    assertEquals(0, hist.allAlarmEvents().get().size());
    underTest.trigger(AlarmPoint.TRIGGER_ACTIVATE);
    assertEquals(1, hist.allAlarmEvents().get().size());
    underTest.trigger(AlarmPoint.TRIGGER_DEACTIVATE);
    assertEquals(2, hist.allAlarmEvents().get().size());
    underTest.trigger(AlarmPoint.TRIGGER_ACTIVATE);
    assertEquals(2, hist.allAlarmEvents().get().size());
    assertEquals(11, eventCounter);
  }
 private AlarmPoint createAlarm(String name) {
   ServiceReference<AlarmSystem> ref = module.findService(AlarmSystem.class);
   alarmSystem = ref.get();
   return alarmSystem.createAlarm(name, createCategory("AlarmHistoryTest"));
 }