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