use of com.qcadoo.localization.api.TranslationService in project qcadoo by qcadoo.
the class ComponentPatternTest method shouldHaveValidInstance.
@Test
@SuppressWarnings("unchecked")
public void shouldHaveValidInstance() throws Exception {
// given
InternalViewDefinitionState viewDefinitionState = mock(InternalViewDefinitionState.class);
TranslationService translationService = mock(TranslationService.class);
ApplicationContext applicationContext = mock(ApplicationContext.class);
InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
ComponentDefinition componentDefinition = getComponentDefinition("testName", null);
componentDefinition.setTranslationService(translationService);
componentDefinition.setApplicationContext(applicationContext);
componentDefinition.setViewDefinition(viewDefinition);
AbstractComponentPattern pattern = new FormComponentPattern(componentDefinition);
ViewEventListenerHook viewEventListenerHook = mock(ViewEventListenerHook.class);
given(viewEventListenerHook.getEventName()).willReturn("save");
pattern.addCustomEvent(viewEventListenerHook);
// when
ComponentState state = pattern.createComponentState(viewDefinitionState);
// then
assertTrue(state instanceof FormComponent);
EventHandlerHolder eventHandlerHolder = (EventHandlerHolder) getField(state, "eventHandlerHolder");
Map<String, List<EventHandlerHolder.EventHandler>> eventHandlers = (Map<String, List<EventHandlerHolder.EventHandler>>) getField(eventHandlerHolder, "eventHandlers");
List<EventHandlerHolder.EventHandler> handlers = eventHandlers.get("save");
assertNotNull(handlers);
assertEquals(2, handlers.size());
assertEquals(viewEventListenerHook, handlers.get(1));
}
Aggregations