ParticipantService.java

1
package fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.services;
2
3
import fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.models.Participant;
4
import fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.repositories.ParticipantRepository;
5
import fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.utils.ErrorMessages;
6
import fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.utils.StringUtils;
7
import jakarta.persistence.NoResultException;
8
import org.springframework.beans.factory.annotation.Autowired;
9
import org.springframework.stereotype.Service;
10
11
import java.util.List;
12
import java.util.NoSuchElementException;
13
14
@Service
15
public class ParticipantService {
16
17
    @Autowired
18
    private ParticipantRepository repository;
19
20
    public Participant create(Participant participant) {
21 1 1. create : replaced return value with null for fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/services/ParticipantService::create → KILLED
        return repository.save(participant);
22
    }
23
24
    public Participant getById(Long id) {
25 1 1. getById : negated conditional → KILLED
        if(!exists(id))
26
            throw new NoResultException(ErrorMessages.PARTICIPANT_DOES_NOT_EXISTS);
27 1 1. getById : replaced return value with null for fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/services/ParticipantService::getById → KILLED
        return repository.getReferenceById(id);
28
    }
29
30
    public List<Participant> getAll() {
31
        List<Participant> participants = repository.findAll();
32 1 1. getAll : negated conditional → KILLED
        if (participants.isEmpty())
33
            throw new NoResultException("Aucun participant n'a été trouvé.");
34 1 1. getAll : replaced return value with Collections.emptyList for fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/services/ParticipantService::getAll → KILLED
        return participants;
35
    }
36
37
    public Participant update(Long id, Participant newParticipant) {
38
        try {
39
            Participant participant = getById(id);
40 1 1. update : negated conditional → KILLED
            if (!StringUtils.isNullOrEmpty(newParticipant.getNom()))
41 1 1. update : removed call to fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/models/Participant::setNom → KILLED
                participant.setNom(newParticipant.getNom());
42 1 1. update : negated conditional → KILLED
            if (!StringUtils.isNullOrEmpty(newParticipant.getPrenom()))
43 1 1. update : removed call to fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/models/Participant::setPrenom → KILLED
                participant.setPrenom(newParticipant.getPrenom());
44 1 1. update : replaced return value with null for fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/services/ParticipantService::update → KILLED
            return repository.save(participant);
45
        }
46
        catch (NoResultException e) {
47
            throw new NoSuchElementException(ErrorMessages.PARTICIPANT_DOES_NOT_EXISTS);
48
        }
49
    }
50
51
    public void delete(Long id) {
52 1 1. delete : negated conditional → KILLED
        if (!exists(id))
53
            throw new NoSuchElementException(ErrorMessages.PARTICIPANT_DOES_NOT_EXISTS);
54 1 1. delete : removed call to fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/repositories/ParticipantRepository::deleteById → KILLED
        repository.deleteById(id);
55
    }
56
57
    public boolean exists(Long id) {
58 2 1. exists : replaced boolean return with false for fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/services/ParticipantService::exists → KILLED
2. exists : replaced boolean return with true for fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/services/ParticipantService::exists → KILLED
        return repository.existsById(id);
59
    }
60
}

Mutations

21

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

25

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

27

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

32

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

34

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

40

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

41

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

42

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

43

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

44

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

52

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

54

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

58

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

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

Active mutators

Tests examined


Report generated by PIT 1.15.3