1 | package com.github.dakusui.pcond.validator; | |
2 | ||
3 | import com.github.dakusui.pcond.core.*; | |
4 | import com.github.dakusui.pcond.forms.Predicates; | |
5 | ||
6 | import java.io.IOException; | |
7 | import java.io.InputStream; | |
8 | import java.util.List; | |
9 | import java.util.Objects; | |
10 | import java.util.Optional; | |
11 | import java.util.Properties; | |
12 | import java.util.function.BiFunction; | |
13 | import java.util.function.Consumer; | |
14 | import java.util.function.Function; | |
15 | import java.util.function.Predicate; | |
16 | ||
17 | import static com.github.dakusui.pcond.internals.InternalUtils.toEvaluableIfNecessary; | |
18 | import static com.github.dakusui.pcond.validator.Validator.Configuration.Utils.*; | |
19 | import static java.lang.String.format; | |
20 | import static java.util.Collections.emptyList; | |
21 | ||
22 | /** | |
23 | * An interface of a policy for behaviours on 'contract violations'. | |
24 | */ | |
25 | public interface Validator { | |
26 | /** | |
27 | * A constant field that holds the default provider instance. | |
28 | */ | |
29 |
1
1. lambda$static$0 : replaced return value with null for com/github/dakusui/pcond/validator/Validator::lambda$static$0 → SURVIVED |
ThreadLocal<Validator> INSTANCE = ThreadLocal.withInitial(() -> create(loadPcondProperties())); |
30 | ||
31 | ||
32 | /** | |
33 | * Returns a configuration object that determines behaviors of this object. | |
34 | * | |
35 | * @return A configuration object. | |
36 | */ | |
37 | Configuration configuration(); | |
38 | ||
39 | /** | |
40 | * Returns a provider instance created from a given `Properties` object. | |
41 | * This method reads the value for the FQCN of this class (`com.github.dakusui.pcond.provider.AssertionProvider`) and creates an instance of a class specified by the value. | |
42 | * If the value is not set, this value instantiates an object of `DefaultAssertionProvider` and returns it. | |
43 | * | |
44 | * @param properties A {@code Properties} object from which an {@code AssertionProvider} is created | |
45 | * @return Created provider instance. | |
46 | */ | |
47 | static Validator create(Properties properties) { | |
48 |
1
1. create : replaced return value with null for com/github/dakusui/pcond/validator/Validator::create → SURVIVED |
return new Impl(configurationFromProperties(properties)); |
49 | } | |
50 | ||
51 | /** | |
52 | * Checks a value if it is {@code null} or not. | |
53 | * If it is not a {@code null}, this method returns the given value itself. | |
54 | * | |
55 | * @param value The given value. | |
56 | * @param <T> The type of the value. | |
57 | * @return The {@code value}. | |
58 | */ | |
59 | default <T> T requireNonNull(T value) { | |
60 |
1
1. requireNonNull : replaced return value with null for com/github/dakusui/pcond/validator/Validator::requireNonNull → KILLED |
return require(value, Predicates.isNotNull(), configuration().exceptionComposer().forRequire()::exceptionForNonNullViolation); |
61 | } | |
62 | ||
63 | /** | |
64 | * Checks a value if it meets a requirement specified by {@code cond}. | |
65 | * If it does, the value itself will be returned. | |
66 | * | |
67 | * @param value The value to be checked. | |
68 | * @param cond The requirement to check the {@code value}. | |
69 | * @param <T> The type of the value. | |
70 | * @return The value. | |
71 | */ | |
72 | default <T> T requireArgument(T value, Predicate<? super T> cond) { | |
73 |
1
1. requireArgument : replaced return value with null for com/github/dakusui/pcond/validator/Validator::requireArgument → KILLED |
return require(value, cond, configuration().exceptionComposer().forRequire()::exceptionForIllegalArgument); |
74 | } | |
75 | ||
76 | /** | |
77 | * Checks a value if it meets a requirement specified by {@code cond}. | |
78 | * If it does, the value itself will be returned. | |
79 | * | |
80 | * @param value The value to be checked. | |
81 | * @param cond The requirement to check the {@code value}. | |
82 | * @param <T> The type of the value. | |
83 | * @return The value. | |
84 | */ | |
85 | default <T> T requireState(T value, Predicate<? super T> cond) { | |
86 |
1
1. requireState : replaced return value with null for com/github/dakusui/pcond/validator/Validator::requireState → KILLED |
return require(value, cond, configuration().exceptionComposer().forRequire()::exceptionForIllegalState); |
87 | } | |
88 | ||
89 | /** | |
90 | * A method to check if a given `value` satisfies a precondition given as `cond`. | |
91 | * If the `cond` is satisfied, the `value` itself will be returned. | |
92 | * Otherwise, an exception returned by `configuration().exceptionComposer().forRequire().exceptionForGeneralViolation(String)` | |
93 | * will be thrown. | |
94 | * | |
95 | * @param value A value to be checked. | |
96 | * @param cond A condition to check if `value` satisfies. | |
97 | * @param <T> The of the `value`. | |
98 | * @return The `value`, if `cond` is satisfied. | |
99 | */ | |
100 | default <T> T require(T value, Predicate<? super T> cond) { | |
101 |
2
1. lambda$require$1 : replaced return value with null for com/github/dakusui/pcond/validator/Validator::lambda$require$1 → KILLED 2. require : replaced return value with null for com/github/dakusui/pcond/validator/Validator::require → KILLED |
return require(value, cond, msg -> configuration().exceptionComposer().forRequire().exceptionForGeneralViolation(msg)); |
102 | } | |
103 | ||
104 | /** | |
105 | * A method to check if a given `value` satisfies a precondition given as `cond`. | |
106 | * If the `cond` is satisfied, the `value` itself will be returned. | |
107 | * Otherwise, an exception created by `exceptionFactory` is thrown. | |
108 | * | |
109 | * @param value A value to be checked. | |
110 | * @param cond A condition to check if `value` satisfies. | |
111 | * @param exceptionFactory A function to create an exception thrown when `cond` | |
112 | * is not satisfied by `value`. | |
113 | * @param <T> The of the `value`. | |
114 | * @return The `value`, if `cond` is satisfied. | |
115 | */ | |
116 | default <T> T require(T value, Predicate<? super T> cond, Function<String, Throwable> exceptionFactory) { | |
117 |
1
1. require : replaced return value with null for com/github/dakusui/pcond/validator/Validator::require → KILLED |
return checkValueAndThrowIfFails( |
118 | value, | |
119 | cond, | |
120 | this.configuration().messageComposer()::composeMessageForPrecondition, | |
121 |
1
1. lambda$require$2 : replaced return value with null for com/github/dakusui/pcond/validator/Validator::lambda$require$2 → KILLED |
explanation -> exceptionFactory.apply(explanation.toString())); |
122 | } | |
123 | ||
124 | /** | |
125 | * Validates the given `value`. | |
126 | * If the value satisfies a condition `cond`, the value itself will be returned. | |
127 | * Otherwise, an exception created by `forValidate.exceptionForGeneralViolation()` | |
128 | * will be thrown. | |
129 | * This method is intended to be used by {@code Validates#validate(Object, Predicate, Function)} | |
130 | * method in `valid8j` library. | |
131 | * | |
132 | * @param value The value to be checked. | |
133 | * @param cond A condition to validate the `value`. | |
134 | * @param forValidate An exception composer for "validate" methods. | |
135 | * @param <T> The type of the value. | |
136 | * @return The value itself. | |
137 | */ | |
138 | default <T> T validate(T value, Predicate<? super T> cond, ExceptionComposer.ForValidate forValidate) { | |
139 |
1
1. validate : replaced return value with null for com/github/dakusui/pcond/validator/Validator::validate → SURVIVED |
return validate(value, cond, forValidate::exceptionForGeneralViolation); |
140 | } | |
141 | ||
142 | /** | |
143 | * Validates the given `value`. | |
144 | * If the value is not `null`, the value itself will be returned. | |
145 | * Otherwise, an exception created by `forValidate.exceptionForGeneralViolation()` | |
146 | * will be thrown. | |
147 | * This method is intended to be used by {@code Validates#validateNonNull(Object)} | |
148 | * method in valid8j library. | |
149 | * | |
150 | * @param value The value to be checked. | |
151 | * @param forValidate An exception composer for "validate" methods. | |
152 | * @param <T> The type of the value. | |
153 | * @return The value itself. | |
154 | */ | |
155 | default <T> T validateNonNull(T value, ExceptionComposer.ForValidate forValidate) { | |
156 |
1
1. validateNonNull : replaced return value with null for com/github/dakusui/pcond/validator/Validator::validateNonNull → SURVIVED |
return validate(value, Predicates.isNotNull(), forValidate::exceptionForNonNullViolation); |
157 | } | |
158 | ||
159 | /** | |
160 | * Validates the given argument variable `value`. | |
161 | * If the value satisfies a condition `cond` for checking an argument variable, the value itself will be returned. | |
162 | * Otherwise, an exception created by `forValidate.exceptionForIllegalArgument()` | |
163 | * will be thrown. | |
164 | * This method is intended to be used by {@code Validates#validateArgument(Object, Predicate)} | |
165 | * method in `valid8j` library. | |
166 | * | |
167 | * @param value The value to be checked. | |
168 | * @param cond A condition to validate the `value`. | |
169 | * @param forValidate An exception composer for "validate" methods. | |
170 | * @param <T> The type of the value. | |
171 | * @return The value itself. | |
172 | */ | |
173 | default <T> T validateArgument(T value, Predicate<? super T> cond, ExceptionComposer.ForValidate forValidate) { | |
174 |
1
1. validateArgument : replaced return value with null for com/github/dakusui/pcond/validator/Validator::validateArgument → SURVIVED |
return validate(value, cond, forValidate::exceptionForIllegalArgument); |
175 | } | |
176 | ||
177 | /** | |
178 | * Validates the given state variable `value`. | |
179 | * If the value satisfies a condition `cond` for checking a state, the value itself will be returned. | |
180 | * Otherwise, an exception created by `forValidate.exceptionForIllegalState()` | |
181 | * will be thrown. | |
182 | * This method is intended to be used by {@code Validates#validateState(Object, Predicate)} | |
183 | * method in valid8j library. | |
184 | * | |
185 | * @param value The value to be checked. | |
186 | * @param cond A condition to validate the `value`. | |
187 | * @param forValidate An exception composer for "validate" methods. | |
188 | * @param <T> The type of the value. | |
189 | * @return The value itself. | |
190 | */ | |
191 | default <T> T validateState(T value, Predicate<? super T> cond, ExceptionComposer.ForValidate forValidate) { | |
192 |
1
1. validateState : replaced return value with null for com/github/dakusui/pcond/validator/Validator::validateState → SURVIVED |
return validate(value, cond, forValidate::exceptionForIllegalState); |
193 | } | |
194 | ||
195 | /** | |
196 | * Validates the given variable `value`. | |
197 | * If the value satisfies a condition `cond`, the value itself will be returned. | |
198 | * Otherwise, an exception created by `exceptionFactory` will be thrown. | |
199 | * This method is intended to be used by {@code Validates#validate(Object, Predicate, Function)} | |
200 | * method in valid8j library. | |
201 | * | |
202 | * @param value The value to be checked. | |
203 | * @param cond A condition to validate the `value`. | |
204 | * @param exceptionFactory A function to create an exception when the `cond` is not satisfied. | |
205 | * @param <T> The type of the value. | |
206 | * @return The value itself. | |
207 | */ | |
208 | default <T> T validate(T value, Predicate<? super T> cond, Function<String, Throwable> exceptionFactory) { | |
209 |
2
1. lambda$validate$3 : replaced return value with null for com/github/dakusui/pcond/validator/Validator::lambda$validate$3 → KILLED 2. validate : replaced return value with null for com/github/dakusui/pcond/validator/Validator::validate → KILLED |
return validate_2(value, cond, explanation -> exceptionFactory.apply(explanation.toString())); |
210 | } | |
211 | ||
212 | default <T> T validate_2(T value, Predicate<? super T> cond, ExceptionFactory<Throwable> exceptionFactory) { | |
213 |
1
1. validate_2 : replaced return value with null for com/github/dakusui/pcond/validator/Validator::validate_2 → KILLED |
return checkValueAndThrowIfFails( |
214 | value, | |
215 | cond, | |
216 | configuration().messageComposer()::composeMessageForValidation, | |
217 | exceptionFactory); | |
218 | } | |
219 | ||
220 | /** | |
221 | * Checks a value if it is not `null`. | |
222 | * If it is not `null`, the value itself will be returned. | |
223 | * If it is, an exception created by `configuration().exceptionComposer().forEnsure().exceptionForNonNullViolation()` will be thrown. | |
224 | * This method is intended for ensuring a "post-condition". | |
225 | * | |
226 | * @param value The value to be checked. | |
227 | * @param <T> The type of the value. | |
228 | * @return The value. | |
229 | */ | |
230 | default <T> T ensureNonNull(T value) { | |
231 |
1
1. ensureNonNull : replaced return value with null for com/github/dakusui/pcond/validator/Validator::ensureNonNull → KILLED |
return ensure(value, Predicates.isNotNull(), configuration().exceptionComposer().forEnsure()::exceptionForNonNullViolation); |
232 | } | |
233 | ||
234 | /** | |
235 | * Checks a value if it meets a requirement specified by {@code cond}. | |
236 | * If it does, the value itself will be returned. | |
237 | * If it does not, an exception created by `configuration().exceptionComposer().forEnsure().exceptionForIllegalState()` will be thrown. | |
238 | * This method is intended for ensuring a "post-condition" of a state. | |
239 | * | |
240 | * @param value The value to be checked. | |
241 | * @param cond The requirement to check the {@code value}. | |
242 | * @param <T> The type of the value. | |
243 | * @return The value. | |
244 | */ | |
245 | default <T> T ensureState(T value, Predicate<? super T> cond) { | |
246 |
1
1. ensureState : replaced return value with null for com/github/dakusui/pcond/validator/Validator::ensureState → KILLED |
return ensure(value, cond, configuration().exceptionComposer().forEnsure()::exceptionForIllegalState); |
247 | } | |
248 | ||
249 | /** | |
250 | * Checks a value if it meets a requirement specified by {@code cond}. | |
251 | * If it does, the value itself will be returned. | |
252 | * If it does not, an exception created by `configuration().exceptionComposer().forEnsure().exceptionForGeneralViolation()` will be thrown. | |
253 | * This method is intended for ensuring a "post-condition". | |
254 | * | |
255 | * @param value The value to be checked. | |
256 | * @param cond The requirement to check the {@code value}. | |
257 | * @param <T> The type of the value. | |
258 | * @return The value. | |
259 | */ | |
260 | default <T> T ensure(T value, Predicate<? super T> cond) { | |
261 |
2
1. ensure : replaced return value with null for com/github/dakusui/pcond/validator/Validator::ensure → KILLED 2. lambda$ensure$4 : replaced return value with null for com/github/dakusui/pcond/validator/Validator::lambda$ensure$4 → KILLED |
return ensure(value, cond, msg -> configuration().exceptionComposer().forEnsure().exceptionForGeneralViolation(msg)); |
262 | } | |
263 | ||
264 | /** | |
265 | * Checks a value if it meets a requirement specified by {@code cond}. | |
266 | * If it does, the value itself will be returned. | |
267 | * If it does not, an exception created by `exceptionComposer` will be thrown. | |
268 | * This method is intended for ensuring a "post-condition". | |
269 | * | |
270 | * @param value The value to be checked. | |
271 | * @param cond The requirement to check the {@code value}. | |
272 | * @param exceptionComposer A function to create an exception to be thrown when | |
273 | * `cond` is not met. | |
274 | * @param <T> The type of the value. | |
275 | * @return The value. | |
276 | */ | |
277 | default <T> T ensure(T value, Predicate<? super T> cond, Function<String, Throwable> exceptionComposer) { | |
278 |
1
1. ensure : replaced return value with null for com/github/dakusui/pcond/validator/Validator::ensure → KILLED |
return checkValueAndThrowIfFails( |
279 | value, | |
280 | cond, | |
281 | configuration().messageComposer()::composeMessageForPostcondition, | |
282 |
1
1. lambda$ensure$5 : replaced return value with null for com/github/dakusui/pcond/validator/Validator::lambda$ensure$5 → KILLED |
explanation -> exceptionComposer.apply(explanation.toString())); |
283 | } | |
284 | ||
285 | /** | |
286 | * A method to check if a `value` satisfies a predicate `cond`. | |
287 | * | |
288 | * This method is intended to be used by {@code Assertions#that(Object, Predicate)} in valid8j library. | |
289 | * If the condition is not satisfied, an exception created by `this.exceptionComposer().forAssert().exceptionInvariantConditionViolation()` | |
290 | * method will be thrown. | |
291 | * | |
292 | * @param value A value to be checked. | |
293 | * @param cond A condition to check the `value`. | |
294 | * @param <T> The type of `value`. | |
295 | */ | |
296 | default <T> void checkInvariant(T value, Predicate<? super T> cond) { | |
297 | checkValueAndThrowIfFails( | |
298 | value, | |
299 | cond, | |
300 | configuration().messageComposer()::composeMessageForAssertion, | |
301 |
1
1. lambda$checkInvariant$6 : replaced return value with null for com/github/dakusui/pcond/validator/Validator::lambda$checkInvariant$6 → KILLED |
explanation -> configuration().exceptionComposer().forAssert().exceptionInvariantConditionViolation(explanation.toString())); |
302 | } | |
303 | ||
304 | /** | |
305 | * A method to check if a `value` satisfies a predicate `cond`. | |
306 | * | |
307 | * This method is intended to be used by {@code Assertions#precondition(Object, Predicate)} in valid8j library. | |
308 | * If the condition is not satisfied, an exception created by `this.exceptionComposer().forAssert().exceptionPreconditionViolation()` | |
309 | * method will be thrown. | |
310 | * | |
311 | * @param value A value to be checked. | |
312 | * @param cond A condition to check the `value`. | |
313 | * @param <T> The type of `value`. | |
314 | */ | |
315 | default <T> void checkPrecondition(T value, Predicate<? super T> cond) { | |
316 | checkValueAndThrowIfFails( | |
317 | value, | |
318 | cond, | |
319 | configuration().messageComposer()::composeMessageForPrecondition, | |
320 |
1
1. lambda$checkPrecondition$7 : replaced return value with null for com/github/dakusui/pcond/validator/Validator::lambda$checkPrecondition$7 → KILLED |
explanation -> configuration().exceptionComposer().forAssert().exceptionPreconditionViolation(explanation.toString())); |
321 | } | |
322 | ||
323 | /** | |
324 | * A method to check if a `value` satisfies a predicate `cond`. | |
325 | * | |
326 | * This method is intended to be used by {@code Assertions#postcondition(Object, Predicate)} in valid8j library. | |
327 | * If the condition is not satisfied, an exception created by `this.exceptionComposer().forAssert().exceptionPostconditionViolation()` | |
328 | * method will be thrown. | |
329 | * | |
330 | * @param value A value to be checked. | |
331 | * @param cond A condition to check the `value`. | |
332 | * @param <T> The type of `value`. | |
333 | */ | |
334 | default <T> void checkPostcondition(T value, Predicate<? super T> cond) { | |
335 | checkValueAndThrowIfFails( | |
336 | value, | |
337 | cond, | |
338 | configuration().messageComposer()::composeMessageForPostcondition, | |
339 |
1
1. lambda$checkPostcondition$8 : replaced return value with null for com/github/dakusui/pcond/validator/Validator::lambda$checkPostcondition$8 → KILLED |
explanation -> configuration().exceptionComposer().forAssert().exceptionPostconditionViolation(explanation.toString())); |
340 | } | |
341 | ||
342 | /** | |
343 | * Executes a test assertion for a given `value` using a predicate `cond`. | |
344 | * If the `cond` is not satisfied by the `value`, an exception created by `configuration().messageComposer().composeMessageForAssertion()` | |
345 | * will be thrown. | |
346 | * | |
347 | * @param value A value to be checked. | |
348 | * @param cond A predicate to check a given `value`. | |
349 | * @param <T> The type of the `value`. | |
350 | */ | |
351 | default <T> void assertThat(T value, Predicate<? super T> cond) { | |
352 | checkValueAndThrowIfFails( | |
353 | value, | |
354 | cond, | |
355 | configuration().messageComposer()::composeMessageForAssertion, | |
356 |
1
1. lambda$assertThat$9 : replaced return value with null for com/github/dakusui/pcond/validator/Validator::lambda$assertThat$9 → NO_COVERAGE |
explanation -> configuration().exceptionComposer().forAssertThat().testFailedException(explanation, configuration().reportComposer())); |
357 | } | |
358 | ||
359 | /** | |
360 | * Executes a test assumption check for a given `value` using a predicate `cond`. | |
361 | * If the `cond` is not satisfied by the `value`, an exception created by `configuration().messageComposer().composeMessageForAssertion()` | |
362 | * will be thrown. | |
363 | * | |
364 | * @param value A value to be checked. | |
365 | * @param cond A predicate to check a given `value`. | |
366 | * @param <T> The type of the `value`. | |
367 | */ | |
368 | default <T> void assumeThat(T value, Predicate<? super T> cond) { | |
369 | checkValueAndThrowIfFails( | |
370 | value, | |
371 | cond, | |
372 | configuration().messageComposer()::composeMessageForAssertion, | |
373 |
1
1. lambda$assumeThat$10 : replaced return value with null for com/github/dakusui/pcond/validator/Validator::lambda$assumeThat$10 → NO_COVERAGE |
explanation -> configuration().exceptionComposer().forAssertThat().testSkippedException(explanation, configuration().reportComposer())); |
374 | } | |
375 | ||
376 | /** | |
377 | * The core method of the `ValueChecker`. | |
378 | * This method checks if the given `evaluationContext` satisfies a condition, passed as `cond`. | |
379 | * If it does, the `evaluationContext` itself will be returned. | |
380 | * If not, an appropriate message will be composed based on the `evaluationContext` and `cond` by the `messageComposerFunction`. | |
381 | * Internally in this method, an `Explanation` of the failure is created by a {@link ReportComposer} | |
382 | * object returned by `configuration().reportComposer()` method. | |
383 | * The `Explanation` is passed to the `exceptionComposerFunction` and the exception | |
384 | * created by the function will be thrown. | |
385 | * | |
386 | * @param <T> The type of the `evaluationContext`. | |
387 | * @param value A value to be checked. | |
388 | * @param cond A predicate that checks the `evaluationContext`. | |
389 | * @param messageComposerFunction A function that composes an error message from the `evaluationContext` and the predicate `cond`. | |
390 | * @param exceptionComposerFunction A function that creates an exception from a failure report created inside this method. | |
391 | * @return The `evaluationContext` itself. | |
392 | */ | |
393 | @SuppressWarnings("unchecked") | |
394 | default <T> T checkValueAndThrowIfFails( | |
395 | T value, | |
396 | Predicate<? super T> cond, | |
397 | BiFunction<T, Predicate<? super T>, String> messageComposerFunction, | |
398 | ExceptionFactory<Throwable> exceptionComposerFunction) { | |
399 | ValueHolder<T> valueHolder = ValueHolder.forValue(value); | |
400 | Evaluable<T> evaluable = toEvaluableIfNecessary(cond); | |
401 | EvaluableIo<T, Evaluable<T>, Boolean> evaluableIo = new EvaluableIo<>(valueHolder, EvaluationContext.resolveEvaluationEntryType(evaluable), evaluable); | |
402 | EvaluationContext<T> evaluationContext = new EvaluationContext<>(); | |
403 |
2
1. checkValueAndThrowIfFails : negated conditional → KILLED 2. checkValueAndThrowIfFails : negated conditional → KILLED |
if (this.configuration().useEvaluator() && cond instanceof Evaluable) { |
404 | Evaluator evaluator = Evaluator.create(); | |
405 |
1
1. checkValueAndThrowIfFails : removed call to com/github/dakusui/pcond/core/Evaluable::accept → KILLED |
((Evaluable<T>) cond).accept(evaluableIo, evaluationContext, evaluator); |
406 |
2
1. checkValueAndThrowIfFails : negated conditional → KILLED 2. checkValueAndThrowIfFails : negated conditional → KILLED |
if (evaluableIo.output().isValueReturned() && Objects.equals(true, evaluableIo.output().value())) |
407 |
1
1. checkValueAndThrowIfFails : replaced return value with null for com/github/dakusui/pcond/validator/Validator::checkValueAndThrowIfFails → KILLED |
return value; |
408 | List<EvaluationEntry> entries = evaluationContext.resultEntries(); | |
409 | throw exceptionComposerFunction.create(configuration() | |
410 | .reportComposer() | |
411 | .composeExplanation( | |
412 | messageComposerFunction.apply(value, cond), | |
413 | entries | |
414 | )); | |
415 | } else { | |
416 |
1
1. checkValueAndThrowIfFails : negated conditional → KILLED |
if (!cond.test(valueHolder.returnedValue())) |
417 | throw exceptionComposerFunction.create(configuration() | |
418 | .reportComposer() | |
419 | .composeExplanation( | |
420 | messageComposerFunction.apply(value, cond), | |
421 | emptyList() | |
422 | )); | |
423 |
1
1. checkValueAndThrowIfFails : replaced return value with null for com/github/dakusui/pcond/validator/Validator::checkValueAndThrowIfFails → KILLED |
return value; |
424 | } | |
425 | } | |
426 | ||
427 | static Validator instance() { | |
428 |
1
1. instance : replaced return value with null for com/github/dakusui/pcond/validator/Validator::instance → KILLED |
return INSTANCE.get(); |
429 | } | |
430 | ||
431 | static void reconfigure(Consumer<Configuration.Builder> configurator) { | |
432 | Configuration.Builder b = instance().configuration().parentBuilder(); | |
433 |
1
1. reconfigure : removed call to com/github/dakusui/pcond/validator/Validator::reconfigure → NO_COVERAGE |
reconfigure(configurator, b); |
434 | } | |
435 | ||
436 | static void reconfigure(Consumer<Configuration.Builder> configurator, Properties properties) { | |
437 | Configuration.Builder b = Configuration.Builder.fromProperties(properties); | |
438 |
1
1. reconfigure : removed call to com/github/dakusui/pcond/validator/Validator::reconfigure → NO_COVERAGE |
reconfigure(configurator, b); |
439 | } | |
440 | ||
441 | static void reconfigure(Consumer<Configuration.Builder> configurator, Configuration.Builder b) { | |
442 |
1
1. reconfigure : removed call to java/util/function/Consumer::accept → NO_COVERAGE |
Objects.requireNonNull(configurator).accept(b); |
443 |
1
1. reconfigure : removed call to java/lang/ThreadLocal::set → NO_COVERAGE |
INSTANCE.set(new Impl(b.build())); |
444 | } | |
445 | ||
446 | static void resetToDefault() { | |
447 |
1
1. resetToDefault : removed call to com/github/dakusui/pcond/validator/Validator::reconfigure → NO_COVERAGE |
reconfigure(b -> { |
448 | }); | |
449 | } | |
450 | ||
451 | static Configuration configurationFromProperties(Properties properties) { | |
452 |
1
1. configurationFromProperties : replaced return value with null for com/github/dakusui/pcond/validator/Validator::configurationFromProperties → KILLED |
return Configuration.Builder.fromProperties(properties).build(); |
453 | } | |
454 | ||
455 | interface ExceptionFactory<E extends Throwable> extends Function<Explanation, E> { | |
456 | default RuntimeException create(Explanation explanation) { | |
457 |
1
1. create : replaced return value with null for com/github/dakusui/pcond/validator/Validator$ExceptionFactory::create → NO_COVERAGE |
return createException(this, explanation); |
458 | } | |
459 | ||
460 | static RuntimeException createException(ExceptionFactory<?> exceptionFactory, Explanation explanation) { | |
461 | Throwable t = exceptionFactory.apply(explanation); | |
462 |
1
1. createException : negated conditional → KILLED |
if (t instanceof Error) |
463 | throw (Error) t; | |
464 |
1
1. createException : negated conditional → KILLED |
if (t instanceof RuntimeException) |
465 | throw (RuntimeException) t; | |
466 | throw new AssertionError(format("Checked exception(%s) cannot be used for validation.", t.getClass()), t); | |
467 | } | |
468 | } | |
469 | ||
470 | interface Configuration { | |
471 | /** | |
472 | * When `com.github.dakusui.pcond.debug` is not `true`, it is assumed that those methods in this interface return `false`. | |
473 | */ | |
474 | interface Debugging { | |
475 | default boolean suppressSquashing() { | |
476 |
1
1. suppressSquashing : replaced boolean return with false for com/github/dakusui/pcond/validator/Validator$Configuration$Debugging::suppressSquashing → NO_COVERAGE |
return true; |
477 | } | |
478 | ||
479 | default boolean enableDebugLog() { | |
480 |
1
1. enableDebugLog : replaced boolean return with false for com/github/dakusui/pcond/validator/Validator$Configuration$Debugging::enableDebugLog → NO_COVERAGE |
return true; |
481 | } | |
482 | ||
483 | default boolean showEvaluableDetail() { | |
484 |
1
1. showEvaluableDetail : replaced boolean return with false for com/github/dakusui/pcond/validator/Validator$Configuration$Debugging::showEvaluableDetail → NO_COVERAGE |
return true; |
485 | } | |
486 | ||
487 | default boolean reportIgnoredEntries() { | |
488 |
1
1. reportIgnoredEntries : replaced boolean return with false for com/github/dakusui/pcond/validator/Validator$Configuration$Debugging::reportIgnoredEntries → NO_COVERAGE |
return true; |
489 | } | |
490 | ||
491 | default boolean passThroughComparisonFailure() { | |
492 |
1
1. passThroughComparisonFailure : replaced boolean return with false for com/github/dakusui/pcond/validator/Validator$Configuration$Debugging::passThroughComparisonFailure → NO_COVERAGE |
return true; |
493 | } | |
494 | } | |
495 | ||
496 | int summarizedStringLength(); | |
497 | ||
498 | boolean useEvaluator(); | |
499 | ||
500 | /** | |
501 | * Returns a message composer, which is responsible for composing an appropriate message for | |
502 | * a context. | |
503 | * | |
504 | * @return A message composer. | |
505 | */ | |
506 | MessageComposer messageComposer(); | |
507 | ||
508 | /** | |
509 | * Returns a report composer, which is responsible for composing an appropriate "report" for | |
510 | * a context. | |
511 | * | |
512 | * @return A report composer | |
513 | */ | |
514 | ReportComposer reportComposer(); | |
515 | ||
516 | /** | |
517 | * Returns an exception composer, which is responsible for creating an exception | |
518 | * object of an appropriate type for a context. | |
519 | * | |
520 | * @return An exception composer. | |
521 | */ | |
522 | ExceptionComposer exceptionComposer(); | |
523 | ||
524 | Optional<Debugging> debugging(); | |
525 | ||
526 | Configuration.Builder parentBuilder(); | |
527 | ||
528 | enum Utils { | |
529 | ; | |
530 | ||
531 | @SuppressWarnings("unchecked") | |
532 | static <E> E instantiate(@SuppressWarnings("unused") Class<E> baseClass, String className) { | |
533 | try { | |
534 |
1
1. instantiate : replaced return value with null for com/github/dakusui/pcond/validator/Validator$Configuration$Utils::instantiate → KILLED |
return (E) Class.forName(className).newInstance(); |
535 | } catch (InstantiationException | IllegalAccessException | | |
536 | ClassNotFoundException e) { | |
537 | throw new RuntimeException(e); | |
538 | } | |
539 | } | |
540 | ||
541 | public static Properties loadPcondProperties() { | |
542 | try { | |
543 | Properties ret = new Properties(); | |
544 |
1
1. loadPcondProperties : removed call to java/util/Properties::forEach → SURVIVED |
System.getProperties().forEach((k, v) -> { |
545 | String key = Objects.toString(k); | |
546 | String value = Objects.toString(v); | |
547 | String prefix = "com.github.dakusui.pcond."; | |
548 |
1
1. lambda$loadPcondProperties$0 : negated conditional → SURVIVED |
if (key.startsWith(prefix)) { |
549 | ret.put(key.replace(prefix, ""), value); | |
550 | } | |
551 | }); | |
552 | try (InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("pcond.properties")) { | |
553 | if (inputStream == null) | |
554 |
1
1. loadPcondProperties : replaced return value with null for com/github/dakusui/pcond/validator/Validator$Configuration$Utils::loadPcondProperties → SURVIVED |
return ret; |
555 |
1
1. loadPcondProperties : removed call to java/util/Properties::load → NO_COVERAGE |
ret.load(inputStream); |
556 |
1
1. loadPcondProperties : replaced return value with null for com/github/dakusui/pcond/validator/Validator$Configuration$Utils::loadPcondProperties → NO_COVERAGE |
return ret; |
557 | } | |
558 | } catch (IOException e) { | |
559 | throw new RuntimeException(e); | |
560 | } | |
561 | } | |
562 | } | |
563 | ||
564 | class Builder implements Cloneable { | |
565 | boolean useEvaluator; | |
566 | int summarizedStringLength; | |
567 | ||
568 | ||
569 | MessageComposer messageComposer; | |
570 | ReportComposer reportComposer; | |
571 | private ExceptionComposer.ForRequire exceptionComposerForRequire; | |
572 | private ExceptionComposer.ForEnsure exceptionComposerForEnsure; | |
573 | private ExceptionComposer.ForValidate defaultExceptionComposerForValidate; | |
574 | private ExceptionComposer.ForAssertion exceptionComposerForAssert; | |
575 | private ExceptionComposer.ForTestAssertion exceptionComposerForTestFailures; | |
576 | ||
577 | public Builder() { | |
578 | } | |
579 | ||
580 | ||
581 | public Builder useEvaluator(boolean useEvaluator) { | |
582 | this.useEvaluator = useEvaluator; | |
583 |
1
1. useEvaluator : replaced return value with null for com/github/dakusui/pcond/validator/Validator$Configuration$Builder::useEvaluator → KILLED |
return this; |
584 | } | |
585 | ||
586 | public Builder summarizedStringLength(int summarizedStringLength) { | |
587 | this.summarizedStringLength = summarizedStringLength; | |
588 |
1
1. summarizedStringLength : replaced return value with null for com/github/dakusui/pcond/validator/Validator$Configuration$Builder::summarizedStringLength → KILLED |
return this; |
589 | } | |
590 | ||
591 | public Builder exceptionComposerForRequire(ExceptionComposer.ForRequire exceptionComposerForRequire) { | |
592 | this.exceptionComposerForRequire = exceptionComposerForRequire; | |
593 |
1
1. exceptionComposerForRequire : replaced return value with null for com/github/dakusui/pcond/validator/Validator$Configuration$Builder::exceptionComposerForRequire → KILLED |
return this; |
594 | } | |
595 | ||
596 | public Builder exceptionComposerForEnsure(ExceptionComposer.ForEnsure exceptionComposerForEnsure) { | |
597 | this.exceptionComposerForEnsure = exceptionComposerForEnsure; | |
598 |
1
1. exceptionComposerForEnsure : replaced return value with null for com/github/dakusui/pcond/validator/Validator$Configuration$Builder::exceptionComposerForEnsure → KILLED |
return this; |
599 | } | |
600 | ||
601 | public Builder defaultExceptionComposerForValidate(ExceptionComposer.ForValidate exceptionComposerForValidate) { | |
602 | this.defaultExceptionComposerForValidate = exceptionComposerForValidate; | |
603 |
1
1. defaultExceptionComposerForValidate : replaced return value with null for com/github/dakusui/pcond/validator/Validator$Configuration$Builder::defaultExceptionComposerForValidate → KILLED |
return this; |
604 | } | |
605 | ||
606 | public Builder exceptionComposerForAssert(ExceptionComposer.ForAssertion exceptionComposerForAssert) { | |
607 | this.exceptionComposerForAssert = exceptionComposerForAssert; | |
608 |
1
1. exceptionComposerForAssert : replaced return value with null for com/github/dakusui/pcond/validator/Validator$Configuration$Builder::exceptionComposerForAssert → KILLED |
return this; |
609 | } | |
610 | ||
611 | public Builder exceptionComposerForAssertThat(ExceptionComposer.ForTestAssertion exceptionComposerForAssertThat) { | |
612 | this.exceptionComposerForTestFailures = exceptionComposerForAssertThat; | |
613 |
1
1. exceptionComposerForAssertThat : replaced return value with null for com/github/dakusui/pcond/validator/Validator$Configuration$Builder::exceptionComposerForAssertThat → KILLED |
return this; |
614 | } | |
615 | ||
616 | public Builder messageComposer(MessageComposer messageComposer) { | |
617 | this.messageComposer = messageComposer; | |
618 |
1
1. messageComposer : replaced return value with null for com/github/dakusui/pcond/validator/Validator$Configuration$Builder::messageComposer → KILLED |
return this; |
619 | } | |
620 | ||
621 | public Builder reportComposer(ReportComposer reportComposer) { | |
622 | this.reportComposer = reportComposer; | |
623 |
1
1. reportComposer : replaced return value with null for com/github/dakusui/pcond/validator/Validator$Configuration$Builder::reportComposer → KILLED |
return this; |
624 | } | |
625 | ||
626 | public Builder useOpentest4J() { | |
627 | this.exceptionComposerForTestFailures = new ExceptionComposer.ForTestAssertion.Opentest4J(); | |
628 |
1
1. useOpentest4J : replaced return value with null for com/github/dakusui/pcond/validator/Validator$Configuration$Builder::useOpentest4J → NO_COVERAGE |
return this; |
629 | } | |
630 | ||
631 | public Configuration build() { | |
632 |
1
1. build : negated conditional → SURVIVED |
if (!isClassPresent("org.junit.ComparisonFailure")) |
633 | this.useOpentest4J(); | |
634 |
1
1. build : replaced return value with null for com/github/dakusui/pcond/validator/Validator$Configuration$Builder::build → KILLED |
return new Configuration() { |
635 | private final Debugging debugging = new Debugging() { | |
636 | }; | |
637 | ||
638 | private final ExceptionComposer exceptionComposer = new ExceptionComposer.Impl( | |
639 | exceptionComposerForRequire, | |
640 | exceptionComposerForEnsure, | |
641 | defaultExceptionComposerForValidate, | |
642 | exceptionComposerForAssert, | |
643 | exceptionComposerForTestFailures | |
644 | ); | |
645 | ||
646 | @Override | |
647 | public int summarizedStringLength() { | |
648 |
1
1. summarizedStringLength : replaced int return with 0 for com/github/dakusui/pcond/validator/Validator$Configuration$Builder$1::summarizedStringLength → KILLED |
return Builder.this.summarizedStringLength; |
649 | } | |
650 | ||
651 | @Override | |
652 | public boolean useEvaluator() { | |
653 |
2
1. useEvaluator : replaced boolean return with false for com/github/dakusui/pcond/validator/Validator$Configuration$Builder$1::useEvaluator → KILLED 2. useEvaluator : replaced boolean return with true for com/github/dakusui/pcond/validator/Validator$Configuration$Builder$1::useEvaluator → KILLED |
return Builder.this.useEvaluator; |
654 | } | |
655 | ||
656 | /** | |
657 | * Returns an exception composer, which is responsible for creating an exception | |
658 | * object of an appropriate type for a context. | |
659 | * | |
660 | * @return An exception composer. | |
661 | */ | |
662 | public ExceptionComposer exceptionComposer() { | |
663 |
1
1. exceptionComposer : replaced return value with null for com/github/dakusui/pcond/validator/Validator$Configuration$Builder$1::exceptionComposer → KILLED |
return this.exceptionComposer; |
664 | } | |
665 | ||
666 | @Override | |
667 | public Optional<Debugging> debugging() { | |
668 |
1
1. debugging : negated conditional → KILLED |
if (Boolean.parseBoolean(System.getProperty("com.github.dakusui.pcond.debug"))) { |
669 |
1
1. debugging : replaced return value with Optional.empty for com/github/dakusui/pcond/validator/Validator$Configuration$Builder$1::debugging → NO_COVERAGE |
return Optional.of(this.debugging); |
670 | } | |
671 | return Optional.empty(); | |
672 | } | |
673 | ||
674 | @Override | |
675 | public MessageComposer messageComposer() { | |
676 |
1
1. messageComposer : replaced return value with null for com/github/dakusui/pcond/validator/Validator$Configuration$Builder$1::messageComposer → KILLED |
return Builder.this.messageComposer; |
677 | } | |
678 | ||
679 | @Override | |
680 | public ReportComposer reportComposer() { | |
681 |
1
1. reportComposer : replaced return value with null for com/github/dakusui/pcond/validator/Validator$Configuration$Builder$1::reportComposer → KILLED |
return Builder.this.reportComposer; |
682 | } | |
683 | ||
684 | @Override | |
685 | public Builder parentBuilder() { | |
686 |
1
1. parentBuilder : replaced return value with null for com/github/dakusui/pcond/validator/Validator$Configuration$Builder$1::parentBuilder → NO_COVERAGE |
return Builder.this.clone(); |
687 | } | |
688 | }; | |
689 | } | |
690 | ||
691 | private static boolean isClassPresent(String s) { | |
692 | try { | |
693 | Class.forName(s); | |
694 |
1
1. isClassPresent : replaced boolean return with false for com/github/dakusui/pcond/validator/Validator$Configuration$Builder::isClassPresent → SURVIVED |
return true; |
695 | } catch (ClassNotFoundException e) { | |
696 |
1
1. isClassPresent : replaced boolean return with true for com/github/dakusui/pcond/validator/Validator$Configuration$Builder::isClassPresent → NO_COVERAGE |
return false; |
697 | } | |
698 | } | |
699 | ||
700 | @Override | |
701 | public Builder clone() { | |
702 | try { | |
703 |
1
1. clone : replaced return value with null for com/github/dakusui/pcond/validator/Validator$Configuration$Builder::clone → NO_COVERAGE |
return (Builder) super.clone(); |
704 | } catch (CloneNotSupportedException e) { | |
705 | throw new AssertionError(); | |
706 | } | |
707 | } | |
708 | ||
709 | static Builder fromProperties(Properties properties) { | |
710 |
1
1. fromProperties : replaced return value with null for com/github/dakusui/pcond/validator/Validator$Configuration$Builder::fromProperties → KILLED |
return new Builder() |
711 | .useEvaluator(Boolean.parseBoolean(properties.getProperty("useEvaluator", "true"))) | |
712 | .summarizedStringLength(Integer.parseInt(properties.getProperty("summarizedStringLength", "40"))) | |
713 | .exceptionComposerForRequire(instantiate(ExceptionComposer.ForRequire.class, properties.getProperty("exceptionComposerForRequire", "com.github.dakusui.pcond.validator.ExceptionComposer$ForRequire$Default"))) | |
714 | .exceptionComposerForEnsure(instantiate(ExceptionComposer.ForEnsure.class, properties.getProperty("exceptionComposerForEnsure", "com.github.dakusui.pcond.validator.ExceptionComposer$ForEnsure$Default"))) | |
715 | .defaultExceptionComposerForValidate(instantiate(ExceptionComposer.ForValidate.class, properties.getProperty("defaultExceptionComposerForValidate", "com.github.dakusui.pcond.validator.ExceptionComposer$ForValidate$Default"))) | |
716 | .exceptionComposerForAssert(instantiate(ExceptionComposer.ForAssertion.class, properties.getProperty("exceptionComposerForAssert", "com.github.dakusui.pcond.validator.ExceptionComposer$ForAssertion$Default"))) | |
717 | .exceptionComposerForAssertThat(instantiate(ExceptionComposer.ForTestAssertion.class, properties.getProperty("exceptionComposerForTestFailures", "com.github.dakusui.pcond.validator.ExceptionComposer$ForTestAssertion$JUnit4"))) | |
718 | .messageComposer(instantiate(MessageComposer.class, properties.getProperty("messageComposer", "com.github.dakusui.pcond.validator.MessageComposer$Default"))) | |
719 | .reportComposer(instantiate(ReportComposer.class, properties.getProperty("reportComposer", "com.github.dakusui.pcond.validator.ReportComposer$Default"))); | |
720 | } | |
721 | } | |
722 | } | |
723 | ||
724 | class Impl implements Validator { | |
725 | ||
726 | private final Configuration configuration; | |
727 | ||
728 | public Impl(Configuration configuration) { | |
729 | this.configuration = Objects.requireNonNull(configuration); | |
730 | } | |
731 | ||
732 | @Override | |
733 | public Configuration configuration() { | |
734 |
1
1. configuration : replaced return value with null for com/github/dakusui/pcond/validator/Validator$Impl::configuration → KILLED |
return this.configuration; |
735 | } | |
736 | } | |
737 | } | |
Mutations | ||
29 |
1.1 |
|
48 |
1.1 |
|
60 |
1.1 |
|
73 |
1.1 |
|
86 |
1.1 |
|
101 |
1.1 2.2 |
|
117 |
1.1 |
|
121 |
1.1 |
|
139 |
1.1 |
|
156 |
1.1 |
|
174 |
1.1 |
|
192 |
1.1 |
|
209 |
1.1 2.2 |
|
213 |
1.1 |
|
231 |
1.1 |
|
246 |
1.1 |
|
261 |
1.1 2.2 |
|
278 |
1.1 |
|
282 |
1.1 |
|
301 |
1.1 |
|
320 |
1.1 |
|
339 |
1.1 |
|
356 |
1.1 |
|
373 |
1.1 |
|
403 |
1.1 2.2 |
|
405 |
1.1 |
|
406 |
1.1 2.2 |
|
407 |
1.1 |
|
416 |
1.1 |
|
423 |
1.1 |
|
428 |
1.1 |
|
433 |
1.1 |
|
438 |
1.1 |
|
442 |
1.1 |
|
443 |
1.1 |
|
447 |
1.1 |
|
452 |
1.1 |
|
457 |
1.1 |
|
462 |
1.1 |
|
464 |
1.1 |
|
476 |
1.1 |
|
480 |
1.1 |
|
484 |
1.1 |
|
488 |
1.1 |
|
492 |
1.1 |
|
534 |
1.1 |
|
544 |
1.1 |
|
548 |
1.1 |
|
554 |
1.1 |
|
555 |
1.1 |
|
556 |
1.1 |
|
583 |
1.1 |
|
588 |
1.1 |
|
593 |
1.1 |
|
598 |
1.1 |
|
603 |
1.1 |
|
608 |
1.1 |
|
613 |
1.1 |
|
618 |
1.1 |
|
623 |
1.1 |
|
628 |
1.1 |
|
632 |
1.1 |
|
634 |
1.1 |
|
648 |
1.1 |
|
653 |
1.1 2.2 |
|
663 |
1.1 |
|
668 |
1.1 |
|
669 |
1.1 |
|
676 |
1.1 |
|
681 |
1.1 |
|
686 |
1.1 |
|
694 |
1.1 |
|
696 |
1.1 |
|
703 |
1.1 |
|
710 |
1.1 |
|
734 |
1.1 |