CommentaireService.java

1
package fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.services;
2
3
import fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.models.Commentaire;
4
import fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.repositories.CommentaireRepository;
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 CommentaireService {
15
16
    @Autowired
17
    private CommentaireRepository repository;
18
19
    @Autowired
20
    private SondageService sondageService;
21
22
    @Autowired
23
    private ParticipantService participantService;
24
25
    public Commentaire create(Long idSondage, Long idParticipant, Commentaire commentaire) {
26 1 1. create : negated conditional → KILLED
        if (!sondageService.exists(idSondage))
27
            throw new NoSuchElementException(ErrorMessages.SONDAGE_DOES_NOT_EXISTS);
28 1 1. create : removed call to fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/models/Commentaire::setSondage → KILLED
        commentaire.setSondage(sondageService.getById(idSondage));
29 1 1. create : negated conditional → KILLED
        if (!participantService.exists(idParticipant))
30
            throw new NoSuchElementException(ErrorMessages.PARTICIPANT_DOES_NOT_EXISTS);
31 1 1. create : removed call to fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/models/Commentaire::setParticipant → KILLED
        commentaire.setParticipant(participantService.getById(idParticipant));
32 1 1. create : replaced return value with null for fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/services/CommentaireService::create → KILLED
        return repository.save(commentaire);
33
    }
34
35
    public Commentaire getById(Long id) {
36 1 1. getById : negated conditional → KILLED
        if(!exists(id))
37
            throw new NoResultException(ErrorMessages.COMMENTAIRE_DOES_NOT_EXISTS);
38 1 1. getById : replaced return value with null for fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/services/CommentaireService::getById → KILLED
        return repository.getReferenceById(id);
39
    }
40
41
    public List<Commentaire> getBySondageId(Long sondageId) {
42 1 1. getBySondageId : negated conditional → KILLED
        if (!sondageService.exists(sondageId))
43
            throw new NoSuchElementException(ErrorMessages.SONDAGE_DOES_NOT_EXISTS);
44
        List<Commentaire> commentaires = repository.getAllBySondage(sondageId);
45 1 1. getBySondageId : negated conditional → KILLED
        if (commentaires.isEmpty())
46
            throw new NoResultException("Aucun commentaire n'a été trouvé.");
47 1 1. getBySondageId : replaced return value with Collections.emptyList for fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/services/CommentaireService::getBySondageId → KILLED
        return commentaires;
48
    }
49
50
    public Commentaire update(Long id, Commentaire newCommentaire) {
51
        try {
52
            Commentaire commentaire = getById(id);
53 1 1. update : removed call to fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/models/Commentaire::setCommentaire → KILLED
            commentaire.setCommentaire(newCommentaire.getCommentaire());
54 1 1. update : replaced return value with null for fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/services/CommentaireService::update → KILLED
            return repository.save(commentaire);
55
        }
56
        catch (NoResultException e) {
57
            throw new NoSuchElementException(ErrorMessages.COMMENTAIRE_DOES_NOT_EXISTS);
58
        }
59
    }
60
61
    public void delete(Long id) {
62 1 1. delete : negated conditional → KILLED
        if (!exists(id))
63
            throw new NoSuchElementException(ErrorMessages.COMMENTAIRE_DOES_NOT_EXISTS);
64 1 1. delete : removed call to fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/repositories/CommentaireRepository::deleteById → KILLED
        repository.deleteById(id);
65
    }
66
67
    public boolean exists(Long id) {
68 2 1. exists : replaced boolean return with true for fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/services/CommentaireService::exists → KILLED
2. exists : replaced boolean return with false for fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/services/CommentaireService::exists → KILLED
        return repository.existsById(id);
69
    }
70
}

Mutations

26

1.1
Location : create
Killed by : fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.CommentaireServiceUnitTest.[engine:junit-jupiter]/[class:fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.CommentaireServiceUnitTest]/[method:givenSondageIdThatDoesNotExist_whenCreate_thenThrowNoSuchElementException()]
negated conditional → KILLED

28

1.1
Location : create
Killed by : fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.CommentaireServiceUnitTest.[engine:junit-jupiter]/[class:fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.CommentaireServiceUnitTest]/[method:givenSondageIdAndParticipantIdAndCommentaire_whenCreate_thenServicesAndRepositoryAreCalled()]
removed call to fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/models/Commentaire::setSondage → KILLED

29

1.1
Location : create
Killed by : fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.CommentaireServiceUnitTest.[engine:junit-jupiter]/[class:fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.CommentaireServiceUnitTest]/[method:givenParticipantIdThatDoesNotExist_whenCreate_thenThrowNoSuchElementException()]
negated conditional → KILLED

31

1.1
Location : create
Killed by : fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.CommentaireServiceUnitTest.[engine:junit-jupiter]/[class:fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.CommentaireServiceUnitTest]/[method:givenSondageIdAndParticipantIdAndCommentaire_whenCreate_thenServicesAndRepositoryAreCalled()]
removed call to fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/models/Commentaire::setParticipant → KILLED

32

1.1
Location : create
Killed by : fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.CommentaireServiceUnitTest.[engine:junit-jupiter]/[class:fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.CommentaireServiceUnitTest]/[method:givenSondageIdAndParticipantIdAndCommentaire_whenCreate_thenServicesAndRepositoryAreCalled()]
replaced return value with null for fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/services/CommentaireService::create → KILLED

36

1.1
Location : getById
Killed by : fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.CommentaireServiceUnitTest.[engine:junit-jupiter]/[class:fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.CommentaireServiceUnitTest]/[method:givenAnIdThatDoesNotExist_whenUpdate_thenThrowNoSuchElementException()]
negated conditional → KILLED

38

1.1
Location : getById
Killed by : fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.CommentaireServiceUnitTest.[engine:junit-jupiter]/[class:fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.CommentaireServiceUnitTest]/[method:givenAnIdAndACommentaire_whenUpdate_thenRepositoryIsCalled()]
replaced return value with null for fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/services/CommentaireService::getById → KILLED

42

1.1
Location : getBySondageId
Killed by : fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.CommentaireServiceUnitTest.[engine:junit-jupiter]/[class:fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.CommentaireServiceUnitTest]/[method:givenASondageIdThatDoesNotExist_whenGetBySondageId_thenThrowNoSuchElementException()]
negated conditional → KILLED

45

1.1
Location : getBySondageId
Killed by : fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.CommentaireServiceUnitTest.[engine:junit-jupiter]/[class:fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.CommentaireServiceUnitTest]/[method:givenASondageId_whenGetBySondageId_thenRepositoryIsCalled()]
negated conditional → KILLED

47

1.1
Location : getBySondageId
Killed by : fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.CommentaireServiceUnitTest.[engine:junit-jupiter]/[class:fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.CommentaireServiceUnitTest]/[method:givenASondageId_whenGetBySondageId_thenRepositoryIsCalled()]
replaced return value with Collections.emptyList for fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/services/CommentaireService::getBySondageId → KILLED

53

1.1
Location : update
Killed by : fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.CommentaireServiceUnitTest.[engine:junit-jupiter]/[class:fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.CommentaireServiceUnitTest]/[method:givenAnIdAndACommentaire_whenUpdate_thenRepositoryIsCalled()]
removed call to fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/models/Commentaire::setCommentaire → KILLED

54

1.1
Location : update
Killed by : fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.CommentaireServiceUnitTest.[engine:junit-jupiter]/[class:fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.CommentaireServiceUnitTest]/[method:givenAnIdAndACommentaire_whenUpdate_thenRepositoryIsCalled()]
replaced return value with null for fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/services/CommentaireService::update → KILLED

62

1.1
Location : delete
Killed by : fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.CommentaireServiceUnitTest.[engine:junit-jupiter]/[class:fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.CommentaireServiceUnitTest]/[method:givenAnIdThatExists_whenDelete_thenRepositoryIsCalled()]
negated conditional → KILLED

64

1.1
Location : delete
Killed by : fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.CommentaireServiceUnitTest.[engine:junit-jupiter]/[class:fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.CommentaireServiceUnitTest]/[method:givenAnIdThatExists_whenDelete_thenRepositoryIsCalled()]
removed call to fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/repositories/CommentaireRepository::deleteById → KILLED

68

1.1
Location : exists
Killed by : fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.CommentaireServiceUnitTest.[engine:junit-jupiter]/[class:fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.CommentaireServiceUnitTest]/[method:givenAnIdThatExists_whenExists_thenReturnFalse()]
replaced boolean return with true for fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/services/CommentaireService::exists → KILLED

2.2
Location : exists
Killed by : fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.CommentaireServiceUnitTest.[engine:junit-jupiter]/[class:fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.CommentaireServiceUnitTest]/[method:givenAnIdThatExists_whenExists_thenReturnTrue()]
replaced boolean return with false for fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/services/CommentaireService::exists → KILLED

Active mutators

Tests examined


Report generated by PIT 1.15.3