### Question:
XmlTemplateLibrary implements TemplateLibrary { public TagRegistry getTagRegistry() { return registry; } XmlTemplateLibrary(Uri uri, Element root, String source);  XmlTemplateLibrary(Uri uri, Element root, String source, boolean safe); TagRegistry getTagRegistry(); Uri getLibraryUri(); boolean isSafe(); String serialize(); static final String TAG_ATTRIBUTE; static final String NAMESPACE_TAG; static final String TEMPLATE_TAG; static final String STYLE_TAG; static final String JAVASCRIPT_TAG; static final String TEMPLATEDEF_TAG; }### Answer:
@Test public void testTemplateElement() throws Exception { TagRegistry registry = lib.getTagRegistry(); assertNotNull(registry.getHandlerFor(new TagRegistry.NSName("#my", "Flat"))); }
@Test public void testTemplateDefElement() throws Exception { TagRegistry registry = lib.getTagRegistry(); assertNotNull(registry.getHandlerFor(new TagRegistry.NSName("#my", "Def"))); }
@Test public void testMissingElements() { TagRegistry registry = lib.getTagRegistry(); assertNull(registry.getHandlerFor(new TagRegistry.NSName("#my", "Foo"))); assertNull(registry.getHandlerFor(new TagRegistry.NSName("my", "Flat"))); }
@Test public void testAddedResources() { final TemplateContext context = new TemplateContext(null, ImmutableMap.<String, Object>of()); TemplateProcessor processor = new DefaultTemplateProcessor(Expressions.forTesting()) { @Override public TemplateContext getTemplateContext() { return context; } }; TagHandler handlerWithResources = lib.getTagRegistry() .getHandlerFor(new TagRegistry.NSName("#my", "Def")); TagHandler handlerWithNoResources = lib.getTagRegistry() .getHandlerFor(new TagRegistry.NSName("#my", "Flat")); Node result = doc.getOwnerDocument().createDocumentFragment(); Element tag = doc.getOwnerDocument().createElement("test"); handlerWithNoResources.process(result, tag, processor); assertEquals("<STYLE>libstyle\nlibstyle2</STYLE>" + "<JAVASCRIPT>libscript\nlibscript2</JAVASCRIPT>", serializeResources(context)); handlerWithResources.process(result, tag, processor); assertEquals("<STYLE>libstyle\nlibstyle2</STYLE>" + "<JAVASCRIPT>libscript\nlibscript2</JAVASCRIPT>" + "<JAVASCRIPT>tagscript</JAVASCRIPT>" + "<STYLE>tagstyle</STYLE>", serializeResources(context)); handlerWithResources.process(result, tag, processor); assertEquals("<STYLE>libstyle\nlibstyle2</STYLE>" + "<JAVASCRIPT>libscript\nlibscript2</JAVASCRIPT>" + "<JAVASCRIPT>tagscript</JAVASCRIPT>" + "<STYLE>tagstyle</STYLE>", serializeResources(context)); }