MessageComposer.java

1
package com.github.valid8j.pcond.validator;
2
3
import com.github.valid8j.pcond.internals.InternalUtils;
4
5
import java.util.function.Predicate;
6
7
import static com.github.valid8j.pcond.internals.InternalUtils.formatObject;
8
import static java.lang.String.format;
9
10
/**
11
 * An interface that defines methods to compose a message when a value violates
12
 * a given condition based on a context.
13
 */
14
public interface MessageComposer {
15
  /**
16
   * Compose a message string for a `value`, which violates a precondition given as `predicate`.
17
   *
18
   * @param value     A value for which a message is created.
19
   * @param predicate A condition that a given `value` violated.
20
   * @param <T>       The type of the `value`.
21
   * @return A composed message string.
22
   */
23
  <T> String composeMessageForPrecondition(T value, Predicate<? super T> predicate);
24
25
  /**
26
   * Compose a message string for a `value`, which violates a postcondition given as `predicate`.
27
   *
28
   * @param value     A value for which a message is created.
29
   * @param predicate A condition that a given `value` violated.
30
   * @param <T>       The type of the `value`.
31
   * @return A composed message string.
32
   */
33
  <T> String composeMessageForPostcondition(T value, Predicate<? super T> predicate);
34
35
  /**
36
   * Compose a message string for a `value`, which violates a general condition given as `predicate`.
37
   * Used for invariant conditions, test assertion (`assertThat`), and test prerequisition
38
   * checking (`assumeThat`).
39
   *
40
   * @param value     A value for which a message is created.
41
   * @param predicate A condition that a given `value` violated.
42
   * @param <T>       The type of the `value`.
43
   * @return A composed message string.
44
   */
45
  <T> String composeMessageForAssertion(T value, Predicate<? super T> predicate);
46
47
  /**
48
   * Compose a message string for a `value`, which violates a user input checking
49
   * condition given as `predicate`.
50
   *
51
   * @param value     A value for which a message is created.
52
   * @param predicate A condition that a given `value` violated.
53
   * @param <T>       The type of the `value`.
54
   * @return A composed message string.
55
   */
56
  <T> String composeMessageForValidation(T value, Predicate<? super T> predicate);
57
58
  /**
59
   * A default implementation of `MessageComposer`.
60
   */
61
  class Default implements MessageComposer {
62
    @Override
63
    public <T> String composeMessageForPrecondition(T value, Predicate<? super T> predicate) {
64 1 1. composeMessageForPrecondition : replaced return value with "" for com/github/valid8j/pcond/validator/MessageComposer$Default::composeMessageForPrecondition → KILLED
      return String.format("value:<%s> violated precondition:value %s", InternalUtils.formatObject(value), predicate);
65
    }
66
67
    @Override
68
    public <T> String composeMessageForPostcondition(T value, Predicate<? super T> predicate) {
69 1 1. composeMessageForPostcondition : replaced return value with "" for com/github/valid8j/pcond/validator/MessageComposer$Default::composeMessageForPostcondition → KILLED
      return String.format("value:<%s> violated postcondition:value %s", InternalUtils.formatObject(value), predicate);
70
    }
71
72
    @Override
73
    public <T> String composeMessageForAssertion(T value, Predicate<? super T> predicate) {
74 1 1. composeMessageForAssertion : replaced return value with "" for com/github/valid8j/pcond/validator/MessageComposer$Default::composeMessageForAssertion → KILLED
      return "Value:" + InternalUtils.formatObject(value) + " violated: " + predicate.toString();
75
    }
76
77
    @Override
78
    public <T> String composeMessageForValidation(T value, Predicate<? super T> predicate) {
79 1 1. composeMessageForValidation : replaced return value with "" for com/github/valid8j/pcond/validator/MessageComposer$Default::composeMessageForValidation → KILLED
      return "Value:" + InternalUtils.formatObject(value) + " violated: " + predicate.toString();
80
    }
81
  }
82
}

Mutations

64

1.1
Location : composeMessageForPrecondition
Killed by : com.github.valid8j.ut.valuechecker.DefaultValidatorTest.withoutEvaluator_conj_thenFail(com.github.valid8j.ut.valuechecker.DefaultValidatorTest)
replaced return value with "" for com/github/valid8j/pcond/validator/MessageComposer$Default::composeMessageForPrecondition → KILLED

69

1.1
Location : composeMessageForPostcondition
Killed by : com.github.valid8j.entrypoints.EnsuresTest.testEnsureNonNull(com.github.valid8j.entrypoints.EnsuresTest)
replaced return value with "" for com/github/valid8j/pcond/validator/MessageComposer$Default::composeMessageForPostcondition → KILLED

74

1.1
Location : composeMessageForAssertion
Killed by : com.github.valid8j.entrypoints.AssertionsTest$MessageTest.composeMessage$thenComposed(com.github.valid8j.entrypoints.AssertionsTest$MessageTest)
replaced return value with "" for com/github/valid8j/pcond/validator/MessageComposer$Default::composeMessageForAssertion → KILLED

79

1.1
Location : composeMessageForValidation
Killed by : com.github.valid8j.entrypoints.ValidatesTest.testValidateMethod$failing(com.github.valid8j.entrypoints.ValidatesTest)
replaced return value with "" for com/github/valid8j/pcond/validator/MessageComposer$Default::composeMessageForValidation → KILLED

Active mutators

Tests examined


Report generated by PIT 1.7.3