SmartlingPluralFix { public static List<TextUnitDTO> fixTextUnits(List<TextUnitDTO> textUnits) { Stream<TextUnitDTO> added = textUnits.stream() .filter(Objects::nonNull) .filter(textUnit -> OTHER.toString().equalsIgnoreCase(textUnit.getPluralForm())) .map(textUnit -> { TextUnitDTO tu = new TextUnitDTO(); tu.setName(textUnit.getName().replace("_other", "_many")); tu.setPluralForm("many"); tu.setPluralFormOther(textUnit.getPluralFormOther()); tu.setTarget(textUnit.getTarget()); tu.setRepositoryName(textUnit.getRepositoryName()); tu.setAssetPath(textUnit.getAssetPath()); tu.setTargetLocale(textUnit.getTargetLocale()); return tu; }); return Stream.concat(added, textUnits.stream()).collect(Collectors.toList()); } private  SmartlingPluralFix(); static List<TextUnitDTO> fixTextUnits(List<TextUnitDTO> textUnits);  }
@Test public void testFixTextUnits() { List<TextUnitDTO> input = ImmutableList.of(); assertThat(fixTextUnits(input)).isEmpty(); String textContent = testIdWatcher.getEntityName("textContent"); input = ImmutableList.of( textUnit("singular1", textContent, null, null), textUnit("singular2", textContent, null, null)); assertThat(fixTextUnits(input)).containsExactlyElementsOf(input); textContent = testIdWatcher.getEntityName("textContent2"); input = ImmutableList.of( textUnit("singular1", textContent, null, null), textUnit("singular2", textContent, null, null), textUnit("plural1_zero", textContent, "zero", "plural1_other"), textUnit("plural1_other", textContent, "other", "plural1_other")); assertThat(fixTextUnits(input)).extracting("name", "target", "pluralForm", "pluralFormOther") .containsExactlyInAnyOrder( tuple("singular1", textContent, null, null), tuple("singular2", textContent, null, null), tuple("plural1_zero", textContent, "zero", "plural1_other"), tuple("plural1_many", textContent, "many", "plural1_other"), tuple("plural1_other", textContent, "other", "plural1_other")); textContent = testIdWatcher.getEntityName("textContent3"); input = ImmutableList.of( textUnit("plural1_zero", textContent, "zero", "plural1_other"), textUnit("plural1_other", textContent, "other", "plural1_other"), textUnit("plural2_zero", textContent, "zero", null), textUnit("plural2_one", textContent, "one", null)); assertThat(fixTextUnits(input)).extracting("name", "target", "pluralForm", "pluralFormOther") .containsExactlyInAnyOrder( tuple("plural1_zero", textContent, "zero", "plural1_other"), tuple("plural1_many", textContent, "many", "plural1_other"), tuple("plural1_other", textContent, "other", "plural1_other"), tuple("plural2_zero", textContent, "zero", null), tuple("plural2_one", textContent, "one", null)); String repository = testIdWatcher.getEntityName("repository"); String assetPath = testIdWatcher.getEntityName("asset"); String targetLocale = "cz-CZ"; textContent = testIdWatcher.getEntityName("textContent4"); input = ImmutableList.of( textUnit("plural1_zero", textContent, "zero", "plural1_other", repository, assetPath, targetLocale), textUnit("plural1_other", textContent, "other", "plural1_other", repository, assetPath, targetLocale), textUnit("plural2_zero", textContent, "zero", "plural2_other", repository, assetPath, targetLocale), textUnit("plural2_one", textContent, "one", "plural2_other", repository, assetPath, targetLocale), textUnit("plural2_other", textContent, "other", "plural2_other", repository, assetPath, targetLocale)); assertThat(fixTextUnits(input)).extracting("name", "target", "pluralForm", "pluralFormOther", "repositoryName", "assetPath", "targetLocale") .containsExactlyInAnyOrder( tuple("plural1_zero", textContent, "zero", "plural1_other", repository, assetPath, targetLocale), tuple("plural1_other", textContent, "other", "plural1_other", repository, assetPath, targetLocale), tuple("plural1_many", textContent, "many", "plural1_other", repository, assetPath, targetLocale), tuple("plural2_zero", textContent, "zero", "plural2_other", repository, assetPath, targetLocale), tuple("plural2_one", textContent, "one", "plural2_other", repository, assetPath, targetLocale), tuple("plural2_many", textContent, "many", "plural2_other", repository, assetPath, targetLocale), tuple("plural2_other", textContent, "other", "plural2_other", repository, assetPath, targetLocale)); }