### Question:
DefaultWikiMacroFactory implements WikiMacroFactory, WikiMacroConstants { @Override public WikiMacro createWikiMacro(DocumentReference documentReference) throws WikiMacroException { XWikiDocument doc; try { doc = getContext().getWiki().getDocument(documentReference, getContext()); } catch (XWikiException ex) { throw new WikiMacroException( String.format("Could not build macro from : [%s], unable to load document", documentReference), ex); } return buildMacro(doc); }  @Override WikiMacro createWikiMacro(DocumentReference documentReference); @Override boolean containsWikiMacro(DocumentReference documentReference); @Override boolean isAllowed(DocumentReference documentReference, WikiMacroVisibility visibility);  }### Answer:
@Test public void createWikiMacro() throws Exception { WikiMacro macro = this.wikiMacroFactory.createWikiMacro(DOCUMENT_REFERENCE); assertNotNull(macro); assertEquals("testmacro", macro.getId()); assertEquals("testmacro", macro.getDescriptor().getId().getId()); assertEquals("Test Macro", macro.getDescriptor().getName()); assertEquals("This is a macro used for testing purposes.", macro.getDescriptor().getDescription()); assertEquals("Test", macro.getDescriptor().getDefaultCategory()); assertEquals(WikiMacroVisibility.USER, ((WikiMacroDescriptor) macro.getDescriptor()).getVisibility()); assertTrue(macro.supportsInlineMode()); assertNull(macro.getDescriptor().getContentDescriptor()); assertTrue(macro.getDescriptor().getParameterDescriptorMap().isEmpty()); assertNull(macro.getDescriptor().getId().getSyntax()); }
@Test public void createWikiMacroWithoutName() throws Exception { this.macroObject.setStringValue(WikiMacroConstants.MACRO_NAME_PROPERTY, ""); saveDocument(); WikiMacro macro = this.wikiMacroFactory.createWikiMacro(DOCUMENT_REFERENCE); assertNotNull(macro); assertEquals("testmacro", macro.getDescriptor().getName()); }
@Test public void createWikiMacroWithEmptyCode() throws Exception { this.macroObject.setStringValue(WikiMacroConstants.MACRO_CODE_PROPERTY, ""); saveDocument(); assertThrows(WikiMacroException.class, () -> this.wikiMacroFactory.createWikiMacro(DOCUMENT_REFERENCE)); }