MailingResult.java

1
package de.aikiit.mailversendala;
2
3
/*
4
 * Copyright (c) P. Ottlinger
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *   https://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing,
13
 * software distributed under the License is distributed on an
14
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
 * KIND, either express or implied.  See the License for the
16
 * specific language governing permissions and limitations
17
 * under the License.
18
 */
19
20
21
import java.util.Optional;
22
import java.util.concurrent.atomic.AtomicInteger;
23
24
/**
25
 * Class encapsulates internal counters to gauge
26
 * <ul>
27
 * <li>how many errors and</li>
28
 * <li>how many mails were successfully sent out</li>
29
 * </ul>
30
 * during an application run.
31
 */
32
public class MailingResult {
33
34
    private AtomicInteger errorCounter;
35
    private AtomicInteger mailCounter;
36
37
    /**
38
     * Increment internal error counter by 1.
39
     */
40
    public void addError() {
41 1 1. addError : negated conditional → KILLED
        if (errorCounter == null) {
42
            this.errorCounter = new AtomicInteger(0);
43
        }
44
        errorCounter.incrementAndGet();
45
    }
46
47
    /**
48
     * Increment internal success counter by 1.
49
     */
50
    public void addSuccess() {
51 1 1. addSuccess : negated conditional → KILLED
        if (mailCounter == null) {
52
            this.mailCounter = new AtomicInteger(0);
53
        }
54
        mailCounter.incrementAndGet();
55
    }
56
57
    /**
58
     * Returns error counter.
59
     * @return current error counter if existing.
60
     */
61
    public Optional<AtomicInteger> getErrorCounter() {
62 1 1. getErrorCounter : replaced return value with Optional.empty for de/aikiit/mailversendala/MailingResult::getErrorCounter → KILLED
        return Optional.ofNullable(errorCounter);
63
    }
64
65
    /**
66
     * Returns success counter.
67
     * @return current success counter if existing.
68
     */
69
    public Optional<AtomicInteger> getMailCounter() {
70 1 1. getMailCounter : replaced return value with Optional.empty for de/aikiit/mailversendala/MailingResult::getMailCounter → KILLED
        return Optional.ofNullable(mailCounter);
71
    }
72
73
    /**
74
     * Returns total counter.
75
     * @return sum of {@link #mailCounter} and {@link #errorCounter}.
76
     */
77
    public int getTotal() {
78 2 1. getTotal : Replaced integer addition with subtraction → KILLED
2. getTotal : replaced int return with 0 for de/aikiit/mailversendala/MailingResult::getTotal → KILLED
        return getErrorCounter().orElse(new AtomicInteger(0)).get() + getMailCounter().orElse(new AtomicInteger(0)).get();
79
    }
80
81
}

Mutations

41

1.1
Location : addError
Killed by : de.aikiit.mailversendala.MailingResultTest.[engine:junit-jupiter]/[class:de.aikiit.mailversendala.MailingResultTest]/[method:incrementErrorCounter()]
negated conditional → KILLED

51

1.1
Location : addSuccess
Killed by : de.aikiit.mailversendala.MailingResultTest.[engine:junit-jupiter]/[class:de.aikiit.mailversendala.MailingResultTest]/[method:incrementSuccessCounterAndTotal()]
negated conditional → KILLED

62

1.1
Location : getErrorCounter
Killed by : de.aikiit.mailversendala.MailingResultTest.[engine:junit-jupiter]/[class:de.aikiit.mailversendala.MailingResultTest]/[method:incrementErrorCounter()]
replaced return value with Optional.empty for de/aikiit/mailversendala/MailingResult::getErrorCounter → KILLED

70

1.1
Location : getMailCounter
Killed by : de.aikiit.mailversendala.MailingResultTest.[engine:junit-jupiter]/[class:de.aikiit.mailversendala.MailingResultTest]/[method:incrementSuccessCounterAndTotal()]
replaced return value with Optional.empty for de/aikiit/mailversendala/MailingResult::getMailCounter → KILLED

78

1.1
Location : getTotal
Killed by : de.aikiit.mailversendala.MailingResultTest.[engine:junit-jupiter]/[class:de.aikiit.mailversendala.MailingResultTest]/[method:incrementSuccessCounterAndTotal()]
Replaced integer addition with subtraction → KILLED

2.2
Location : getTotal
Killed by : de.aikiit.mailversendala.MailingResultTest.[engine:junit-jupiter]/[class:de.aikiit.mailversendala.MailingResultTest]/[method:incrementErrorCounter()]
replaced int return with 0 for de/aikiit/mailversendala/MailingResult::getTotal → KILLED

Active mutators

Tests examined


Report generated by PIT 1.30.2 support