### Question:
DefaultIconSetLoader implements IconSetLoader { @Override public IconSet loadIconSet(DocumentReference iconSetReference) throws IconException { try { DocumentModelBridge doc = documentAccessBridge.getDocumentInstance(iconSetReference); String content = doc.getContent(); DocumentReference iconClassRef = new DocumentReference(wikiDescriptorManager.getCurrentWikiId(), "IconThemesCode", "IconThemeClass"); String name = (String) documentAccessBridge.getProperty(iconSetReference, iconClassRef, "name"); return loadIconSet(new StringReader(content), name); } catch (Exception e) { throw new IconException(String.format(ERROR_MSG, iconSetReference), e); } }  @Override IconSet loadIconSet(DocumentReference iconSetReference); @Override IconSet loadIconSet(Reader input, String name);  }### Answer:
@Test public void loadIconSet() throws Exception { Reader content = new InputStreamReader(getClass().getResourceAsStream("/test.iconset")); IconSet result = iconSetLoader.loadIconSet(content, "FontAwesome"); verifies(result); assertEquals("FontAwesome", result.getName()); }
@Test public void loadIconSetFromWikiDocument() throws Exception { DocumentReference iconSetRef = new DocumentReference("xwiki", "IconThemes", "Default"); DocumentReference iconClassRef = new DocumentReference("wikiId", "IconThemesCode", "IconThemeClass"); when(documentAccessBridge.getProperty(eq(iconSetRef), eq(iconClassRef), eq("name"))).thenReturn("MyIconTheme"); DocumentModelBridge doc = mock(DocumentModelBridge.class); when(documentAccessBridge.getDocumentInstance(iconSetRef)).thenReturn(doc); StringWriter content = new StringWriter(); IOUtils.copyLarge(new InputStreamReader(getClass().getResourceAsStream("/test.iconset")), content); when(doc.getContent()).thenReturn(content.toString()); IconSet result = iconSetLoader.loadIconSet(iconSetRef); verifies(result); assertEquals("MyIconTheme", result.getName()); }
@Test public void loadIconSetWithException() throws Exception { Reader content = mock(Reader.class); IOException exception = new IOException("test"); when(content.read(any(char[].class))).thenThrow(exception); Exception caughException = null; try { iconSetLoader.loadIconSet(content, "FontAwesome"); } catch (IconException e) { caughException = e; } assertNotNull(caughException); assert (caughException instanceof IconException); assertEquals(exception, caughException.getCause()); assertEquals("Failed to load the IconSet [FontAwesome].", caughException.getMessage()); }
@Test public void loadIconSetFromWikiDocumentWithException() throws Exception { Exception exception = new Exception("test"); when(documentAccessBridge.getDocumentInstance(any(DocumentReference.class))).thenThrow(exception); Exception caughException = null; try { iconSetLoader.loadIconSet(new DocumentReference("a", "b", "c")); } catch (IconException e) { caughException = e; } assertNotNull(caughException); assert (caughException instanceof IconException); assertEquals(exception, caughException.getCause()); assertEquals("Failed to load the IconSet [a:b.c].", caughException.getMessage()); }