@Test public void shouldUpdateOrInsertOnSaveBasedOnHasId() { FacilityType facType = mock(FacilityType.class); when(facType.hasId()).thenReturn(true); repo.save(facType); verify(mapper).update(facType); when(facType.hasId()).thenReturn(false); repo.save(facType); verify(mapper).insert(facType); }
public void save(FacilityType facilityType) { if(facilityType == null) throw new NullPointerException("FacilityType argument is null"); try { if(facilityType.hasId()) mapper.update(facilityType); else mapper.insert(facilityType); } catch(DuplicateKeyException dke) { throw new DataException("error.duplicate.facility.type", dke); } catch(DataIntegrityViolationException dive) { throw new DataException("error.incorrect.length", dive); } }
FacilityTypeRepository { public void save(FacilityType facilityType) { if(facilityType == null) throw new NullPointerException("FacilityType argument is null"); try { if(facilityType.hasId()) mapper.update(facilityType); else mapper.insert(facilityType); } catch(DuplicateKeyException dke) { throw new DataException("error.duplicate.facility.type", dke); } catch(DataIntegrityViolationException dive) { throw new DataException("error.incorrect.length", dive); } } }
FacilityTypeRepository { public void save(FacilityType facilityType) { if(facilityType == null) throw new NullPointerException("FacilityType argument is null"); try { if(facilityType.hasId()) mapper.update(facilityType); else mapper.insert(facilityType); } catch(DuplicateKeyException dke) { throw new DataException("error.duplicate.facility.type", dke); } catch(DataIntegrityViolationException dive) { throw new DataException("error.incorrect.length", dive); } } @Autowired  FacilityTypeRepository(FacilityTypeMapper facilityTypeMapper); }
FacilityTypeRepository { public void save(FacilityType facilityType) { if(facilityType == null) throw new NullPointerException("FacilityType argument is null"); try { if(facilityType.hasId()) mapper.update(facilityType); else mapper.insert(facilityType); } catch(DuplicateKeyException dke) { throw new DataException("error.duplicate.facility.type", dke); } catch(DataIntegrityViolationException dive) { throw new DataException("error.incorrect.length", dive); } } @Autowired  FacilityTypeRepository(FacilityTypeMapper facilityTypeMapper); FacilityType getByCode(String code); FacilityType getByCodeOrThrowException(String code); List<FacilityType> getAll(); void save(FacilityType facilityType); FacilityType getFacilityTypeByCode(FacilityType facilityType); }
FacilityTypeRepository { public void save(FacilityType facilityType) { if(facilityType == null) throw new NullPointerException("FacilityType argument is null"); try { if(facilityType.hasId()) mapper.update(facilityType); else mapper.insert(facilityType); } catch(DuplicateKeyException dke) { throw new DataException("error.duplicate.facility.type", dke); } catch(DataIntegrityViolationException dive) { throw new DataException("error.incorrect.length", dive); } } @Autowired  FacilityTypeRepository(FacilityTypeMapper facilityTypeMapper); FacilityType getByCode(String code); FacilityType getByCodeOrThrowException(String code); List<FacilityType> getAll(); void save(FacilityType facilityType); FacilityType getFacilityTypeByCode(FacilityType facilityType); static final String ERROR_FACILITY_TYPE_CODE_INVALID; }