CdiVaadinServletService extends VaadinServletService { @Override public void init() throws ServiceException { delegate.init(); super.init(); } CdiVaadinServletService(CdiVaadinServlet servlet,
                                   DeploymentConfiguration configuration,
                                   BeanManager beanManager); @Override void init(); @Override void fireUIInitListeners(UI ui); Optional<Instantiator> loadInstantiators(); CdiVaadinServlet getServlet();  }
@Test(expected = ServiceException.class) public void init_instantiatorInitReturnsFalse_ExceptionThrown() throws ServiceException { BeanManager mockBm = mock(BeanManager.class); Bean<Instantiator> mockBean = mock(Bean.class); Set<Bean<?>> beans = Collections.singleton(mockBean); when(mockBm.getBeans(eq(Instantiator.class), same(BeanLookup.SERVICE))) .thenReturn(beans); when(mockBm.resolve(same(beans))).thenReturn((Bean) mockBean); Instantiator mockInstantiator = mock(Instantiator.class); Context mockContext = mock(Context.class); when(mockBm.getContext(VaadinServiceScoped.class)) .thenReturn(mockContext); when(mockContext.get(same(mockBean), any())) .thenReturn(mockInstantiator); when(mockInstantiator.init(any())).thenReturn(false); initService(mockBm); verify(mockInstantiator, times(1)).init(same(service)); }