LocalizationFactory implements PageFactory { @Override public <P extends Previewable & Identifiable> String generate(P previewable) { if (previewable instanceof Assetable) { return new TemplateEngine("localizationFactory.hbs.js") .with("localization", getLocalization(previewable)) .build(new Object()); } return ""; } @Inject  LocalizationFactory(PageRepository pageRepository); @Override String generate(P previewable);  }
@Test public void should_create_a_factory_which_contains_localizations() throws Exception { writeByteArrayToFile(localizationFile, localizationFileContent.getBytes()); assertThat(localizationFactory.generate(page)) .isEqualTo(createFactory(localizationFileContent)); }
@Test public void should_create_an_empty_factory_whenever_localization_file_is_not_valid_json() throws Exception { writeByteArrayToFile(localizationFile, "invalid json".getBytes()); assertThat(localizationFactory.generate(page)) .isEqualTo(createFactory("{}")); }
@Test public void should_create_an_empty_factory_whenever_localization_file_does_not_exist() throws Exception { deleteQuietly(localizationFile); assertThat(localizationFactory.generate(page)) .isEqualTo(createFactory("{}")); }