@Test public void detachNoScope() { // given prepAttach(); ui.attach(); // when ui.detach(); // then // no exception }
@SuppressWarnings("deprecation") private void prepAttach() { when(request.getParameter("v-loc")).thenReturn(baseUri + "/#home"); ui.getPage().init(request); when(session.createConnectorId(Matchers.any(ClientConnector.class))) .thenAnswer(new ConnectorIdAnswer()); when(session.getLocale()).thenReturn(Locale.FRANCE); when(session.hasLock()).thenReturn(true); ui.setSession(session); }
@Test public void changeView() { // given when(toView.getRootComponent()).thenReturn(viewContent); when(toView.getName()).thenReturn("toView"); // when ui.changeView(toView); // then verify(toView).getRootComponent(); verify(translator).translate(toView); verify(viewContent).setSizeFull(); assertThat(ui.getViewDisplayPanel().getContent()).isEqualTo(viewContent); }
@Test public void detachScopeNotNull() { // given prepAttach(); ui.attach(); ui.setScope(uiScope); ui.setInstanceKey(uiKey); // when ui.detach(); // then verify(uiScope).releaseScope(ui.getInstanceKey()); verify(broadcaster).unregister(Broadcaster.ALL_MESSAGES, ui); }
/** There is a much better functional test */ @Test public void receiveBroadcastMessage() throws Exception { // given prepAttach(); ui.attach(); ui.setScope(uiScope); ui.setInstanceKey(uiKey); // when ui.receiveBroadcast("group", "message", uiKey, 55); // then assertThat(logMonitor.debugLogs()) .contains("UI instance UIKey:33 receiving message id: 55 from: UIKey:33"); }
@Test public void pageTitle() throws Exception { // given when(applicationTitle.getTitleKey()).thenReturn(LabelKey.Yes); when(translate.from(LabelKey.Yes)).thenReturn("Title"); // when assertThat(ui.pageTitle()).isEqualTo("Title"); }
@Test(expected = MethodReconfigured.class) public void methodReconfigured() { // given // when ui.setNavigator(vaadinNavigator); // then }
@Test(expected = ConfigurationException.class) public void changeView_RootComponentNotSet() { // given when(toView.getRootComponent()).thenReturn(null); when(toView.getName()).thenReturn("toView"); // when ui.changeView(toView); // then }
@Test public void init() { // given prepAttach(); // when ui.init(request); // then verify(session).setConverterFactory(converterFactory); InOrder inOrder = inOrder(currentLocale, navigator, translator, navigator); // inOrder.verify(currentLocale) // .setLocale(Locale.FRANCE, false); inOrder.verify(navigator).init(); inOrder.verify(translator).translate(ui); inOrder.verify(navigator).navigateTo("home"); }
@Test(expected = ConfigurationException.class) public void init_with_viewDisplayPanel_parent_null() { // given ui = new DuffUI( navigator, errorHandler, converterFactory, broadcaster, pushMessageRouter, applicationTitle, translate, currentLocale, translator); prepAttach(); // when ui.init(request); // then }
@Before public void setup() { Locale.setDefault(Locale.UK); when(uiBusProvider.get()).thenReturn(eventBus); pushMessageRouter = new DefaultPushMessageRouter(uiBusProvider); logMonitor = new LogMonitor(); logMonitor.addClassFilter(ScopedUI.class); uiKey = new UIKey(33); ui = new BasicUI( navigator, errorHandler, converterFactory, broadcaster, pushMessageRouter, applicationTitle, translate, currentLocale, translator, option); ui.setInstanceKey(uiKey); }