MethodQuery.java

1
package com.github.valid8j.pcond.core.refl;
2
3
import com.github.valid8j.pcond.internals.InternalChecks;
4
5
import java.util.Arrays;
6
import java.util.Objects;
7
import java.util.function.Function;
8
import java.util.function.Predicate;
9
10
import static com.github.valid8j.pcond.core.refl.ReflUtils.replacePlaceHolderWithActualArgument;
11
import static java.lang.String.format;
12
import static java.util.Objects.requireNonNull;
13
import static java.util.stream.Collectors.joining;
14
15
/**
16
 * An interface that models a query to specify a method.
17
 */
18
public interface MethodQuery {
19
  boolean isStatic();
20
21
  Object targetObject();
22
23
  Class<?> targetClass();
24
25
  String methodName();
26
27
  Object[] arguments();
28
29
  /**
30
   * Returns a string that describes this object.
31
   *
32
   * @return A description of this object.
33
   */
34
  String describe();
35
36
  default MethodQuery bindActualArguments(Predicate<Object> isPlaceHolder, Function<Object, Object> replace) {
37 1 1. lambda$bindActualArguments$0 : replaced return value with null for com/github/valid8j/pcond/core/refl/MethodQuery::lambda$bindActualArguments$0 → KILLED
    Function<Object, Object> argReplacer = object -> replacePlaceHolderWithActualArgument(object, isPlaceHolder, replace);
38
    Object targetObject = argReplacer.apply(this.targetObject());
39 1 1. bindActualArguments : replaced return value with null for com/github/valid8j/pcond/core/refl/MethodQuery::bindActualArguments → KILLED
    return create(
40
        this.isStatic(),
41
        targetObject,
42 1 1. bindActualArguments : negated conditional → KILLED
        this.isStatic() ? this.targetClass() : targetObject.getClass(),
43
        this.methodName(),
44
        Arrays.stream(this.arguments()).map(argReplacer).toArray());
45
  }
46
47
  static MethodQuery instanceMethod(Object targetObject, String methodName, Object... arguments) {
48 1 1. instanceMethod : replaced return value with null for com/github/valid8j/pcond/core/refl/MethodQuery::instanceMethod → KILLED
    return create(false, requireNonNull(targetObject), ReflUtils.targetTypeOf(targetObject), methodName, arguments);
49
  }
50
51
  /**
52
   * Create a `MethodQuery` object to search matching static methods.
53
   *
54
   * @param targetClass A class from which a method is searched.
55
   * @param methodName  A name of a method to be searched.
56
   * @param arguments   Argument values;
57
   * @return A `MethodQuery` object.
58
   */
59
  static MethodQuery classMethod(Class<?> targetClass, String methodName, Object... arguments) {
60 1 1. classMethod : replaced return value with null for com/github/valid8j/pcond/core/refl/MethodQuery::classMethod → KILLED
    return create(true, null, targetClass, methodName, arguments);
61
  }
62
63
  static MethodQuery create(boolean isStatic, Object targetObject, Class<?> targetClass, String methodName, Object[] arguments) {
64
    requireNonNull(targetClass);
65
    requireNonNull(arguments);
66
    requireNonNull(methodName);
67 1 1. create : negated conditional → KILLED
    if (isStatic)
68 1 1. lambda$create$1 : replaced return value with "" for com/github/valid8j/pcond/core/refl/MethodQuery::lambda$create$1 → NO_COVERAGE
      InternalChecks.requireArgument(targetObject, Objects::isNull, () -> "targetObject must be null when isStatic is true.");
69
    else {
70
      requireNonNull(targetObject);
71 3 1. lambda$create$2 : replaced boolean return with true for com/github/valid8j/pcond/core/refl/MethodQuery::lambda$create$2 → SURVIVED
2. lambda$create$3 : replaced return value with "" for com/github/valid8j/pcond/core/refl/MethodQuery::lambda$create$3 → NO_COVERAGE
3. lambda$create$2 : replaced boolean return with false for com/github/valid8j/pcond/core/refl/MethodQuery::lambda$create$2 → KILLED
      InternalChecks.requireArgument(targetObject, v -> targetClass.isAssignableFrom(v.getClass()), () -> format("Incompatible object '%s' was given it needs to be assignable to '%s'.", targetObject, targetClass.getName()));
72
    }
73
74 1 1. create : replaced return value with null for com/github/valid8j/pcond/core/refl/MethodQuery::create → KILLED
    return new MethodQuery() {
75
      @Override
76
      public boolean isStatic() {
77 2 1. isStatic : replaced boolean return with false for com/github/valid8j/pcond/core/refl/MethodQuery$1::isStatic → KILLED
2. isStatic : replaced boolean return with true for com/github/valid8j/pcond/core/refl/MethodQuery$1::isStatic → KILLED
        return isStatic;
78
      }
79
80
      @Override
81
      public Object targetObject() {
82 1 1. targetObject : replaced return value with null for com/github/valid8j/pcond/core/refl/MethodQuery$1::targetObject → KILLED
        return targetObject;
83
      }
84
85
      @Override
86
      public String methodName() {
87 1 1. methodName : replaced return value with "" for com/github/valid8j/pcond/core/refl/MethodQuery$1::methodName → KILLED
        return methodName;
88
      }
89
90
      @Override
91
      public Class<?> targetClass() {
92 1 1. targetClass : replaced return value with null for com/github/valid8j/pcond/core/refl/MethodQuery$1::targetClass → KILLED
        return targetClass;
93
      }
94
95
      @Override
96
      public Object[] arguments() {
97 1 1. arguments : replaced return value with null for com/github/valid8j/pcond/core/refl/MethodQuery$1::arguments → KILLED
        return arguments;
98
      }
99
100
      @Override
101
      public String describe() {
102 1 1. lambda$describe$0 : replaced return value with "" for com/github/valid8j/pcond/core/refl/MethodQuery$1::lambda$describe$0 → KILLED
        Function<Object, String> parameterFormatter = s -> "<" + s + ">";
103 2 1. describe : negated conditional → KILLED
2. describe : replaced return value with "" for com/github/valid8j/pcond/core/refl/MethodQuery$1::describe → KILLED
        return format("%s.%s(%s)",
104
            isStatic ?
105
                targetClass.getName() :
106
                parameterFormatter.apply(targetObject),
107
            methodName,
108
            Arrays.stream(arguments)
109
                .map(parameterFormatter)
110
                .collect(joining(",")));
111
      }
112
    };
113
  }
114
}

Mutations

37

1.1
Location : lambda$bindActualArguments$0
Killed by : com.github.valid8j.ut.internal.CallTest.methodIncompatible(com.github.valid8j.ut.internal.CallTest)
replaced return value with null for com/github/valid8j/pcond/core/refl/MethodQuery::lambda$bindActualArguments$0 → KILLED

39

1.1
Location : bindActualArguments
Killed by : com.github.valid8j.ut.internal.CallTest.methodIncompatible(com.github.valid8j.ut.internal.CallTest)
replaced return value with null for com/github/valid8j/pcond/core/refl/MethodQuery::bindActualArguments → KILLED

42

1.1
Location : bindActualArguments
Killed by : com.github.valid8j.ut.internal.CallTest.exceptionThrowingMethod(com.github.valid8j.ut.internal.CallTest)
negated conditional → KILLED

48

1.1
Location : instanceMethod
Killed by : com.github.valid8j.ut.internal.CallTest.methodIncompatible(com.github.valid8j.ut.internal.CallTest)
replaced return value with null for com/github/valid8j/pcond/core/refl/MethodQuery::instanceMethod → KILLED

60

1.1
Location : classMethod
Killed by : com.github.valid8j.ut.internal.CallTest.classMethodCaBeCalled(com.github.valid8j.ut.internal.CallTest)
replaced return value with null for com/github/valid8j/pcond/core/refl/MethodQuery::classMethod → KILLED

67

1.1
Location : create
Killed by : com.github.valid8j.ut.internal.CallTest.methodIncompatible(com.github.valid8j.ut.internal.CallTest)
negated conditional → KILLED

68

1.1
Location : lambda$create$1
Killed by : none
replaced return value with "" for com/github/valid8j/pcond/core/refl/MethodQuery::lambda$create$1 → NO_COVERAGE

71

1.1
Location : lambda$create$2
Killed by : com.github.valid8j.ut.internal.CallTest.methodIncompatible(com.github.valid8j.ut.internal.CallTest)
replaced boolean return with false for com/github/valid8j/pcond/core/refl/MethodQuery::lambda$create$2 → KILLED

2.2
Location : lambda$create$2
Killed by : none
replaced boolean return with true for com/github/valid8j/pcond/core/refl/MethodQuery::lambda$create$2 → SURVIVED

3.3
Location : lambda$create$3
Killed by : none
replaced return value with "" for com/github/valid8j/pcond/core/refl/MethodQuery::lambda$create$3 → NO_COVERAGE

74

1.1
Location : create
Killed by : com.github.valid8j.ut.internal.CallTest.methodIncompatible(com.github.valid8j.ut.internal.CallTest)
replaced return value with null for com/github/valid8j/pcond/core/refl/MethodQuery::create → KILLED

77

1.1
Location : isStatic
Killed by : com.github.valid8j.ut.internal.CallTest.classMethodCaBeCalled(com.github.valid8j.ut.internal.CallTest)
replaced boolean return with false for com/github/valid8j/pcond/core/refl/MethodQuery$1::isStatic → KILLED

2.2
Location : isStatic
Killed by : com.github.valid8j.ut.internal.CallTest.methodIncompatible(com.github.valid8j.ut.internal.CallTest)
replaced boolean return with true for com/github/valid8j/pcond/core/refl/MethodQuery$1::isStatic → KILLED

82

1.1
Location : targetObject
Killed by : com.github.valid8j.ut.internal.CallTest.methodIncompatible(com.github.valid8j.ut.internal.CallTest)
replaced return value with null for com/github/valid8j/pcond/core/refl/MethodQuery$1::targetObject → KILLED

87

1.1
Location : methodName
Killed by : com.github.valid8j.ut.internal.CallTest.methodIncompatible(com.github.valid8j.ut.internal.CallTest)
replaced return value with "" for com/github/valid8j/pcond/core/refl/MethodQuery$1::methodName → KILLED

92

1.1
Location : targetClass
Killed by : com.github.valid8j.ut.internal.CallTest.methodIncompatible(com.github.valid8j.ut.internal.CallTest)
replaced return value with null for com/github/valid8j/pcond/core/refl/MethodQuery$1::targetClass → KILLED

97

1.1
Location : arguments
Killed by : com.github.valid8j.ut.internal.CallTest.methodIncompatible(com.github.valid8j.ut.internal.CallTest)
replaced return value with null for com/github/valid8j/pcond/core/refl/MethodQuery$1::arguments → KILLED

102

1.1
Location : lambda$describe$0
Killed by : com.github.valid8j.ut.internal.CallTest.instanceMethodCanBeCalled(com.github.valid8j.ut.internal.CallTest)
replaced return value with "" for com/github/valid8j/pcond/core/refl/MethodQuery$1::lambda$describe$0 → KILLED

103

1.1
Location : describe
Killed by : com.github.valid8j.ut.internal.CallTest.instanceMethodCanBeCalled(com.github.valid8j.ut.internal.CallTest)
negated conditional → KILLED

2.2
Location : describe
Killed by : com.github.valid8j.ut.internal.CallTest.instanceMethodCanBeCalled(com.github.valid8j.ut.internal.CallTest)
replaced return value with "" for com/github/valid8j/pcond/core/refl/MethodQuery$1::describe → KILLED

Active mutators

Tests examined


Report generated by PIT 1.7.3