CategoryResponse { public Category map() { Category category; if (isWikiDataIdPresent) { category = new Category(code, new ArrayList<>(), wikiDataCode); for (Map.Entry<String, String> name : names.entrySet()) { category.getNames().add(new CategoryName(category.getTag(), name.getKey(), name.getValue(), wikiDataCode)); } } else { category = new Category(code, new ArrayList<>()); for (Map.Entry<String, String> name : names.entrySet()) { category.getNames().add(new CategoryName(category.getTag(), name.getKey(), name.getValue())); } } return category; } CategoryResponse(String code, Map<String, String> names, String wikiDataCode);  CategoryResponse(String code, Map<String, String> names); Category map();  }
@Test public void mapWithoutWikiDataId_returnsCategoryWithNamesWithoutWikiDataId() { mCategoryResponse = new CategoryResponse(CATEGORY_TAG, mNamesMap); Category category = mCategoryResponse.map(); assertThat(category.getTag()).isEqualTo(CATEGORY_TAG); assertThat(category.getNames()).hasSize(2); CategoryName categoryName1 = category.getNames().get(0); assertThat(categoryName1.getLanguageCode()).isEqualTo(LANGUAGE_CODE_ENGLISH); assertThat(categoryName1.getName()).isEqualTo(GUMMY_BEARS_EN); assertThat(categoryName1.getCategoryTag()).isEqualTo(CATEGORY_TAG); assertThat(categoryName1.getIsWikiDataIdPresent()).isFalse(); assertThat(categoryName1.getWikiDataId()).isEqualTo("null"); CategoryName categoryName2 = category.getNames().get(1); assertThat(categoryName2.getLanguageCode()).isEqualTo(LANGUAGE_CODE_FRENCH); assertThat(categoryName2.getName()).isEqualTo(GUMMY_BEARS_FR); assertThat(categoryName2.getCategoryTag()).isEqualTo(CATEGORY_TAG); assertThat(categoryName2.getIsWikiDataIdPresent()).isFalse(); assertThat(categoryName2.getWikiDataId()).isEqualTo("null"); }
@Test public void mapWithWikiDataId_returnsCategoryWithNamesWithWikiDataId() { mCategoryResponse = new CategoryResponse(CATEGORY_TAG, mNamesMap, WIKI_DATA_ID); Category category = mCategoryResponse.map(); assertThat(category.getTag()).isEqualTo(CATEGORY_TAG); assertThat(category.getNames()).hasSize(2); CategoryName categoryName1 = category.getNames().get(0); assertThat(categoryName1.getLanguageCode()).isEqualTo(LANGUAGE_CODE_ENGLISH); assertThat(categoryName1.getName()).isEqualTo(GUMMY_BEARS_EN); assertThat(categoryName1.getCategoryTag()).isEqualTo(CATEGORY_TAG); assertThat(categoryName1.getIsWikiDataIdPresent()).isTrue(); assertThat(categoryName1.getWikiDataId()).isEqualTo(WIKI_DATA_ID); CategoryName categoryName2 = category.getNames().get(1); assertThat(categoryName2.getLanguageCode()).isEqualTo(LANGUAGE_CODE_FRENCH); assertThat(categoryName2.getName()).isEqualTo(GUMMY_BEARS_FR); assertThat(categoryName2.getCategoryTag()).isEqualTo(CATEGORY_TAG); assertThat(categoryName2.getIsWikiDataIdPresent()).isTrue(); assertThat(categoryName2.getWikiDataId()).isEqualTo(WIKI_DATA_ID); }