### Question:
JudgeConverter { public Judge convertJudge(String judgeName, List<JudgeRole> specialRoles, ImportCorrectionList correctionList) { Preconditions.checkNotNull(correctionList); String normalizedJudgeName = judgeNameNormalizer.normalize(judgeName); if (StringUtils.isBlank(normalizedJudgeName)) { correctionList.addCorrection(createDelete(Judge.class).oldValue(judgeName).newValue(null).build()); return null; } Judge judge = new Judge(normalizedJudgeName, specialRoles); if (!(PersonNameNormalizer.unify(judgeName).equals(toRootLowerCase(normalizedJudgeName)))) { correctionList.addCorrection(createUpdate(judge) .ofProperty(CorrectedProperty.NAME).oldValue(judgeName).newValue(normalizedJudgeName) .build()); } return judge; }  Judge convertJudge(String judgeName, List<JudgeRole> specialRoles, ImportCorrectionList correctionList); Judge convertJudge(String judgeName, ImportCorrectionList correctionList); @Autowired void setJudgeNameNormalizer(JudgeNameNormalizer judgeNameNormalizer);  }### Answer:
@Test(expected=NullPointerException.class) public void convert_correctionListNull() { judgeConverter.convertJudge("ssd ", null); }
@Test public void convert_normalizedNameBlank() { String judgeName = " !! "; when(judgeNameNormalizer.normalize(judgeName)).thenReturn(" "); Judge judge = judgeConverter.convertJudge(judgeName, correctionList); assertNull(judge); assertEquals(1, correctionList.getNumberOfCorrections()); correctionList.hasImportCorrection(createDelete(Judge.class).oldValue(judgeName).newValue(null).build()); }
@Test public void convert_nameCorrection() { String judgeName = " Jan Nowak!! "; String normalizedJudgeName = "Jan Nowak"; when(judgeNameNormalizer.normalize(judgeName)).thenReturn(normalizedJudgeName); Judge judge = judgeConverter.convertJudge(judgeName, correctionList); assertNotNull(judge); assertEquals(normalizedJudgeName, judge.getName()); assertEquals(0, judge.getSpecialRoles().size()); assertEquals(1, correctionList.getNumberOfCorrections()); correctionList.hasImportCorrection(createUpdate(judge).ofProperty(NAME).oldValue(judgeName).newValue(normalizedJudgeName).build()); }
@Test public void convert_withRoles_noCorrection() { String judgeName = " Jan Nowak "; String normalizedJudgeName = "Jan Nowak"; List<JudgeRole> judgeRoles = Lists.newArrayList(JudgeRole.PRESIDING_JUDGE, JudgeRole.REPORTING_JUDGE); when(judgeNameNormalizer.normalize(judgeName)).thenReturn(normalizedJudgeName); Judge judge = judgeConverter.convertJudge(judgeName, judgeRoles, correctionList); assertNotNull(judge); assertEquals(normalizedJudgeName, judge.getName()); assertThat(judge.getSpecialRoles(), Matchers.containsInAnyOrder(JudgeRole.PRESIDING_JUDGE, JudgeRole.REPORTING_JUDGE)); assertEquals(0, correctionList.getNumberOfCorrections()); }
@Test public void convert_LongDashIsNoCorrection() { String judgeName = "Jan Nowak– Kos"; String normalizedJudgeName = "Jan Nowak-Kos"; assertNotEquals(toRootLowerCase(judgeName), PersonNameNormalizer.unify(judgeName)); assertEquals(toRootLowerCase(normalizedJudgeName), PersonNameNormalizer.unify(normalizedJudgeName)); when(judgeNameNormalizer.normalize(judgeName)).thenReturn(normalizedJudgeName); Judge judge = judgeConverter.convertJudge(judgeName, correctionList); assertNotNull(judge); assertEquals(normalizedJudgeName, judge.getName()); assertEquals(0, judge.getSpecialRoles().size()); assertEquals(0, correctionList.getNumberOfCorrections()); }