@Test public void testGetHtmlSurvivesPluginThrowingExceptionFromGetFinalHtml() throws Exception { Mockito.when(goodDescriptorRenderer.getFinalHtml(link)).thenReturn("final html"); Assert.assertEquals("final html", RemoteIssueLinkUtils.getFinalHtml(link, pluginAccessor)); Mockito.when(goodDescriptorRenderer.getFinalHtml(Mockito.<RemoteIssueLink>any())) .thenThrow(new LinkageError("Misbehaving plugin exception - non-fatal error")); expectedException.expect(Exception.class); RemoteIssueLinkUtils.getFinalHtml(link, pluginAccessor); }
@Before public void setUp() throws Exception { Mockito.when(defaultRenderer.isDefaultHandler()).thenReturn(true); Mockito.when(badDescriptorRenderer.isDefaultHandler()) .thenThrow(new RuntimeException("Misbehaving plugin exception")); Mockito.when(goodDescriptorRenderer.handlesApplicationType("application")).thenReturn(true); Mockito.when(badDescriptorRenderer.handlesApplicationType(Mockito.anyString())) .thenThrow(new RuntimeException("Misbehaving plugin exception")); Mockito.when( pluginAccessor.getEnabledModuleDescriptorsByClass( IssueLinkRendererModuleDescriptor.class)) .thenReturn( ImmutableList.of(badDescriptorRenderer, goodDescriptorRenderer, defaultRenderer)); Mockito.when(goodDescriptorRenderer.getModule()).thenReturn(renderer); }
@Test public void testConvertToIssueLinkContextsSurvivesPluginThrowingExceptionFromGetModule() throws Exception { Mockito.when(goodDescriptorRenderer.getModule()) .thenThrow(new RuntimeException("Misbehaving plugin exception")); final Map<String, List<IssueLinkContext>> contexts = RemoteIssueLinkUtils.convertToIssueLinkContexts( ImmutableList.of(link), 1L, "", new MockI18nHelper(), pluginAccessor); Assert.assertEquals(Collections.<String, List<IssueLinkContext>>emptyMap(), contexts); }
@Test public void testConvertToIssueLinkContexts() throws Exception { Mockito.when(renderer.shouldDisplay(Mockito.<RemoteIssueLink>any())).thenReturn(true); Mockito.when(renderer.requiresAsyncLoading(link)).thenReturn(true); Mockito.when(goodDescriptorRenderer.getInitialHtml(link)).thenReturn("valid html"); final Map<String, List<IssueLinkContext>> contextMap = RemoteIssueLinkUtils.convertToIssueLinkContexts( ImmutableList.of(link), 1L, "", new MockI18nHelper(), pluginAccessor); Assert.assertEquals(1, contextMap.size()); final List<IssueLinkContext> contexts = contextMap.values().iterator().next(); final IssueLinkContext context = Iterables.getOnlyElement(contexts); Assert.assertTrue(context.isRequiresAsyncLoading()); Assert.assertEquals("valid html", context.getHtml()); }