GameGate.java

1
package edu.ucsb.cs156.happiercows.jobs;
2
3
import java.time.LocalDateTime;
4
5
import edu.ucsb.cs156.happiercows.entities.Game;
6
import edu.ucsb.cs156.happiercows.repositories.GameRepository;
7
import edu.ucsb.cs156.happiercows.utilities.PacificTimeUtils;
8
import edu.ucsb.cs156.jobs.services.JobContext;
9
10
/**
11
 * A shared gate used by every job (scheduled or on demand) that operates on a
12
 * game: jobs should only touch games that are in progress (see
13
 * {@link Game#gameInProgress(LocalDateTime)}).
14
 *
15
 * As a side effect, when a game whose end date has passed is encountered,
16
 * it is automatically hidden (see issue #250).
17
 */
18
public class GameGate {
19
20
    /**
21
     * Determine whether a job should process the given game, using the
22
     * current Pacific time as "now" - see issue #318 (the JVM's own default
23
     * timezone isn't guaranteed to be Pacific).
24
     *
25
     * @param game the game the job wants to process
26
     * @param gameRepository repository used to save the game when it is auto-hidden
27
     * @param ctx the job context, for logging
28
     * @return true if the game is in progress and the job should proceed
29
     */
30
    public static boolean shouldProcess(Game game, GameRepository gameRepository, JobContext ctx) {
31 2 1. shouldProcess : replaced boolean return with true for edu/ucsb/cs156/happiercows/jobs/GameGate::shouldProcess → KILLED
2. shouldProcess : replaced boolean return with false for edu/ucsb/cs156/happiercows/jobs/GameGate::shouldProcess → KILLED
        return shouldProcess(game, gameRepository, ctx, LocalDateTime.now(PacificTimeUtils.ZONE));
32
    }
33
34
    /**
35
     * Determine whether a job should process the given game as of the given
36
     * instant.
37
     *
38
     * If the game is not in progress, a skip message is logged; additionally,
39
     * if the game has ended and the game is not yet hidden, it is hidden
40
     * and saved.
41
     *
42
     * @param game the game the job wants to process
43
     * @param gameRepository repository used to save the game when it is auto-hidden
44
     * @param ctx the job context, for logging
45
     * @param now the current time, as of which to evaluate the game's status
46
     * @return true if the game is in progress and the job should proceed
47
     */
48
    public static boolean shouldProcess(
49
            Game game, GameRepository gameRepository, JobContext ctx, LocalDateTime now) {
50 1 1. shouldProcess : negated conditional → KILLED
        if (game.gameInProgress(now)) {
51 1 1. shouldProcess : replaced boolean return with false for edu/ucsb/cs156/happiercows/jobs/GameGate::shouldProcess → KILLED
            return true;
52
        }
53 1 1. shouldProcess : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED
        ctx.log(String.format("Skipping Game id=%d (%s) because the game is not in progress",
54
                game.getId(), game.getName()));
55 2 1. shouldProcess : negated conditional → KILLED
2. shouldProcess : negated conditional → KILLED
        if (game.endDateHasPassed(now) && !game.isHidden()) {
56 1 1. shouldProcess : removed call to edu/ucsb/cs156/happiercows/entities/Game::setHidden → KILLED
            game.setHidden(true);
57
            gameRepository.save(game);
58 1 1. shouldProcess : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED
            ctx.log(String.format("Game id=%d (%s) has ended; setting hidden to true",
59
                    game.getId(), game.getName()));
60
        }
61 1 1. shouldProcess : replaced boolean return with true for edu/ucsb/cs156/happiercows/jobs/GameGate::shouldProcess → KILLED
        return false;
62
    }
63
}

Mutations

31

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

2.2
Location : shouldProcess
Killed by : edu.ucsb.cs156.happiercows.jobs.GameGateTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.jobs.GameGateTests]/[method:shouldProcess_convenience_overload_delegates_to_pacific_now()]
replaced boolean return with false for edu/ucsb/cs156/happiercows/jobs/GameGate::shouldProcess → KILLED

50

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

51

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

53

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

55

1.1
Location : shouldProcess
Killed by : edu.ucsb.cs156.happiercows.jobs.GameGateTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.jobs.GameGateTests]/[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.GameGateTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.jobs.GameGateTests]/[method:shouldProcess_does_not_save_again_when_ended_game_is_already_hidden()]
negated conditional → KILLED

56

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

58

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

61

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

Active mutators

Tests examined


Report generated by PIT 1.22.1