### Question:
DefaultIconSetManager implements IconSetManager { @Override public IconSet getIconSet(String name) throws IconException { if (DEFAULT_ICONSET_NAME.equals(name)) { return getDefaultIconSet(); } IconSet iconSet = iconSetCache.get(name, wikiDescriptorManager.getCurrentWikiId()); if (iconSet == null) { try { String xwql = "FROM doc.object(IconThemesCode.IconThemeClass) obj WHERE obj.name = :name"; Query query = queryManager.createQuery(xwql, Query.XWQL); query.bindValue("name", name); List<String> results = query.execute(); if (results.isEmpty()) { return null; } String docName = results.get(0); DocumentReference docRef = documentReferenceResolver.resolve(docName); iconSet = iconSetLoader.loadIconSet(docRef); iconSetCache.put(docRef, iconSet); iconSetCache.put(name, wikiDescriptorManager.getCurrentWikiId(), iconSet); } catch (QueryException e) { throw new IconException(String.format("Failed to load the icon set [%s].", name), e); } } return iconSet; }  @Override IconSet getCurrentIconSet(); @Override IconSet getDefaultIconSet(); @Override IconSet getIconSet(String name); @Override List<String> getIconSetNames();  }### Answer:
@Test public void getIconSetWhenInCache() throws Exception { IconSet iconSet = new IconSet("silk"); when(iconSetCache.get("silk", "currentWikiId")).thenReturn(iconSet); assertEquals(iconSet, mocker.getComponentUnderTest().getIconSet("silk")); verify(iconSetCache, never()).put(anyString(), any(IconSet.class)); }
@Test public void getIconSetWhenNotInCache() throws Exception { IconSet iconSet = new IconSet("silk"); Query query = mock(Query.class); when(queryManager.createQuery("FROM doc.object(IconThemesCode.IconThemeClass) obj WHERE obj.name = :name", Query.XWQL)).thenReturn(query); List<String> results = new ArrayList<>(); results.add("IconThemes.Silk"); when(query.<String>execute()).thenReturn(results); DocumentReference documentReference = new DocumentReference("wiki", "IconThemes", "Silk"); when(documentReferenceResolver.resolve("IconThemes.Silk")).thenReturn(documentReference); when(iconSetLoader.loadIconSet(documentReference)).thenReturn(iconSet); assertEquals(iconSet, mocker.getComponentUnderTest().getIconSet("silk")); verify(query).bindValue("name", "silk"); verify(iconSetCache).put(documentReference, iconSet); verify(iconSetCache).put("silk", "currentWikiId", iconSet); }
@Test public void getIconSetWhenDoesNotExists() throws Exception { Query query = mock(Query.class); when(queryManager.createQuery("FROM doc.object(IconThemesCode.IconThemeClass) obj WHERE obj.name = :name", Query.XWQL)).thenReturn(query); List<String> results = new ArrayList<>(); when(query.<String>execute()).thenReturn(results); assertNull(mocker.getComponentUnderTest().getIconSet("silk")); verify(query).bindValue("name", "silk"); }
@Test public void getIconSetWhenException() throws Exception { Exception exception = new QueryException("exception in the query", null, null); when(queryManager.createQuery(any(), any())).thenThrow(exception); Exception caughtException = null; try { mocker.getComponentUnderTest().getIconSet("silk"); } catch (IconException e) { caughtException = e; } assertNotNull(caughtException); assertEquals(exception, caughtException.getCause()); assertEquals("Failed to load the icon set [silk].", caughtException.getMessage()); }