EphemerisModuleHandlerFactory extends BaseModuleHandlerFactory implements ModuleHandlerFactory { @Override protected @Nullable ModuleHandler internalCreate(final Module module, final String ruleUID) { final String moduleTypeUID = module.getTypeUID(); logger.trace("create {} -> {} : {}", module.getId(), moduleTypeUID, ruleUID); if (module instanceof Condition) { switch (moduleTypeUID) { case EphemerisConditionHandler.HOLIDAY_MODULE_TYPE_ID: case EphemerisConditionHandler.WEEKEND_MODULE_TYPE_ID: case EphemerisConditionHandler.WEEKDAY_MODULE_TYPE_ID: case EphemerisConditionHandler.DAYSET_MODULE_TYPE_ID: return new EphemerisConditionHandler((Condition) module, ephemerisManager); } } logger.error("The ModuleHandler is not supported: {}", moduleTypeUID); return null; } @Activate  EphemerisModuleHandlerFactory(final @Reference EphemerisManager ephemerisManager); @Override Collection<String> getTypes();  }
@Test public void testFactoryFailsCreatingModuleHandlerForDaysetCondition() { when(moduleMock.getTypeUID()).thenReturn(EphemerisConditionHandler.DAYSET_MODULE_TYPE_ID); when(moduleMock.getConfiguration()).thenReturn(new Configuration()); assertThrows(IllegalArgumentException.class, () -> factory.internalCreate(moduleMock, "My first rule")); }
@Test public void testFactoryCreatesModuleHandlerForDaysetCondition() { when(moduleMock.getTypeUID()).thenReturn(EphemerisConditionHandler.DAYSET_MODULE_TYPE_ID); when(moduleMock.getConfiguration()).thenReturn(new Configuration(Map.of("dayset", "school"))); ModuleHandler handler = factory.internalCreate(moduleMock, "My second rule"); assertThat(handler, is(notNullValue())); assertThat(handler, instanceOf(EphemerisConditionHandler.class)); }
@Test public void testFactoryCreatesModuleHandlerForWeekdayCondition() { when(moduleMock.getTypeUID()).thenReturn(EphemerisConditionHandler.WEEKDAY_MODULE_TYPE_ID); when(moduleMock.getConfiguration()).thenReturn(new Configuration()); ModuleHandler handler = factory.internalCreate(moduleMock, "My first rule"); assertThat(handler, is(notNullValue())); assertThat(handler, instanceOf(EphemerisConditionHandler.class)); when(moduleMock.getConfiguration()).thenReturn(new Configuration(Map.of("offset", 5))); handler = factory.internalCreate(moduleMock, "My second rule"); assertThat(handler, is(notNullValue())); assertThat(handler, instanceOf(EphemerisConditionHandler.class)); }