### Question:
DefaultMacroManager implements MacroManager { @Override public Macro<?> getMacro(MacroId macroId) throws MacroLookupException { String macroHint = macroId.toString(); ComponentManager cm = this.componentManager.get(); try { if (cm.hasComponent(Macro.class, macroHint)) { return cm.getInstance(Macro.class, macroHint); } else { if (cm.hasComponent(Macro.class, macroId.getId())) { return cm.getInstance(Macro.class, macroId.getId()); } throw new MacroNotFoundException(String.format("No macro [%s] could be found.", macroId.toString())); } } catch (ComponentLookupException e) { throw new MacroLookupException(String.format("Macro [%s] failed to be instantiated.", macroId.toString()), e); } }  @Override Set<MacroId> getMacroIds(); @Override Set<MacroId> getMacroIds(Syntax syntax); @Override Macro<?> getMacro(MacroId macroId); @Override boolean exists(MacroId macroId);  }### Answer:
@Test public void testGetExistingMacro() throws Exception { Assert.assertNotNull(getMockedComponent().getMacro(new MacroId("testsimplemacro"))); }
@Test public void testGetNotExistingMacro() throws Exception { try { getMockedComponent().getMacro(new MacroId("notregisteredmacro")); Assert.fail("Expected a MacroNotFoundException when looking for not registered macro"); } catch (MacroNotFoundException expected) { Assert.assertEquals("No macro [notregisteredmacro] could be found.", expected.getMessage()); } }
@Test public void testGetInvalidMacro() throws Exception { DefaultComponentDescriptor<Macro> cd = new DefaultComponentDescriptor<Macro>(); cd.setRoleType(Macro.class); cd.setRoleHint("testinvalidmacro"); cd.setImplementation(TestInvalidMacro.class); getComponentManager().registerComponent(cd); try { getMockedComponent().getMacro(new MacroId("testinvalidmacro")); Assert.fail("Expected a MacroLookupException when looking for an invalid macro"); } catch (MacroLookupException expected) { Assert.assertEquals("Macro [testinvalidmacro] failed to be instantiated.", expected.getMessage()); } }
@Test public void testGetExistingMacroForASpecificSyntaxWhenMacroIsRegisteredForAllSyntaxes() throws Exception { Assert.assertNotNull(getMockedComponent().getMacro(new MacroId("testsimplemacro", new Syntax(SyntaxType.XWIKI, "2.0")))); }