| 1 | package com.github.valid8j.classic; | |
| 2 | ||
| 3 | import com.github.valid8j.pcond.fluent.Statement; | |
| 4 | import com.github.valid8j.pcond.forms.Functions; | |
| 5 | import com.github.valid8j.pcond.forms.Predicates; | |
| 6 | import com.github.valid8j.pcond.forms.Printables; | |
| 7 | import com.github.valid8j.pcond.validator.Validator; | |
| 8 | ||
| 9 | import java.util.List; | |
| 10 | import java.util.function.Function; | |
| 11 | import java.util.function.Predicate; | |
| 12 | import java.util.function.Supplier; | |
| 13 | ||
| 14 | /** | |
| 15 | * An entry-point class for test assertions. | |
| 16 | * You can use the methods to replace the usages of the methods the same names of the `Hamcrest`. | |
| 17 | * | |
| 18 | * Instead of the `Matcher` s of `Hamcrest`, you can use just simple functions and predicates. | |
| 19 | * | |
| 20 | * There are pre-defined printable functions and predicates in the {@link Functions} | |
| 21 | * class and {@link Predicates} class. | |
| 22 | * | |
| 23 | * You can build your matchers by composing them using methods in the Java's | |
| 24 | * {@link Function} and {@link Predicate} such as {@link Function#andThen(Function)}, | |
| 25 | * {@link Function#compose(Function)}, {@link Predicate#and(Predicate)}, {@link Predicate#or(Predicate)}, | |
| 26 | * and {@link Predicate#negate()}. | |
| 27 | * | |
| 28 | * To create your own function or predicate that renders a human-readable message, | |
| 29 | * you can use the `function` and `predicate` methods defined in the `Printables` | |
| 30 | * class. | |
| 31 | * | |
| 32 | * {@link Predicates#transform(Function)} is a method | |
| 33 | * to build a predicate, which first transforms a value into a type that the `pcond` offers | |
| 34 | * a rich support, such as {@link String}, {@link List}, {@link Comparable}, etc., | |
| 35 | * and the applies predicates to the transformed value. | |
| 36 | * With this approach, you will not need to create your own matchers, but just create | |
| 37 | * a function that transform your class into easily verifiable types for your verification. | |
| 38 | * | |
| 39 | * Each method, which ends with `Statement` or `all`, in this class accepts {@link Statement} objects. | |
| 40 | * To create a {@link Statement} object, you can call static methods in {@link Statement} itself. | |
| 41 | * class such as {@link Statement#booleanValue(Boolean)}, {@link Statement#stringValue(String)}, | |
| 42 | * etc. | |
| 43 | * | |
| 44 | * @see Predicates | |
| 45 | * @see Functions | |
| 46 | * @see Predicates#transform(Function) | |
| 47 | * @see Printables#predicate(String, Predicate) | |
| 48 | * @see Printables#function(String, Function) | |
| 49 | * @see Printables#predicate(Supplier, Predicate) | |
| 50 | * @see Printables#function(Supplier, Function) | |
| 51 | */ | |
| 52 | public enum TestAssertions { | |
| 53 | ||
| 54 | ; | |
| 55 | ||
| 56 | /** | |
| 57 | * A method to check a given `value` satisfies a condition `predicate`, to be verified by the test. | |
| 58 | * If it is not satisfied, the test should fail. | |
| 59 | * | |
| 60 | * @param value The value to be checked. | |
| 61 | * @param predicate A condition to check the `value`. | |
| 62 | * @param <T> The type of the `value`. | |
| 63 | */ | |
| 64 | public static <T> void assertThat(T value, Predicate<? super T> predicate) { | |
| 65 |
1
1. assertThat : removed call to com/github/valid8j/pcond/validator/Validator::assertThat → KILLED |
Validator.instance().assertThat(value, predicate); |
| 66 | } | |
| 67 | ||
| 68 | /** | |
| 69 | * A method to check a given `value` satisfies a condition `predicate`, which is required by the *test's design* to execute it. | |
| 70 | * If it is not satisfied, that means, the value violates an assumption of the test, therefore the test should be ignored, not fail. | |
| 71 | * If you are using *JUnit4*, an `AssumptionViolatedException` should be thrown. | |
| 72 | * | |
| 73 | * @param value The value to be checked. | |
| 74 | * @param predicate A condition to check the `value`. | |
| 75 | * @param <T> The type of the `value`. | |
| 76 | */ | |
| 77 | public static <T> void assumeThat(T value, Predicate<? super T> predicate) { | |
| 78 |
1
1. assumeThat : removed call to com/github/valid8j/pcond/validator/Validator::assumeThat → KILLED |
Validator.instance().assumeThat(value, predicate); |
| 79 | } | |
| 80 | } | |
Mutations | ||
| 65 |
1.1 |
|
| 78 |
1.1 |