@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()); }
@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; }
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; } }
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; }  }
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(); }
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();  }