AdditiveResponse { public Additive map() { Additive additive; if (isWikiDataIdPresent) { additive = new Additive(tag, new ArrayList<>(), overexposureRisk, wikiDataCode); for (Map.Entry<String, String> name : names.entrySet()) { AdditiveName additiveName = new AdditiveName(additive.getTag(), name.getKey(), name.getValue(), overexposureRisk, wikiDataCode); additiveName.setExposureEvalMap( exposure95ThGreaterThanAdi, exposure95ThGreaterThanNoael, exposureMeanGreaterThanAdi, exposureMeanGreaterThanNoael ); additive.getNames().add(additiveName); } } else { additive = new Additive(tag, new ArrayList<>(), overexposureRisk ); for (Map.Entry<String, String> name : names.entrySet()) { AdditiveName additiveName = new AdditiveName( additive.getTag(), name.getKey(), name.getValue(), overexposureRisk ); additiveName.setExposureEvalMap( exposure95ThGreaterThanAdi, exposure95ThGreaterThanNoael, exposureMeanGreaterThanAdi, exposureMeanGreaterThanNoael ); additive.getNames().add( additiveName ); } } additive.setExposureEvalMap( exposure95ThGreaterThanAdi, exposure95ThGreaterThanNoael, exposureMeanGreaterThanAdi, exposureMeanGreaterThanNoael ); return additive; } AdditiveResponse( String tag, Map<String, String> names, String overexposureRisk, String wikiDataCode );  AdditiveResponse( String tag, Map<String, String> names, String overexposureRisk ); void setExposureEvalMap( String exposure95ThGreaterThanAdi, String exposure95ThGreaterThanNoael, String exposureMeanGreaterThanAdi, String exposureMeanGreaterThanNoael ); Additive map();  }
@Test public void mapWithoutWikiDataId_returnsAdditiveWithNamesWithoutWikiDataId() { mAdditiveResponse = new AdditiveResponse(ADDITIVE_TAG, mStringMap, null); Additive additive = mAdditiveResponse.map(); assertThat(additive.getTag()).isEqualTo(ADDITIVE_TAG); assertThat(additive.getNames()).hasSize(2); assertThat(additive.getNames().get(0).getLanguageCode()).isEqualTo(LANGUAGE_CODE_ENGLISH); assertThat(additive.getNames().get(0).getName()).isEqualTo(VINEGAR_EN); assertThat(additive.getNames().get(0).getAdditiveTag()).isEqualTo(ADDITIVE_TAG); assertThat(additive.getNames().get(0).getWikiDataId()).isEqualTo("null"); assertThat(additive.getNames().get(0).getIsWikiDataIdPresent()).isFalse(); assertThat(additive.getNames().get(1).getLanguageCode()).isEqualTo(LANGUAGE_CODE_FRENCH); assertThat(additive.getNames().get(1).getName()).isEqualTo(VINEGAR_FR); assertThat(additive.getNames().get(1).getAdditiveTag()).isEqualTo(ADDITIVE_TAG); assertThat(additive.getNames().get(1).getWikiDataId()).isEqualTo("null"); assertThat(additive.getNames().get(1).getIsWikiDataIdPresent()).isFalse(); }
@Test public void mapWithWikiDataId_returnsAdditiveWithNamesWithWikiDataId() { mAdditiveResponse = new AdditiveResponse(ADDITIVE_TAG, mStringMap, null, WIKI_DATA_ID); Additive additive = mAdditiveResponse.map(); assertThat(additive.getTag()).isEqualTo(ADDITIVE_TAG); assertThat(additive.getNames()).hasSize(2); assertThat(additive.getNames().get(0).getLanguageCode()).isEqualTo(LANGUAGE_CODE_ENGLISH); assertThat(additive.getNames().get(0).getName()).isEqualTo(VINEGAR_EN); assertThat(additive.getNames().get(0).getAdditiveTag()).isEqualTo(ADDITIVE_TAG); assertThat(additive.getNames().get(0).getWikiDataId()).isEqualTo(WIKI_DATA_ID); assertThat(additive.getNames().get(0).getIsWikiDataIdPresent()).isTrue(); assertThat(additive.getNames().get(1).getLanguageCode()).isEqualTo(LANGUAGE_CODE_FRENCH); assertThat(additive.getNames().get(1).getName()).isEqualTo(VINEGAR_FR); assertThat(additive.getNames().get(1).getAdditiveTag()).isEqualTo(ADDITIVE_TAG); assertThat(additive.getNames().get(1).getWikiDataId()).isEqualTo(WIKI_DATA_ID); assertThat(additive.getNames().get(1).getIsWikiDataIdPresent()).isTrue(); }