|
1
|
|
package fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.services; |
|
2
|
|
|
|
3
|
|
import fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.models.Sondage; |
|
4
|
|
import fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.repositories.SondageRepository; |
|
5
|
|
import fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.utils.ErrorMessages; |
|
6
|
|
import jakarta.persistence.NoResultException; |
|
7
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
8
|
|
import org.springframework.stereotype.Service; |
|
9
|
|
|
|
10
|
|
import java.util.List; |
|
11
|
|
import java.util.NoSuchElementException; |
|
12
|
|
|
|
13
|
|
@Service |
|
14
|
|
public class SondageService { |
|
15
|
|
|
|
16
|
|
@Autowired |
|
17
|
|
private SondageRepository repository; |
|
18
|
|
|
|
19
|
|
@Autowired |
|
20
|
|
private ParticipantService participantService; |
|
21
|
|
|
|
22
|
|
public Sondage create(Long idParticipant, Sondage sondage) { |
|
23
|
|
try { |
|
24
|
1
1. create : removed call to fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/models/Sondage::setCreateBy → KILLED
|
sondage.setCreateBy(participantService.getById(idParticipant)); |
|
25
|
1
1. create : replaced return value with null for fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/services/SondageService::create → KILLED
|
return repository.save(sondage); |
|
26
|
|
} |
|
27
|
|
catch (NoResultException e) { |
|
28
|
|
throw new NoSuchElementException(ErrorMessages.PARTICIPANT_DOES_NOT_EXISTS); |
|
29
|
|
} |
|
30
|
|
} |
|
31
|
|
|
|
32
|
|
public Sondage getById(Long id) { |
|
33
|
1
1. getById : negated conditional → KILLED
|
if(!exists(id)) |
|
34
|
|
throw new NoResultException(ErrorMessages.SONDAGE_DOES_NOT_EXISTS); |
|
35
|
1
1. getById : replaced return value with null for fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/services/SondageService::getById → KILLED
|
return repository.getReferenceById(id); |
|
36
|
|
} |
|
37
|
|
|
|
38
|
|
public List<Sondage> getAll() { |
|
39
|
|
List<Sondage> sondages = repository.findAll(); |
|
40
|
1
1. getAll : negated conditional → KILLED
|
if (sondages.isEmpty()) |
|
41
|
|
throw new NoResultException("Aucun sondage n'a été trouvé."); |
|
42
|
1
1. getAll : replaced return value with Collections.emptyList for fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/services/SondageService::getAll → KILLED
|
return sondages; |
|
43
|
|
} |
|
44
|
|
|
|
45
|
|
public Sondage update(Long id, Sondage newSondage) { |
|
46
|
|
Sondage sondage = getById(id); |
|
47
|
2
1. update : negated conditional → KILLED
2. update : removed call to fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/models/Sondage::setFin → KILLED
|
if (newSondage.getFin() != null) sondage.setFin(newSondage.getFin()); |
|
48
|
2
1. update : negated conditional → KILLED
2. update : removed call to fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/models/Sondage::setNom → KILLED
|
if (newSondage.getNom() != null) sondage.setNom(newSondage.getNom()); |
|
49
|
2
1. update : negated conditional → KILLED
2. update : removed call to fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/models/Sondage::setDescription → KILLED
|
if (newSondage.getDescription() != null) sondage.setDescription(newSondage.getDescription()); |
|
50
|
2
1. update : negated conditional → KILLED
2. update : removed call to fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/models/Sondage::setCloture → KILLED
|
if (newSondage.getCloture() != null) sondage.setCloture(newSondage.getCloture()); |
|
51
|
1
1. update : replaced return value with null for fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/services/SondageService::update → KILLED
|
return repository.save(sondage); |
|
52
|
|
} |
|
53
|
|
|
|
54
|
|
public void delete(Long id) { |
|
55
|
1
1. delete : negated conditional → KILLED
|
if (!exists(id)) |
|
56
|
|
throw new NoSuchElementException(ErrorMessages.SONDAGE_DOES_NOT_EXISTS); |
|
57
|
1
1. delete : removed call to fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/repositories/SondageRepository::deleteById → KILLED
|
repository.deleteById(id); |
|
58
|
|
} |
|
59
|
|
|
|
60
|
|
public boolean exists(Long id) { |
|
61
|
2
1. exists : replaced boolean return with true for fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/services/SondageService::exists → KILLED
2. exists : replaced boolean return with false for fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/services/SondageService::exists → KILLED
|
return repository.existsById(id); |
|
62
|
|
} |
|
63
|
|
} |
| | Mutations |
| 24 |
|
1.1 Location : create Killed by : fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.SondageServiceUnitTest.[engine:junit-jupiter]/[class:fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.SondageServiceUnitTest]/[method:givenAnIdAndASondage_whenCreate_thenParticipantServiceAndSondageRepositoryAreCalled()] removed call to fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/models/Sondage::setCreateBy → KILLED
|
| 25 |
|
1.1 Location : create Killed by : fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.SondageServiceUnitTest.[engine:junit-jupiter]/[class:fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.SondageServiceUnitTest]/[method:givenAnIdAndASondage_whenCreate_thenParticipantServiceAndSondageRepositoryAreCalled()] replaced return value with null for fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/services/SondageService::create → KILLED
|
| 33 |
|
1.1 Location : getById Killed by : fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.SondageServiceUnitTest.[engine:junit-jupiter]/[class:fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.SondageServiceUnitTest]/[method:givenAnId_whenGetById_thenSondageRepositoryIsCalled()] negated conditional → KILLED
|
| 35 |
|
1.1 Location : getById Killed by : fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.SondageServiceUnitTest.[engine:junit-jupiter]/[class:fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.SondageServiceUnitTest]/[method:givenAnId_whenGetById_thenSondageRepositoryIsCalled()] replaced return value with null for fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/services/SondageService::getById → KILLED
|
| 40 |
|
1.1 Location : getAll Killed by : fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.SondageServiceUnitTest.[engine:junit-jupiter]/[class:fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.SondageServiceUnitTest]/[method:givenAnId_whenGetAll_thenSondageRepositoryIsCalled()] negated conditional → KILLED
|
| 42 |
|
1.1 Location : getAll Killed by : fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.SondageServiceUnitTest.[engine:junit-jupiter]/[class:fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.SondageServiceUnitTest]/[method:givenAnId_whenGetAll_thenSondageRepositoryIsCalled()] replaced return value with Collections.emptyList for fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/services/SondageService::getAll → KILLED
|
| 47 |
|
1.1 Location : update Killed by : fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.SondageServiceUnitTest.[engine:junit-jupiter]/[class:fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.SondageServiceUnitTest]/[method:givenASondageIdThatExists_whenUpdate_thenSondageRepositoryIsCalledTwoTimes()] negated conditional → KILLED 2.2 Location : update Killed by : fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.SondageServiceUnitTest.[engine:junit-jupiter]/[class:fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.SondageServiceUnitTest]/[method:givenASondageIdThatExists_whenUpdate_thenSondageRepositoryIsCalledTwoTimes()] removed call to fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/models/Sondage::setFin → KILLED
|
| 48 |
|
1.1 Location : update Killed by : fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.SondageServiceUnitTest.[engine:junit-jupiter]/[class:fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.SondageServiceUnitTest]/[method:givenASondageIdThatExists_whenUpdate_thenSondageRepositoryIsCalledTwoTimes()] negated conditional → KILLED 2.2 Location : update Killed by : fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.SondageServiceUnitTest.[engine:junit-jupiter]/[class:fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.SondageServiceUnitTest]/[method:givenASondageIdThatExists_whenUpdate_thenSondageRepositoryIsCalledTwoTimes()] removed call to fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/models/Sondage::setNom → KILLED
|
| 49 |
|
1.1 Location : update Killed by : fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.SondageServiceUnitTest.[engine:junit-jupiter]/[class:fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.SondageServiceUnitTest]/[method:givenASondageIdThatExists_whenUpdate_thenSondageRepositoryIsCalledTwoTimes()] negated conditional → KILLED 2.2 Location : update Killed by : fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.SondageServiceUnitTest.[engine:junit-jupiter]/[class:fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.SondageServiceUnitTest]/[method:givenASondageIdThatExists_whenUpdate_thenSondageRepositoryIsCalledTwoTimes()] removed call to fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/models/Sondage::setDescription → KILLED
|
| 50 |
|
1.1 Location : update Killed by : fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.SondageServiceUnitTest.[engine:junit-jupiter]/[class:fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.SondageServiceUnitTest]/[method:givenASondageIdThatExists_whenUpdate_thenSondageRepositoryIsCalledTwoTimes()] negated conditional → KILLED 2.2 Location : update Killed by : fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.SondageServiceUnitTest.[engine:junit-jupiter]/[class:fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.SondageServiceUnitTest]/[method:givenASondageIdThatExists_whenUpdate_thenSondageRepositoryIsCalledTwoTimes()] removed call to fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/models/Sondage::setCloture → KILLED
|
| 51 |
|
1.1 Location : update Killed by : fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.SondageServiceUnitTest.[engine:junit-jupiter]/[class:fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.SondageServiceUnitTest]/[method:givenASondageIdThatExists_whenUpdate_thenSondageRepositoryIsCalledTwoTimes()] replaced return value with null for fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/services/SondageService::update → KILLED
|
| 55 |
|
1.1 Location : delete Killed by : fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.SondageServiceUnitTest.[engine:junit-jupiter]/[class:fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.SondageServiceUnitTest]/[method:givenASondageIdAThatDoesNotExists_whenDelete_thenSondageRepositoryIsCalledOneTime()] negated conditional → KILLED
|
| 57 |
|
1.1 Location : delete Killed by : fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.SondageServiceUnitTest.[engine:junit-jupiter]/[class:fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.SondageServiceUnitTest]/[method:givenASondageIdThatExists_whenDelete_thenSondageRepositoryIsCalledTwoTimes()] removed call to fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/repositories/SondageRepository::deleteById → KILLED
|
| 61 |
|
1.1 Location : exists Killed by : fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.SondageServiceUnitTest.[engine:junit-jupiter]/[class:fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.SondageServiceUnitTest]/[method:givenASondageIdAThatDoesNotExists_whenDelete_thenSondageRepositoryIsCalledOneTime()] replaced boolean return with true for fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/services/SondageService::exists → KILLED 2.2 Location : exists Killed by : fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.SondageServiceUnitTest.[engine:junit-jupiter]/[class:fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.SondageServiceUnitTest]/[method:givenAnId_whenGetById_thenSondageRepositoryIsCalled()] replaced boolean return with false for fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/services/SondageService::exists → KILLED
|