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