JsonUtils.java

1
package com.github.dakusui.symfonion.compat.json;
2
3
import com.google.gson.JsonArray;
4
import com.google.gson.JsonElement;
5
import com.google.gson.JsonObject;
6
import com.google.gson.JsonPrimitive;
7
8
import java.util.Optional;
9
10
import static com.github.valid8j.fluent.Expectations.require;
11
import static com.github.valid8j.fluent.Expectations.value;
12
13
/**
14
 * //@formatter:off
15
 * //@formatter:on
16
 */
17
public enum JsonUtils {
18
  ;
19
  private static final JsonElement DEFAULT_VALUE = new JsonArray();
20
  public static Path path(Object... path) {
21 1 1. path : replaced return value with null for com/github/dakusui/symfonion/compat/json/JsonUtils::path → KILLED
    return new Path(path);
22
  }
23
24
  public static Optional<JsonElement> findJsonElement(JsonElement base, Path path) {
25 1 1. findJsonElement : replaced return value with Optional.empty for com/github/dakusui/symfonion/compat/json/JsonUtils::findJsonElement → NO_COVERAGE
    return getJsonElement(JsonElement.class, base, path);
26
  }
27
28
  public static Optional<JsonObject> findJsonObject(JsonElement base, Path path) {
29 1 1. findJsonObject : replaced return value with Optional.empty for com/github/dakusui/symfonion/compat/json/JsonUtils::findJsonObject → NO_COVERAGE
    return getJsonElement(JsonObject.class, base, path);
30
  }
31
32
  public static Optional<JsonArray> findJsonArray(JsonElement base, Path path) {
33 1 1. findJsonArray : replaced return value with Optional.empty for com/github/dakusui/symfonion/compat/json/JsonUtils::findJsonArray → KILLED
    return getJsonElement(JsonArray.class, base, path);
34
  }
35
36
  public static Optional<JsonPrimitive> findJsonPrimitive(JsonPrimitive base, Path path) {
37 1 1. findJsonPrimitive : replaced return value with Optional.empty for com/github/dakusui/symfonion/compat/json/JsonUtils::findJsonPrimitive → NO_COVERAGE
    return getJsonElement(JsonPrimitive.class, base, path);
38
  }
39
40
  @SuppressWarnings("unchecked")
41
  private static <T extends JsonElement> Optional<T> getJsonElement(Class<T> jsonType, JsonElement base, Path path) {
42
    var ret = require(value(CompatJsonUtils.asJsonElementWithDefault(base, DEFAULT_VALUE, path.path())).toBe()
43
                                                                                                       .instanceOf(jsonType));
44 1 1. getJsonElement : negated conditional → KILLED
    return ret != DEFAULT_VALUE ? Optional.of((T) ret)
45
                                : Optional.empty();
46
  }
47
48
  public record Path(Object... path) {
49
  }
50
}

Mutations

21

1.1
Location : path
Killed by : com.github.dakusui.symfonion.tests.MidiCompilerTest.[engine:junit-jupiter]/[class:com.github.dakusui.symfonion.tests.MidiCompilerTest]/[test-template:exercise(com.github.dakusui.symfonion.testutils.SymfonionTestCase)]/[test-template-invocation:#2]
replaced return value with null for com/github/dakusui/symfonion/compat/json/JsonUtils::path → KILLED

25

1.1
Location : findJsonElement
Killed by : none
replaced return value with Optional.empty for com/github/dakusui/symfonion/compat/json/JsonUtils::findJsonElement → NO_COVERAGE

29

1.1
Location : findJsonObject
Killed by : none
replaced return value with Optional.empty for com/github/dakusui/symfonion/compat/json/JsonUtils::findJsonObject → NO_COVERAGE

33

1.1
Location : findJsonArray
Killed by : com.github.dakusui.symfonion.tests.MidiCompilerTest.[engine:junit-jupiter]/[class:com.github.dakusui.symfonion.tests.MidiCompilerTest]/[test-template:exercise(com.github.dakusui.symfonion.testutils.SymfonionTestCase)]/[test-template-invocation:#2]
replaced return value with Optional.empty for com/github/dakusui/symfonion/compat/json/JsonUtils::findJsonArray → KILLED

37

1.1
Location : findJsonPrimitive
Killed by : none
replaced return value with Optional.empty for com/github/dakusui/symfonion/compat/json/JsonUtils::findJsonPrimitive → NO_COVERAGE

44

1.1
Location : getJsonElement
Killed by : com.github.dakusui.symfonion.tests.MidiCompilerTest.[engine:junit-jupiter]/[class:com.github.dakusui.symfonion.tests.MidiCompilerTest]/[test-template:exercise(com.github.dakusui.symfonion.testutils.SymfonionTestCase)]/[test-template-invocation:#2]
negated conditional → KILLED

Active mutators

Tests examined


Report generated by PIT 1.19.1