TemplateEngineManagerImpl implements TemplateEngineManager { @Override public TemplateEngine getTemplateEngineForContentType(String contentType) { Provider<? extends TemplateEngine> provider = contentTypeToTemplateEngineMap .get(contentType); if (provider != null) { return provider.get(); } else { return null; } } @Inject  TemplateEngineManagerImpl(Injector injector); @Override Set<String> getContentTypes(); @Override TemplateEngine getTemplateEngineForContentType(String contentType);  }
@Test public void testGetJson() { assertThat(createTemplateEngineManager().getTemplateEngineForContentType( ContentTypes.APPLICATION_JSON), instanceOf(TemplateEngineJson.class)); }
@Test public void testGetJsonP() { assertThat(createTemplateEngineManager().getTemplateEngineForContentType( ContentTypes.APPLICATION_JSONP), instanceOf(TemplateEngineJsonP.class)); }
@Test public void testGetFreemarker() { assertThat(createTemplateEngineManager().getTemplateEngineForContentType( ContentTypes.TEXT_HTML), instanceOf(TemplateEngineFreemarker.class)); }
@Test public void testGetCustom() { assertThat(createTemplateEngineManager(CustomTemplateEngine.class).getTemplateEngineForContentType( "custom"), instanceOf(CustomTemplateEngine.class)); }
@Test public void testOverrideJson() { assertThat(createTemplateEngineManager(OverrideJsonTemplateEngine.class).getTemplateEngineForContentType( ContentTypes.APPLICATION_JSON), instanceOf(OverrideJsonTemplateEngine.class)); }
@Test public void testOverrideHtml() { assertThat(createTemplateEngineManager(OverrideHtmlTemplateEngine.class).getTemplateEngineForContentType( ContentTypes.TEXT_HTML), instanceOf(OverrideHtmlTemplateEngine.class)); }
@Test public void testOverrideHtmlOrderMatters() { TemplateEngineManager templateEngineManager = createTemplateEngineManager( OverrideHtmlTemplateEngine.class, OverrideHtmlTemplateEngine3.class, OverrideHtmlTemplateEngine2.class); assertThat(templateEngineManager.getTemplateEngineForContentType( ContentTypes.TEXT_HTML), instanceOf(OverrideHtmlTemplateEngine2.class)); }
@Test public void testGetNonExistingProducesNoNPE() { TemplateEngineManager manager = createTemplateEngineManager(OverrideJsonTemplateEngine.class); assertNull(manager.getTemplateEngineForContentType("non/existing")); }