@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); }
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; }
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; } }
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; }  }
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); }
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);  }