### Question:
ScChamberDivisionCreator { public SupremeCourtChamberDivision getOrCreateScChamberDivision(String chamberDivisionFullName) { Preconditions.checkArgument(StringUtils.isNotBlank(chamberDivisionFullName)); SupremeCourtChamberDivision scChamberDivision = scChamberDivisionRepository.findOneByFullName(chamberDivisionFullName); if (scChamberDivision == null) { SupremeCourtChamber scChamber = findScChamber(chamberDivisionFullName); scChamberDivision = createAndSaveScChamberDivision(scChamber, chamberDivisionFullName); } return scChamberDivision; }  SupremeCourtChamberDivision getOrCreateScChamberDivision(String chamberDivisionFullName); @Autowired void setScChamberRepository(ScChamberRepository scChamberRepository); @Autowired void setScChamberDivisionRepository(ScChamberDivisionRepository scChamberDivisionRepository); @Autowired void setScChamberDivisionNameExtractor(ScChamberDivisionNameExtractor scChamberDivisionNameExtractor);  }### Answer:
@Test(expected=IllegalArgumentException.class) public void getOrCreateScChamberDivision_EmptyDivisioName() { scChamberDivisionCreator.getOrCreateScChamberDivision(""); }
@Test public void getOrCreateScChamberDivision_Found() { String divisionFullName = "Izba Karna Wydział 2"; SupremeCourtChamberDivision scChamberDivision = new SupremeCourtChamberDivision(); when(scChamberDivisionRepository.findOneByFullName(divisionFullName)).thenReturn(scChamberDivision); SupremeCourtChamberDivision retScChamberDivision = scChamberDivisionCreator.getOrCreateScChamberDivision(divisionFullName); assertTrue(retScChamberDivision == scChamberDivision); }
@Test(expected=EntityNotFoundException.class) public void getOrCreateScChamberDivision_NotFound_Create_ChamberNotFound() { String divisionFullName = "Izba Karna Wydział 2"; when(scChamberDivisionRepository.findOneByFullName(divisionFullName)).thenReturn(null); String chamberName = "Izba Karna"; when(scChamberDivisionNameExtractor.extractChamberName(divisionFullName)).thenReturn(chamberName); when(scChamberRepository.findOneByName(chamberName)).thenReturn(null); scChamberDivisionCreator.getOrCreateScChamberDivision(divisionFullName); }
@Test public void getOrCreateScChamberDivision_NotFound_Create_ChamberFound() { String divisionFullName = "Izba Karna Wydział 2"; when(scChamberDivisionRepository.findOneByFullName(divisionFullName)).thenReturn(null); String chamberName = "Izba Karna"; when(scChamberDivisionNameExtractor.extractChamberName(divisionFullName)).thenReturn(chamberName); SupremeCourtChamber scChamber = new SupremeCourtChamber(); when(scChamberRepository.findOneByName(chamberName)).thenReturn(scChamber); String divisionName = "Wydział 2"; when(scChamberDivisionNameExtractor.extractDivisionName(divisionFullName)).thenReturn(divisionName); SupremeCourtChamberDivision scChamberDivision = scChamberDivisionCreator.getOrCreateScChamberDivision(divisionFullName); assertTrue(scChamber == scChamberDivision.getScChamber()); assertEquals(divisionFullName, scChamberDivision.getFullName()); assertEquals(divisionName, scChamberDivision.getName()); verify(scChamberDivisionRepository).saveAndFlush(scChamberDivision); }