### Question:
WikiTemplatePropertyGroupProvider implements WikiPropertyGroupProvider { @Override public WikiPropertyGroup get(String wikiId) throws WikiPropertyGroupException { WikiTemplatePropertyGroup group = new WikiTemplatePropertyGroup(GROUP_NAME); try { XWikiDocument descriptorDocument = wikiDescriptorDocumentHelper.getDocumentFromWikiId(wikiId); BaseObject object = descriptorDocument.getXObject(WikiTemplateClassDocumentInitializer.SERVER_CLASS); if (object != null) { group.setTemplate( object.getIntValue(WikiTemplateClassDocumentInitializer.FIELD_ISWIKITEMPLATE, 0) != 0); } } catch (WikiManagerException e) { throw new WikiPropertyGroupException(String.format(ERROR_MESSAGE_NO_DESCRIPTOR_DOCUMENT, wikiId), e); } return group; }  @Override WikiPropertyGroup get(String wikiId); @Override void save(WikiPropertyGroup group, String wikiId); static final String GROUP_NAME; }### Answer:
@Test public void get() throws Exception { XWikiDocument descriptorDocument = mock(XWikiDocument.class); when(wikiDescriptorDocumentHelper.getDocumentFromWikiId("wikiId")).thenReturn(descriptorDocument); BaseObject object = mock(BaseObject.class); when(descriptorDocument.getXObject(eq(WikiTemplateClassDocumentInitializer.SERVER_CLASS))).thenReturn(object); when(object.getIntValue("iswikitemplate", 0)).thenReturn(1); WikiPropertyGroup result = mocker.getComponentUnderTest().get("wikiId"); assertEquals(true, result.get("isTemplate")); assertTrue(result instanceof WikiTemplatePropertyGroup); assertTrue(((WikiTemplatePropertyGroup)result).isTemplate()); XWikiDocument descriptorDocument2 = mock(XWikiDocument.class); when(wikiDescriptorDocumentHelper.getDocumentFromWikiId("wikiId2")).thenReturn(descriptorDocument2); BaseObject object2 = mock(BaseObject.class); when(descriptorDocument2.getXObject(eq(WikiTemplateClassDocumentInitializer.SERVER_CLASS))).thenReturn(object2); when(object2.getIntValue("iswikitemplate", 0)).thenReturn(0); WikiPropertyGroup result2 = mocker.getComponentUnderTest().get("wikiId2"); assertEquals(false, result2.get("isTemplate")); assertTrue(result2 instanceof WikiTemplatePropertyGroup); assertFalse(((WikiTemplatePropertyGroup) result2).isTemplate()); }
@Test public void getWhenNoObject() throws Exception { XWikiDocument descriptorDocument = mock(XWikiDocument.class); when(wikiDescriptorDocumentHelper.getDocumentFromWikiId("wikiId")).thenReturn(descriptorDocument); WikiPropertyGroup result = mocker.getComponentUnderTest().get("wikiId"); assertEquals(false, result.get("isTemplate")); }
@Test public void getWhenException() throws Exception { WikiManagerException exception = new WikiManagerException("error in WikiManager"); when(wikiDescriptorDocumentHelper.getDocumentFromWikiId("wikiId")).thenThrow(exception); boolean exceptionCaught = false; try { mocker.getComponentUnderTest().get("wikiId"); } catch(WikiPropertyGroupException e) { exceptionCaught = true; assertEquals("Unable to load descriptor document for wiki [wikiId].", e.getMessage()); assertEquals(exception, e.getCause()); } assertTrue(exceptionCaught); }