From.java

1
package com.roxoft.lib;
2
3
import java.nio.charset.StandardCharsets;
4
import java.security.MessageDigest;
5
import java.security.NoSuchAlgorithmException;
6
7
public final class From {
8
    /** The value to be converted. */
9
    private final String value;
10
11
    private From(final String input) {
12
        this.value = input;
13
    }
14
15
    /**
16
     * @param input a value to perform a conversion on.
17
     * @return a new {@link From} object from which to do a conversion.
18
     */
19
    public static From string(final String input) {
20 1 1. string : replaced return value with null for com/roxoft/lib/From::string → KILLED
        return new From(input);
21
    }
22
23
    /**
24
     * @return An MD5 hashed {@link String} in hexadecimal.
25
     * @throws NoSuchAlgorithmException if MD5 cannot be used for any reason
26
     */
27
    public String toMD5Hex() throws NoSuchAlgorithmException {
28 1 1. toMD5Hex : replaced return value with "" for com/roxoft/lib/From::toMD5Hex → KILLED
        return toMD5Hex(16);
29
    }
30
31
    /**
32
     * @param hexCharacters number of hex characters to convert from the start. Max 16
33
     * @return An MD5 hashed {@link String} of the specified number of charactes in hexadecimal.
34
     * @throws NoSuchAlgorithmException if MD5 cannot be used for any reason
35
     */
36
    public String toMD5Hex(final int hexCharacters) throws NoSuchAlgorithmException {
37
        final int hexCharactersToGenerate = Math.min(hexCharacters, 16);
38
        final byte[] bytesOfMessage = value.getBytes(StandardCharsets.UTF_8);
39
        final MessageDigest md = MessageDigest.getInstance("MD5");
40
        final byte[] mD5digest = md.digest(bytesOfMessage);
41
        final StringBuilder hexStringBuilder = new StringBuilder();
42 2 1. toMD5Hex : negated conditional → KILLED
2. toMD5Hex : changed conditional boundary → KILLED
        for (int i = 0; i < hexCharactersToGenerate; i++) {
43
            hexStringBuilder.append(String.format("%02X", mD5digest[i]));
44
        }
45 1 1. toMD5Hex : replaced return value with "" for com/roxoft/lib/From::toMD5Hex → KILLED
        return hexStringBuilder.toString();
46
    }
47
}

Mutations

20

1.1
Location : string
Killed by : com.roxoft.lib.FromTest.[engine:junit-jupiter]/[class:com.roxoft.lib.FromTest]/[method:canBeCreated()]
replaced return value with null for com/roxoft/lib/From::string → KILLED

28

1.1
Location : toMD5Hex
Killed by : com.roxoft.lib.FromTest.[engine:junit-jupiter]/[class:com.roxoft.lib.FromTest]/[method:toMD5Hex()]
replaced return value with "" for com/roxoft/lib/From::toMD5Hex → KILLED

42

1.1
Location : toMD5Hex
Killed by : com.roxoft.lib.FromTest.[engine:junit-jupiter]/[class:com.roxoft.lib.FromTest]/[method:toSizeLimitedMD5HexInputRange()]
negated conditional → KILLED

2.2
Location : toMD5Hex
Killed by : com.roxoft.lib.FromTest.[engine:junit-jupiter]/[class:com.roxoft.lib.FromTest]/[method:toSizeLimitedMD5HexInputRange()]
changed conditional boundary → KILLED

45

1.1
Location : toMD5Hex
Killed by : com.roxoft.lib.FromTest.[engine:junit-jupiter]/[class:com.roxoft.lib.FromTest]/[method:toSizeLimitedMD5HexInputRange()]
replaced return value with "" for com/roxoft/lib/From::toMD5Hex → KILLED

Active mutators

Tests examined


Report generated by PIT 1.14.4