CommonsGate.java

1
package edu.ucsb.cs156.happiercows.jobs;
2
3
import java.time.LocalDateTime;
4
5
import edu.ucsb.cs156.happiercows.entities.Commons;
6
import edu.ucsb.cs156.happiercows.repositories.CommonsRepository;
7
import edu.ucsb.cs156.jobs.services.JobContext;
8
9
/**
10
 * A shared gate used by every job (scheduled or on demand) that operates on a
11
 * commons: jobs should only touch games that are in progress (see
12
 * {@link Commons#gameInProgress(LocalDateTime)}).
13
 *
14
 * As a side effect, when a commons whose end date has passed is encountered,
15
 * it is automatically hidden (see issue #250).
16
 */
17
public class CommonsGate {
18
19
    /**
20
     * Determine whether a job should process the given commons.
21
     *
22
     * If the game is not in progress, a skip message is logged; additionally,
23
     * if the game has ended and the commons is not yet hidden, it is hidden
24
     * and saved.
25
     *
26
     * @param commons the commons the job wants to process
27
     * @param commonsRepository repository used to save the commons when it is auto-hidden
28
     * @param ctx the job context, for logging
29
     * @return true if the game is in progress and the job should proceed
30
     */
31
    public static boolean shouldProcess(Commons commons, CommonsRepository commonsRepository, JobContext ctx) {
32
        LocalDateTime now = LocalDateTime.now();
33 1 1. shouldProcess : negated conditional → KILLED
        if (commons.gameInProgress(now)) {
34 1 1. shouldProcess : replaced boolean return with false for edu/ucsb/cs156/happiercows/jobs/CommonsGate::shouldProcess → KILLED
            return true;
35
        }
36 1 1. shouldProcess : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED
        ctx.log(String.format("Skipping Commons id=%d (%s) because the game is not in progress",
37
                commons.getId(), commons.getName()));
38 2 1. shouldProcess : negated conditional → KILLED
2. shouldProcess : negated conditional → KILLED
        if (commons.endDateHasPassed(now) && !commons.isHidden()) {
39 1 1. shouldProcess : removed call to edu/ucsb/cs156/happiercows/entities/Commons::setHidden → KILLED
            commons.setHidden(true);
40
            commonsRepository.save(commons);
41 1 1. shouldProcess : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED
            ctx.log(String.format("Commons id=%d (%s) has ended; setting hidden to true",
42
                    commons.getId(), commons.getName()));
43
        }
44 1 1. shouldProcess : replaced boolean return with true for edu/ucsb/cs156/happiercows/jobs/CommonsGate::shouldProcess → KILLED
        return false;
45
    }
46
}

Mutations

33

1.1
Location : shouldProcess
Killed by : edu.ucsb.cs156.happiercows.jobs.CommonsGateTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.jobs.CommonsGateTests]/[method:shouldProcess_returns_true_and_logs_nothing_when_game_in_progress()]
negated conditional → KILLED

34

1.1
Location : shouldProcess
Killed by : edu.ucsb.cs156.happiercows.jobs.CommonsGateTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.jobs.CommonsGateTests]/[method:shouldProcess_returns_true_and_logs_nothing_when_game_in_progress()]
replaced boolean return with false for edu/ucsb/cs156/happiercows/jobs/CommonsGate::shouldProcess → KILLED

36

1.1
Location : shouldProcess
Killed by : edu.ucsb.cs156.happiercows.jobs.CommonsGateTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.jobs.CommonsGateTests]/[method:shouldProcess_returns_false_and_does_not_hide_when_game_not_yet_started()]
removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED

38

1.1
Location : shouldProcess
Killed by : edu.ucsb.cs156.happiercows.jobs.CommonsGateTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.jobs.CommonsGateTests]/[method:shouldProcess_returns_false_and_does_not_hide_when_game_not_yet_started()]
negated conditional → KILLED

2.2
Location : shouldProcess
Killed by : edu.ucsb.cs156.happiercows.jobs.CommonsGateTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.jobs.CommonsGateTests]/[method:shouldProcess_does_not_save_again_when_ended_commons_is_already_hidden()]
negated conditional → KILLED

39

1.1
Location : shouldProcess
Killed by : edu.ucsb.cs156.happiercows.jobs.CommonsGateTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.jobs.CommonsGateTests]/[method:shouldProcess_returns_false_and_hides_commons_when_game_has_ended()]
removed call to edu/ucsb/cs156/happiercows/entities/Commons::setHidden → KILLED

41

1.1
Location : shouldProcess
Killed by : edu.ucsb.cs156.happiercows.jobs.CommonsGateTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.jobs.CommonsGateTests]/[method:shouldProcess_returns_false_and_hides_commons_when_game_has_ended()]
removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED

44

1.1
Location : shouldProcess
Killed by : edu.ucsb.cs156.happiercows.jobs.CommonsGateTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.jobs.CommonsGateTests]/[method:shouldProcess_returns_false_and_does_not_hide_when_game_not_yet_started()]
replaced boolean return with true for edu/ucsb/cs156/happiercows/jobs/CommonsGate::shouldProcess → KILLED

Active mutators

Tests examined


Report generated by PIT 1.17.0