### Question:
StunnerFormsHandler { public void refreshCurrentSessionForms() { refreshCurrentSessionForms(null); } StunnerFormsHandler(); @Inject  StunnerFormsHandler(final SessionManager sessionManager,
                               final Event<RefreshFormPropertiesEvent> refreshFormsEvent); void refreshCurrentSessionForms(); void refreshCurrentSessionForms(final Class<?> defSetType);  }### Answer:
@Test @SuppressWarnings("unchecked") public void testRefreshCurrentSessionForms() { ClientSession session = mock(ClientSession.class); when(sessionManager.getCurrentSession()).thenReturn(session); tested.refreshCurrentSessionForms(); ArgumentCaptor<RefreshFormPropertiesEvent> eventCaptor = ArgumentCaptor.forClass(RefreshFormPropertiesEvent.class); verify(refreshFormsEvent, times(1)).fire(eventCaptor.capture()); RefreshFormPropertiesEvent event = eventCaptor.getValue(); assertEquals(session, event.getSession()); assertNull(event.getUuid()); }
@Test @SuppressWarnings("unchecked") public void testRefreshCurrentSessionFormsByDomain() { ClientSession session = mock(ClientSession.class); CanvasHandler handler = mock(CanvasHandler.class); Diagram diagram = mock(Diagram.class); Metadata metadata = mock(Metadata.class); when(sessionManager.getCurrentSession()).thenReturn(session); when(session.getCanvasHandler()).thenReturn(handler); when(handler.getDiagram()).thenReturn(diagram); when(diagram.getMetadata()).thenReturn(metadata); when(metadata.getDefinitionSetId()).thenReturn(BindableAdapterUtils.getDefinitionSetId(SomeDomain.class)); tested.refreshCurrentSessionForms(SomeDomain.class); ArgumentCaptor<RefreshFormPropertiesEvent> eventCaptor = ArgumentCaptor.forClass(RefreshFormPropertiesEvent.class); verify(refreshFormsEvent, times(1)).fire(eventCaptor.capture()); RefreshFormPropertiesEvent event = eventCaptor.getValue(); assertEquals(session, event.getSession()); assertNull(event.getUuid()); }
@Test @SuppressWarnings("unchecked") public void testRefreshCurrentSessionFormsByNotMatchingDomain() { ClientSession session = mock(ClientSession.class); CanvasHandler handler = mock(CanvasHandler.class); Diagram diagram = mock(Diagram.class); Metadata metadata = mock(Metadata.class); when(sessionManager.getCurrentSession()).thenReturn(session); when(session.getCanvasHandler()).thenReturn(handler); when(handler.getDiagram()).thenReturn(diagram); when(diagram.getMetadata()).thenReturn(metadata); when(metadata.getDefinitionSetId()).thenReturn("ds1"); tested.refreshCurrentSessionForms(SomeDomain.class); verify(refreshFormsEvent, never()).fire(any(RefreshFormPropertiesEvent.class)); }