PathDetails.java

1
package com.renomad.minum.web;
2
3
4
import java.util.HashMap;
5
import java.util.Map;
6
import java.util.Objects;
7
8
/**
9
 * Some essential characteristics of the path portion of the start line
10
 */
11
public final class PathDetails {
12
13
    public static final PathDetails empty = new PathDetails("", "", Map.of());
14
15
    private final String isolatedPath;
16
    private final String rawQueryString;
17
    private final Map<String, String> queryString;
18
19
    /**
20
     * Basic constructor
21
     * @param isolatedPath the isolated path is found after removing the query string
22
     * @param rawQueryString the raw query is the string after a question mark (if it exists - it's optional)
23
     *                       if there is no query string, then we leave rawQuery as a null value
24
     * @param queryString the query is a map of the keys -> values found in the query string
25
     */
26
    public PathDetails (
27
            String isolatedPath,
28
            String rawQueryString,
29
            Map<String, String> queryString
30
    ) {
31
        this.isolatedPath = isolatedPath;
32
        this.rawQueryString = rawQueryString;
33
        this.queryString = Objects.requireNonNullElseGet(queryString, Map::of);
34
    }
35
36
    /**
37
     * Provides the path by itself, without the query string.  For examples,
38
     * here are some request lines with their isolated paths:
39
     * <pre>
40
     * {@code
41
     * request line                                isolated path
42
     * -------------------                         -------------
43
     * POST / HTTP/1.1                             ""
44
     * GET /background.png HTTP/1.0                "background.png"
45
     * HEAD /test.html?query=alibaba HTTP/1.1      "test.html"
46
     * OPTIONS /anypage.html HTTP/1.0              "anypage.html"
47
     * }
48
     * </pre>
49
     */
50
    public String getIsolatedPath() {
51 1 1. getIsolatedPath : replaced return value with "" for com/renomad/minum/web/PathDetails::getIsolatedPath → TIMED_OUT
        return isolatedPath;
52
    }
53
54
    /**
55
     * Returns the raw query string.  For example, in "HEAD /test.html?query=alibaba HTTP/1.1",
56
     * the raw query string is "query=alibaba"
57
     */
58
    public String getRawQueryString() {
59 1 1. getRawQueryString : replaced return value with "" for com/renomad/minum/web/PathDetails::getRawQueryString → KILLED
        return rawQueryString;
60
    }
61
62
    /**
63
     * This returns the query string portion of the request line as a map, with
64
     * case-sensitive keys.
65
     * <p>
66
     *     Note: in the case of duplicate keys, last-in wins
67
     * </p>
68
     */
69
    public Map<String, String> getQueryString() {
70 1 1. getQueryString : replaced return value with Collections.emptyMap for com/renomad/minum/web/PathDetails::getQueryString → KILLED
        return new HashMap<>(queryString);
71
    }
72
73
    @Override
74
    public boolean equals(Object o) {
75 2 1. equals : negated conditional → TIMED_OUT
2. equals : replaced boolean return with false for com/renomad/minum/web/PathDetails::equals → TIMED_OUT
        if (this == o) return true;
76 2 1. equals : negated conditional → KILLED
2. equals : replaced boolean return with true for com/renomad/minum/web/PathDetails::equals → KILLED
        if (!(o instanceof PathDetails that)) return false;
77 4 1. equals : negated conditional → KILLED
2. equals : replaced boolean return with true for com/renomad/minum/web/PathDetails::equals → KILLED
3. equals : negated conditional → KILLED
4. equals : negated conditional → KILLED
        return Objects.equals(isolatedPath, that.isolatedPath) && Objects.equals(rawQueryString, that.rawQueryString) && Objects.equals(queryString, that.queryString);
78
    }
79
80
    @Override
81
    public int hashCode() {
82 1 1. hashCode : replaced int return with 0 for com/renomad/minum/web/PathDetails::hashCode → TIMED_OUT
        return Objects.hash(isolatedPath, rawQueryString, queryString);
83
    }
84
85
    @Override
86
    public String toString() {
87 1 1. toString : replaced return value with "" for com/renomad/minum/web/PathDetails::toString → KILLED
        return "PathDetails{" +
88
                "isolatedPath='" + isolatedPath + '\'' +
89
                ", rawQueryString='" + rawQueryString + '\'' +
90
                ", queryString=" + queryString +
91
                '}';
92
    }
93
}

Mutations

51

1.1
Location : getIsolatedPath
Killed by : none
replaced return value with "" for com/renomad/minum/web/PathDetails::getIsolatedPath → TIMED_OUT

59

1.1
Location : getRawQueryString
Killed by : com.renomad.minum.web.PathDetailsTests.happyPath(com.renomad.minum.web.PathDetailsTests)
replaced return value with "" for com/renomad/minum/web/PathDetails::getRawQueryString → KILLED

70

1.1
Location : getQueryString
Killed by : com.renomad.minum.web.EndpointTests.test_Endpoint_HappyPath(com.renomad.minum.web.EndpointTests)
replaced return value with Collections.emptyMap for com/renomad/minum/web/PathDetails::getQueryString → KILLED

75

1.1
Location : equals
Killed by : none
negated conditional → TIMED_OUT

2.2
Location : equals
Killed by : none
replaced boolean return with false for com/renomad/minum/web/PathDetails::equals → TIMED_OUT

76

1.1
Location : equals
Killed by : com.renomad.minum.web.WebTests
negated conditional → KILLED

2.2
Location : equals
Killed by : com.renomad.minum.EqualsTests.equalsTest(com.renomad.minum.EqualsTests)
replaced boolean return with true for com/renomad/minum/web/PathDetails::equals → KILLED

77

1.1
Location : equals
Killed by : com.renomad.minum.web.WebTests
negated conditional → KILLED

2.2
Location : equals
Killed by : com.renomad.minum.EqualsTests.equalsTest(com.renomad.minum.EqualsTests)
replaced boolean return with true for com/renomad/minum/web/PathDetails::equals → KILLED

3.3
Location : equals
Killed by : com.renomad.minum.web.WebTests
negated conditional → KILLED

4.4
Location : equals
Killed by : com.renomad.minum.web.WebTests
negated conditional → KILLED

82

1.1
Location : hashCode
Killed by : none
replaced int return with 0 for com/renomad/minum/web/PathDetails::hashCode → TIMED_OUT

87

1.1
Location : toString
Killed by : com.renomad.minum.web.RequestTests.test_Request_ToString(com.renomad.minum.web.RequestTests)
replaced return value with "" for com/renomad/minum/web/PathDetails::toString → KILLED

Active mutators

Tests examined


Report generated by PIT 1.17.0