### Question:
Mapper { public Result map(String mediaType, String sourceName, SearchResultInfo resultInfo) throws Exception { Target target = Target.valueOf(sourceName.toUpperCase()); Result result = new Result(resultInfo); MARCMapper marcMapper; switch (target) { case DFB: marcMapper = new DFBMarcMapper(mediaType, target.getCataloguingSourceUri(), true); break; case BIBBI: default: marcMapper = new BSMarcMapper(mediaType, target.getCataloguingSourceUri(), true); break; } result.setSource(target.getDatabaseName()); if (target.getDataFormat().contains("marc")) { result.setHits(marcMapper.getMapping(resultInfo.getMarcXmlContent())); } else { throw new Exception("No mapper identified for this resource"); } return result; }  Result map(String mediaType, String sourceName, SearchResultInfo resultInfo);  }### Answer:
@Test public void test_mapping() throws Exception { ResourceReader resourceReader = new ResourceReader(); String sourceName = "bibbi"; String record = resourceReader.readFile("BS_external_data.xml"); String json = resourceReader.readFile("BS_external_data_processed.json"); Gson gson = new GsonBuilder().setPrettyPrinting().create(); Mapper mapper = new Mapper(); assertEquals(simplifyBNodes(json), simplifyBNodes(gson.toJson(mapper.map("Book", sourceName, new SearchResultInfo(record))))); assertThat(simplifyBNodes(json), SameJSONAs.sameJSONAs(simplifyBNodes(gson.toJson(mapper.map("Book", sourceName, new SearchResultInfo(record))))) .allowingAnyArrayOrdering() .allowingExtraUnexpectedFields()); assertEquals(sourceName, mapper.map("Book", sourceName, new SearchResultInfo(record)).getSource()); }
@Test(expected = Exception.class) public void mapper_throws_exception_on_unknown_format() throws Exception { Mapper mapper = new Mapper(); mapper.map("Book","google", null); }