Context.java

1
package com.renomad.minum.state;
2
3
import com.renomad.minum.database.Db;
4
import com.renomad.minum.database.DbData;
5
import com.renomad.minum.database.DbEngine2;
6
import com.renomad.minum.logging.ILogger;
7
import com.renomad.minum.queue.ActionQueueState;
8
import com.renomad.minum.web.FullSystem;
9
10
import java.nio.file.Path;
11
import java.util.concurrent.ExecutorService;
12
13
14
/**
15
 * Holds important system-wide data and methods, such as the
16
 * logger, constants, and the {@link FullSystem} instance.
17
 * <p>
18
 *     The common situations:
19
 * </p>
20
 * <ul>
21
 *     <li>Building a Minum {@link Db} database</li>
22
 *     <li>Getting system constants like the database directory</li>
23
 *     <li>Getting the system {@link ExecutorService} for starting threads or an {@link com.renomad.minum.queue.ActionQueue}</li>
24
 *     <li>Getting a {@link FullSystem} object, which has</li>
25
 *     <ul>
26
 *         <li>the {@link com.renomad.minum.web.WebFramework}, which registers endpoints</li>
27
 *         <li>the {@link com.renomad.minum.security.TheBrig}, which handles bad actors on the internet</li>
28
 *     </ul>
29
 * </ul>
30
 */
31
public final class Context {
32
33
    private final ILogger logger;
34
    private final ExecutorService executorService;
35
    private final Constants constants;
36
    private FullSystem fullSystem;
37
    private final ActionQueueState actionQueueState;
38
39
    public Context(ExecutorService executorService, Constants constants, ILogger logger) {
40
        this.executorService = executorService;
41
        this.constants = constants;
42
        actionQueueState = new ActionQueueState();
43
        this.logger = logger;
44
    }
45
46
    public ILogger getLogger() {
47 1 1. getLogger : replaced return value with null for com/renomad/minum/state/Context::getLogger → KILLED
        return logger;
48
    }
49
50
    public ExecutorService getExecutorService() {
51 1 1. getExecutorService : replaced return value with null for com/renomad/minum/state/Context::getExecutorService → KILLED
        return executorService;
52
    }
53
54
    public Constants getConstants() {
55 1 1. getConstants : replaced return value with null for com/renomad/minum/state/Context::getConstants → KILLED
        return constants;
56
    }
57
58
    public void setFullSystem(FullSystem fullSystem) {
59
        this.fullSystem = fullSystem;
60
    }
61
62
    public FullSystem getFullSystem() {
63 1 1. getFullSystem : replaced return value with null for com/renomad/minum/state/Context::getFullSystem → TIMED_OUT
        return fullSystem;
64
    }
65
66
    public ActionQueueState getActionQueueState() {
67 1 1. getActionQueueState : replaced return value with null for com/renomad/minum/state/Context::getActionQueueState → KILLED
        return actionQueueState;
68
    }
69
70
    /**
71
     * This is a helper method to instantiate a {@link Db} class,
72
     * avoiding the need for a user to provide the root database
73
     * directory and the context.
74
     * <p>
75
     * Since this is a generic method, a bit of care is required when
76
     * calling.  Try to use a pattern like the following pseudocode:
77
     * {@snippet :
78
     *  Db<Photograph> photoDb = context.getDb("photos", new Photograph());
79
     * }
80
     * @param name the name of this data.  Note that this will be used
81
     *             as the directory for the data, so use characters your
82
     *             operating system would allow.
83
     * @param instance an instance of the {@link DbData} data. This is used in the
84
     *                 Db code to deserialize the data when reading.
85
     */
86
    public <T extends DbData<?>> Db<T> getDb(String name, T instance) {
87 1 1. getDb : replaced return value with null for com/renomad/minum/state/Context::getDb → KILLED
        return new Db<>(Path.of(constants.dbDirectory, name), this, instance);
88
    }
89
90
    /**
91
     * This is a helper method to instantiate a {@link DbEngine2} class,
92
     * using the engine2 database implementation. It is similar to
93
     * {@link #getDb(String, DbData)} in all other respects.
94
     * <p>
95
     *     By switching your old database calls to use this, when it runs
96
     *     it will convert the file schema.
97
     * </p>
98
     * <p>
99
     *     <b>Please backup your database before conversion</b>
100
     * </p>
101
     */
102
    public <T extends DbData<?>> DbEngine2<T> getDb2(String name, T instance) {
103 1 1. getDb2 : replaced return value with null for com/renomad/minum/state/Context::getDb2 → KILLED
        return new DbEngine2<>(Path.of(constants.dbDirectory, name), this, instance);
104
    }
105
106
107
}

Mutations

47

1.1
Location : getLogger
Killed by : com.renomad.minum.logging.TestLoggerTests.test_TestLogger_MaxLines(com.renomad.minum.logging.TestLoggerTests)
replaced return value with null for com/renomad/minum/state/Context::getLogger → KILLED

51

1.1
Location : getExecutorService
Killed by : com.renomad.minum.web.FullSystemTests.test_BlockCore_RegularException(com.renomad.minum.web.FullSystemTests)
replaced return value with null for com/renomad/minum/state/Context::getExecutorService → KILLED

55

1.1
Location : getConstants
Killed by : com.renomad.minum.web.WebFrameworkTests.test_ExtraMimeMappings_Null(com.renomad.minum.web.WebFrameworkTests)
replaced return value with null for com/renomad/minum/state/Context::getConstants → KILLED

63

1.1
Location : getFullSystem
Killed by : none
replaced return value with null for com/renomad/minum/state/Context::getFullSystem → TIMED_OUT

67

1.1
Location : getActionQueueState
Killed by : com.renomad.minum.web.FullSystemTests.test_BlockCore_RegularException(com.renomad.minum.web.FullSystemTests)
replaced return value with null for com/renomad/minum/state/Context::getActionQueueState → KILLED

87

1.1
Location : getDb
Killed by : com.renomad.minum.database.DbEngine2Tests.test_ConvertingDatabase_Db_To_DbEngine2(com.renomad.minum.database.DbEngine2Tests)
replaced return value with null for com/renomad/minum/state/Context::getDb → KILLED

103

1.1
Location : getDb2
Killed by : com.renomad.minum.web.FullSystemTests.testFullSystem_EdgeCase_InstantlyClosed(com.renomad.minum.web.FullSystemTests)
replaced return value with null for com/renomad/minum/state/Context::getDb2 → KILLED

Active mutators

Tests examined


Report generated by PIT 1.17.0