ProjectDetailConverter { public Project convert(ProjectDetail source) throws IOException { Project.Builder builder = Project.newBuilder(); builder.setId(normalizeId(source.getProjectId())); if (ProjectConverter.isAcronymValid(source.getAcronym())) { builder.setProjectAcronym(source.getAcronym()); } if (StringUtils.isNotBlank(source.getCode())) { builder.setProjectGrantId(source.getCode()); } if (StringUtils.isNotBlank(source.getJsonextrainfo())) { builder.setJsonextrainfo(source.getJsonextrainfo()); } else { builder.setJsonextrainfo(ProjectConverter.BLANK_JSONEXTRAINFO); } if (CollectionUtils.isNotEmpty(source.getFundingPath())) { builder.setFundingClass(fundingTreeParser.extractFundingClass(source.getFundingPath())); } return builder.build(); }  Project convert(ProjectDetail source);  }
@Test(expected=RuntimeException.class) public void testConversionOnInvalidProjectId() throws Exception { ProjectDetail source = new ProjectDetail(); source.setProjectId("invalidId"); converter.convert(source); }
@Test public void testConversionOnObject() throws Exception { ProjectDetail source = new ProjectDetail(); source.setProjectId("xyz_________::1234"); source.setAcronym("acronym"); Project result = converter.convert(source); assertNotNull(result); assertEquals("40|xyz_________::81dc9bdb52d04dc20036dbd8313ed055", result.getId()); assertEquals(source.getAcronym(), result.getProjectAcronym()); assertEquals(ProjectConverter.BLANK_JSONEXTRAINFO, result.getJsonextrainfo()); }
@Test public void testConversionOnResource() throws Exception { List<Project> expected = JsonUtils.convertToList(outputResourceLocation, Project.SCHEMA$, Project.class); StreamingFacade streamingFacade = new StreamingFacadeMockFactory().instantiate(null); List<Project> actual = new ArrayList<>(); try (Scanner scanner = new Scanner(new BufferedInputStream(streamingFacade.getStream()))) { String line = getNonEmptyLine(scanner); assertNotNull(line); ProjectDetail projectDetail = ProjectDetail.fromJson(line); assertNotNull(projectDetail); actual.add(converter.convert(projectDetail)); line = getNonEmptyLine(scanner); assertNotNull(line); projectDetail = ProjectDetail.fromJson(line); assertNotNull(projectDetail); actual.add(converter.convert(projectDetail)); line = getNonEmptyLine(scanner); assertNull(line); } TestsIOUtils.assertEqualSets(expected, actual, true); }