use of com.vaadin.flow.di.DefaultInstantiator in project flow by vaadin.
the class EventUtilTest method setUp.
@Before
public void setUp() {
VaadinSession session = Mockito.mock(VaadinSession.class);
UI ui = new UI() {
@Override
public VaadinSession getSession() {
return session;
}
};
VaadinService service = Mockito.mock(VaadinService.class);
when(session.getService()).thenReturn(service);
DefaultInstantiator instantiator = new DefaultInstantiator(service);
when(service.getInstantiator()).thenReturn(instantiator);
UI.setCurrent(ui);
}
use of com.vaadin.flow.di.DefaultInstantiator in project flow by vaadin.
the class CustomElementRegistryInitializerTest method setup.
@Before
public void setup() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
Field customElements = CustomElementRegistry.class.getDeclaredField("customElements");
customElements.setAccessible(true);
customElements.set(CustomElementRegistry.getInstance(), new AtomicReference<>());
customElementRegistryInitializer = new CustomElementRegistryInitializer();
VaadinSession session = Mockito.mock(VaadinSession.class);
UI ui = new UI() {
@Override
public VaadinSession getSession() {
return session;
}
};
VaadinService service = Mockito.mock(VaadinService.class);
when(session.getService()).thenReturn(service);
DefaultInstantiator instantiator = new DefaultInstantiator(service);
when(service.getInstantiator()).thenReturn(instantiator);
UI.setCurrent(ui);
}
use of com.vaadin.flow.di.DefaultInstantiator in project flow by vaadin.
the class VaadinService method createInstantiator.
/**
* Creates an instantiator to use with this service.
* <p>
* A custom Vaadin service implementation can override this method to pick
* an instantiator. The method {@link #loadInstantiators()} is used to find
* a custom instantiator. If there is no one found then the default is used.
* You may override this method or {@link #loadInstantiators()} in your
* custom service.
*
* @return an instantiator to use, not <code>null</code>
*
* @throws ServiceException
* if there are multiple applicable instantiators
*
* @see #loadInstantiators()
* @see Instantiator
*/
protected Instantiator createInstantiator() throws ServiceException {
return loadInstantiators().orElseGet(() -> {
DefaultInstantiator defaultInstantiator = new DefaultInstantiator(this);
defaultInstantiator.init(this);
return defaultInstantiator;
});
}
use of com.vaadin.flow.di.DefaultInstantiator in project flow by vaadin.
the class ComponentTest method setup.
@Before
public void setup() {
divWithTextComponent = new TestComponent(ElementFactory.createDiv("Test component"));
parentDivComponent = new TestComponent(ElementFactory.createDiv());
child1SpanComponent = new TestComponent(ElementFactory.createSpan("Span"));
child2InputComponent = new TestComponent(ElementFactory.createInput());
parentDivComponent.getElement().appendChild(child1SpanComponent.getElement(), child2InputComponent.getElement());
VaadinSession session = Mockito.mock(VaadinSession.class);
UI ui = new UI() {
@Override
public VaadinSession getSession() {
return session;
}
};
VaadinService service = Mockito.mock(VaadinService.class);
when(session.getService()).thenReturn(service);
DefaultInstantiator instantiator = new DefaultInstantiator(service);
when(service.getInstantiator()).thenReturn(instantiator);
UI.setCurrent(ui);
}
use of com.vaadin.flow.di.DefaultInstantiator in project flow by vaadin.
the class PolymerTemplateTest method setUp.
@SuppressWarnings("serial")
@Before
public void setUp() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
executionOrder.clear();
executionParams.clear();
Field customElements = CustomElementRegistry.class.getDeclaredField("customElements");
customElements.setAccessible(true);
customElements.set(CustomElementRegistry.getInstance(), new AtomicReference<>());
Map<String, Class<? extends Component>> map = new HashMap<>();
map.put("child-template", TemplateChild.class);
map.put("ffs", TestPolymerTemplate.class);
map.put("execution-child", ExecutionChild.class);
CustomElementRegistry.getInstance().setCustomElements(map);
VaadinSession session = Mockito.mock(VaadinSession.class);
UI ui = new UI() {
private Page page = new Page(this) {
@Override
public ExecutionCanceler executeJavaScript(String expression, Serializable... parameters) {
executionOrder.add(expression);
executionParams.add(parameters);
return () -> true;
}
};
@Override
public VaadinSession getSession() {
return session;
}
@Override
public Page getPage() {
return page;
}
};
VaadinService service = Mockito.mock(VaadinService.class);
when(session.getService()).thenReturn(service);
DefaultInstantiator instantiator = new DefaultInstantiator(service);
when(service.getInstantiator()).thenReturn(instantiator);
UI.setCurrent(ui);
}
Aggregations