| 1 | package com.github.valid8j.pcond.forms; | |
| 2 | ||
| 3 | import com.github.valid8j.pcond.core.printable.PrintableFunctionFactory; | |
| 4 | import com.github.valid8j.pcond.core.refl.MethodQuery; | |
| 5 | import com.github.valid8j.pcond.core.refl.Parameter; | |
| 6 | import com.github.valid8j.pcond.core.refl.ReflUtils; | |
| 7 | import com.github.valid8j.pcond.experimentals.currying.CurriedFunction; | |
| 8 | import com.github.valid8j.pcond.experimentals.currying.CurryingUtils; | |
| 9 | import com.github.valid8j.pcond.experimentals.currying.multi.MultiFunction; | |
| 10 | import com.github.valid8j.pcond.experimentals.currying.multi.MultiFunctionUtils; | |
| 11 | import com.github.valid8j.pcond.validator.Validator; | |
| 12 | import com.github.valid8j.pcond.internals.InternalUtils; | |
| 13 | ||
| 14 | import java.util.Collection; | |
| 15 | import java.util.List; | |
| 16 | import java.util.NoSuchElementException; | |
| 17 | import java.util.function.Function; | |
| 18 | import java.util.function.Predicate; | |
| 19 | import java.util.stream.IntStream; | |
| 20 | import java.util.stream.Stream; | |
| 21 | ||
| 22 | import static com.github.valid8j.pcond.core.refl.ReflUtils.invokeMethod; | |
| 23 | import static com.github.valid8j.pcond.forms.Predicates.allOf; | |
| 24 | import static com.github.valid8j.pcond.forms.Predicates.isInstanceOf; | |
| 25 | import static com.github.valid8j.pcond.internals.InternalUtils.formatObject; | |
| 26 | import static java.lang.String.format; | |
| 27 | import static java.util.Collections.singletonList; | |
| 28 | import static java.util.Objects.requireNonNull; | |
| 29 | ||
| 30 | /** | |
| 31 | * An entry point for acquiring function objects. | |
| 32 | * Functions retrieved by methods in this class are all "printable". | |
| 33 | */ | |
| 34 | public class Functions { | |
| 35 | private Functions() { | |
| 36 | ||
| 37 | } | |
| 38 | ||
| 39 | /** | |
| 40 | * Returns a printable function that returns a given object itself. | |
| 41 | * | |
| 42 | * @param <E> The type of the object. | |
| 43 | * @return The function. | |
| 44 | */ | |
| 45 | public static <E> Function<E, E> identity() { | |
| 46 |
1
1. identity : replaced return value with null for com/github/valid8j/pcond/forms/Functions::identity → KILLED |
return PrintableFunctionFactory.Simple.IDENTITY.instance(); |
| 47 | } | |
| 48 | ||
| 49 | /** | |
| 50 | * Returns a function that gives a string representation of a object given to it. | |
| 51 | * Internally, the returned function calls `toString` method on a given object. | |
| 52 | * | |
| 53 | * @param <E> The type of the object | |
| 54 | * @return The function. | |
| 55 | */ | |
| 56 | public static <E> Function<E, String> stringify() { | |
| 57 |
1
1. stringify : replaced return value with null for com/github/valid8j/pcond/forms/Functions::stringify → KILLED |
return PrintableFunctionFactory.Simple.STRINGIFY.instance(); |
| 58 | } | |
| 59 | ||
| 60 | /** | |
| 61 | * Returns a function that gives a length of a string passed as an argument. | |
| 62 | * | |
| 63 | * @return The function. | |
| 64 | */ | |
| 65 | public static Function<? super String, Integer> length() { | |
| 66 |
1
1. length : replaced return value with null for com/github/valid8j/pcond/forms/Functions::length → RUN_ERROR |
return PrintableFunctionFactory.Simple.LENGTH.instance(); |
| 67 | } | |
| 68 | ||
| 69 | ||
| 70 | @SuppressWarnings({ "unchecked", "RedundantClassCall" }) | |
| 71 | public static <E> Function<List<E>, E> elementAt(int i) { | |
| 72 |
1
1. elementAt : replaced return value with null for com/github/valid8j/pcond/forms/Functions::elementAt → KILLED |
return Function.class.cast(PrintableFunctionFactory.Parameterized.ELEMENT_AT.create(singletonList(i))); |
| 73 | } | |
| 74 | ||
| 75 | /** | |
| 76 | * Returns a function that that returns a size of a given list. | |
| 77 | * | |
| 78 | * @return The function. | |
| 79 | */ | |
| 80 | public static <E> Function<Collection<E>, Integer> size() { | |
| 81 |
1
1. size : replaced return value with null for com/github/valid8j/pcond/forms/Functions::size → KILLED |
return PrintableFunctionFactory.Simple.SIZE.instance(); |
| 82 | } | |
| 83 | ||
| 84 | /** | |
| 85 | * Returns a function that returns a stream for a given collection. | |
| 86 | * | |
| 87 | * @param <E> Type of elements in the given collection. | |
| 88 | * @return The function. | |
| 89 | */ | |
| 90 | public static <E> Function<Collection<? extends E>, Stream<E>> stream() { | |
| 91 |
1
1. stream : replaced return value with null for com/github/valid8j/pcond/forms/Functions::stream → KILLED |
return PrintableFunctionFactory.Simple.STREAM.instance(); |
| 92 | } | |
| 93 | ||
| 94 | /** | |
| 95 | * Returns a function that returns a stream for a given collection. | |
| 96 | * | |
| 97 | * @param elementClass A parameter to let compiler know the type of the element in a collection. | |
| 98 | * @param <E> A type of elements in a collection. | |
| 99 | * @return The function. | |
| 100 | */ | |
| 101 | public static <E> Function<Collection<? extends E>, Stream<E>> stream(@SuppressWarnings("unused") Class<E> elementClass) { | |
| 102 |
1
1. stream : replaced return value with null for com/github/valid8j/pcond/forms/Functions::stream → RUN_ERROR |
return stream(); |
| 103 | } | |
| 104 | ||
| 105 | /** | |
| 106 | * Returns a function that returns a stream for a given object. | |
| 107 | * This method corresponds to {@link Stream#of(Object)} method. | |
| 108 | * | |
| 109 | * @param <E> Type of object. | |
| 110 | * @return The function. | |
| 111 | */ | |
| 112 | public static <E> Function<E, Stream<E>> streamOf() { | |
| 113 |
1
1. streamOf : replaced return value with null for com/github/valid8j/pcond/forms/Functions::streamOf → RUN_ERROR |
return PrintableFunctionFactory.Simple.STREAM_OF.instance(); |
| 114 | } | |
| 115 | ||
| 116 | /** | |
| 117 | * Returns a function that casts an object into a given class. | |
| 118 | * | |
| 119 | * @param type The type to which the given object is cast | |
| 120 | * @param <E> The type to which the object is case. | |
| 121 | * @return The function. | |
| 122 | */ | |
| 123 | public static <E> Function<? super Object, E> cast(Class<E> type) { | |
| 124 |
1
1. cast : replaced return value with null for com/github/valid8j/pcond/forms/Functions::cast → KILLED |
return PrintableFunctionFactory.Parameterized.CAST.create(singletonList(type)); |
| 125 | } | |
| 126 | ||
| 127 | /** | |
| 128 | * Returns a function that casts an object into a given class. | |
| 129 | * ```java | |
| 130 | * assertThat( | |
| 131 | * asList(lastName, fullName), | |
| 132 | * allOf( | |
| 133 | * transform(elementAt(0).andThen(cast(String.class))).check(allOf(isNotNull(), not(isEmptyString()))), | |
| 134 | * transform(elementAt(1).andThen(castTo((List<String>)value()))).check(Predicates.contains(lastName)))); | |
| 135 | * ``` | |
| 136 | * | |
| 137 | * @param value A type place-holder. | |
| 138 | * Always use a value returned from {@link Functions#value()} method. | |
| 139 | * @param <E> The type to which the object is case. | |
| 140 | * @return The function. | |
| 141 | */ | |
| 142 | public static <E> Function<? super Object, E> castTo(@SuppressWarnings("unused") E value) { | |
| 143 |
1
1. castTo : replaced return value with null for com/github/valid8j/pcond/forms/Functions::castTo → NO_COVERAGE |
return PrintableFunctionFactory.Simple.CAST_TO.instance(); |
| 144 | } | |
| 145 | ||
| 146 | /** | |
| 147 | * Returns a function that creates and returns a list that contains all the elements in the given list. | |
| 148 | * | |
| 149 | * @param <I> The type of the input collection. | |
| 150 | * @param <E> Type of the elements in the collection | |
| 151 | * @return The function. | |
| 152 | */ | |
| 153 | public static <I extends Collection<E>, E> Function<I, List<E>> collectionToList() { | |
| 154 |
1
1. collectionToList : replaced return value with null for com/github/valid8j/pcond/forms/Functions::collectionToList → RUN_ERROR |
return PrintableFunctionFactory.Simple.COLLECTION_TO_LIST.instance(); |
| 155 | } | |
| 156 | ||
| 157 | /** | |
| 158 | * Returns a function that converts a given array into a list. | |
| 159 | * | |
| 160 | * @param <E> Type of elements in a given array. | |
| 161 | * @return The function. | |
| 162 | */ | |
| 163 | public static <E> Function<E[], List<E>> arrayToList() { | |
| 164 |
1
1. arrayToList : replaced return value with null for com/github/valid8j/pcond/forms/Functions::arrayToList → RUN_ERROR |
return PrintableFunctionFactory.Simple.ARRAY_TO_LIST.instance(); |
| 165 | } | |
| 166 | ||
| 167 | /** | |
| 168 | * Returns a function the counts lines in a given string. | |
| 169 | * | |
| 170 | * @return The function. | |
| 171 | */ | |
| 172 | public static Function<String, Integer> countLines() { | |
| 173 |
1
1. countLines : replaced return value with null for com/github/valid8j/pcond/forms/Functions::countLines → RUN_ERROR |
return PrintableFunctionFactory.Simple.COUNT_LINES.instance(); |
| 174 | } | |
| 175 | ||
| 176 | /** | |
| 177 | * //@formatter:off | |
| 178 | * The returned function tries to find a {@code substring} after a given string. | |
| 179 | * If found, it returns the result of the following statement. | |
| 180 | * | |
| 181 | * [source,java] | |
| 182 | * ---- | |
| 183 | * s.substring(s.indexOf(substring) + substring.length()) | |
| 184 | * ---- | |
| 185 | * | |
| 186 | * If not found, a {@link StringIndexOutOfBoundsException} will be thrown. | |
| 187 | * //@formatter:on | |
| 188 | * | |
| 189 | * @param substring A substring to find in a given string. | |
| 190 | * @return The string after the {@code substring}. | |
| 191 | */ | |
| 192 | public static Function<String, String> findString(String substring) { | |
| 193 | requireNonNull(substring); | |
| 194 |
1
1. findString : replaced return value with null for com/github/valid8j/pcond/forms/Functions::findString → RUN_ERROR |
return PrintableFunctionFactory.function( |
| 195 |
1
1. lambda$findString$0 : replaced return value with "" for com/github/valid8j/pcond/forms/Functions::lambda$findString$0 → NO_COVERAGE |
() -> format("findString[%s]", substring), |
| 196 | s -> { | |
| 197 | int index = s.indexOf(substring); | |
| 198 |
2
1. lambda$findString$1 : changed conditional boundary → RUN_ERROR 2. lambda$findString$1 : negated conditional → RUN_ERROR |
if (index >= 0) |
| 199 |
2
1. lambda$findString$1 : Replaced integer addition with subtraction → RUN_ERROR 2. lambda$findString$1 : replaced return value with "" for com/github/valid8j/pcond/forms/Functions::lambda$findString$1 → RUN_ERROR |
return s.substring(s.indexOf(substring) + substring.length()); |
| 200 | throw new NoSuchElementException(format("'%s' was not found in '%s'", substring, s)); | |
| 201 | }); | |
| 202 | } | |
| 203 | ||
| 204 | /** | |
| 205 | * https://en.wikipedia.org/wiki/Currying[Curries] a static method specified by the given arguments. | |
| 206 | * | |
| 207 | * @param aClass A class to which the method to be curried belongs to. | |
| 208 | * @param methodName A name of the method to be curried. | |
| 209 | * @param parameterTypes Parameters types of the method. | |
| 210 | * @return A printable and curried function of the target method. | |
| 211 | */ | |
| 212 | @SuppressWarnings("JavadocLinkAsPlainText") | |
| 213 | public static CurriedFunction<Object, Object> curry(Class<?> aClass, String methodName, Class<?>... parameterTypes) { | |
| 214 |
1
1. curry : replaced return value with null for com/github/valid8j/pcond/forms/Functions::curry → SURVIVED |
return curry(multifunction(aClass, methodName, parameterTypes)); |
| 215 | } | |
| 216 | ||
| 217 | /** | |
| 218 | * Curries a given multi-function. | |
| 219 | * | |
| 220 | * @param function A multi-function to be curried | |
| 221 | * @return A curried function | |
| 222 | * @see Functions#curry(Class, String, Class[]) | |
| 223 | */ | |
| 224 | public static CurriedFunction<Object, Object> curry(MultiFunction<Object> function) { | |
| 225 |
1
1. curry : replaced return value with null for com/github/valid8j/pcond/forms/Functions::curry → SURVIVED |
return CurryingUtils.curry(function); |
| 226 | } | |
| 227 | ||
| 228 | public static <R> MultiFunction<R> multifunction(Class<?> aClass, String methodName, Class<?>... parameterTypes) { | |
| 229 |
1
1. multifunction : replaced return value with null for com/github/valid8j/pcond/forms/Functions::multifunction → KILLED |
return MultiFunctionUtils.multifunction(IntStream.range(0, parameterTypes.length).toArray(), aClass, methodName, parameterTypes); |
| 230 | } | |
| 231 | ||
| 232 | /** | |
| 233 | * Returns a {@link Function} created from a method specified by a {@code methodQuery}. | |
| 234 | * If the {@code methodQuery} matches none or more than one methods, a {@code RuntimeException} will be thrown. | |
| 235 | * | |
| 236 | * To pass an input value given to an entry point method, such as `TestAssertions.assertThat`, to the method, use a place-holder value returned by {@link Functions#parameter()}. | |
| 237 | * | |
| 238 | * @param methodQuery A query object that specifies a method to be invoked by the returned function. | |
| 239 | * @param <T> the type of the input to the returned function | |
| 240 | * @return Created function. | |
| 241 | * @see Functions#classMethod(Class, String, Object[]) | |
| 242 | * @see Functions#instanceMethod(Object, String, Object[]) | |
| 243 | * @see Functions#parameter() | |
| 244 | */ | |
| 245 | public static <T, R> Function<T, R> call(MethodQuery methodQuery) { | |
| 246 |
5
1. lambda$null$2 : replaced boolean return with true for com/github/valid8j/pcond/forms/Functions::lambda$null$2 → SURVIVED 2. call : replaced return value with null for com/github/valid8j/pcond/forms/Functions::call → KILLED 3. lambda$call$4 : replaced return value with null for com/github/valid8j/pcond/forms/Functions::lambda$call$4 → KILLED 4. lambda$null$2 : replaced boolean return with false for com/github/valid8j/pcond/forms/Functions::lambda$null$2 → KILLED 5. lambda$null$3 : replaced return value with null for com/github/valid8j/pcond/forms/Functions::lambda$null$3 → KILLED |
return Printables.function(methodQuery.describe(), t -> invokeMethod(methodQuery.bindActualArguments((o) -> o instanceof Parameter, o -> t))); |
| 247 | } | |
| 248 | ||
| 249 | ||
| 250 | /** | |
| 251 | * // @formatter:off | |
| 252 | * Creates a {@link MethodQuery} object from given arguments to search for {@code static} methods. | |
| 253 | * Note that {@code arguments} are actual argument values, not the formal parameter types. | |
| 254 | * The pcond library searches for the "best" matching method for you. | |
| 255 | * In case no matching method is found or more than one methods are found, a {@link RuntimeException} | |
| 256 | * will be thrown. | |
| 257 | * | |
| 258 | * In order to specify a parameter which should be passed to the returned function at applying, | |
| 259 | * you can use an object returned by {@link Functions#parameter} method. | |
| 260 | * This is useful to construct a function from an existing method. | |
| 261 | * | |
| 262 | * To pass an input value given to an entry point method, such as `TestAssertions.assertThat`, to the method, use a place-holder value returned by {@link Functions#parameter()}. | |
| 263 | * | |
| 264 | * That is, in order to create a function which computes sin using query a method {@link Math#sin(double)}, | |
| 265 | * you can do following | |
| 266 | * | |
| 267 | * [source, java] | |
| 268 | * ---- | |
| 269 | * public class Example | |
| 270 | * public void buildSinFunction() { | |
| 271 | * MethodQuery mq = classMethod(Math.class, "sin", parameter()); | |
| 272 | * Function<Double, Double> sin = call(mq); | |
| 273 | * System.out.println(sin(Math.PI/2)); | |
| 274 | * } | |
| 275 | * } | |
| 276 | * ---- | |
| 277 | * This prints {@code 1.0}. | |
| 278 | * | |
| 279 | * In case your arguments do not contain any {@link Parameter} object, the input | |
| 280 | * argument passed to the built function will be simply ignored. | |
| 281 | * | |
| 282 | * // @formatter:on | |
| 283 | * | |
| 284 | * @param targetClass A class | |
| 285 | * @param methodName A method name | |
| 286 | * @param arguments Arguments | |
| 287 | * @return A method query for static methods specified by arguments. | |
| 288 | * @see ReflUtils#findMethod(Class, String, Object[]) | |
| 289 | * @see Functions#parameter() | |
| 290 | */ | |
| 291 | public static MethodQuery classMethod(Class<?> targetClass, String methodName, Object... arguments) { | |
| 292 |
1
1. classMethod : replaced return value with null for com/github/valid8j/pcond/forms/Functions::classMethod → RUN_ERROR |
return MethodQuery.classMethod(targetClass, methodName, arguments); |
| 293 | } | |
| 294 | ||
| 295 | /** | |
| 296 | * // @formatter:off | |
| 297 | * Creates a {@link MethodQuery} object from given arguments to search for {@code static} methods. | |
| 298 | * Excepting that this method returns a query for instance methods, it is quite | |
| 299 | * similar to {@link Functions#classMethod(Class, String, Object[])}. | |
| 300 | * | |
| 301 | * This method is useful to build a function from an instance method. | |
| 302 | * That is, you can create a function which returns the length of a given string | |
| 303 | * from a method {@link String#length()} with a following code snippet. | |
| 304 | * | |
| 305 | * [source, java] | |
| 306 | * ---- | |
| 307 | * public void buildLengthFunction() { | |
| 308 | * Function<String, Integer> length = call(instanceMethod(parameter(), "length")); | |
| 309 | * } | |
| 310 | * ---- | |
| 311 | * | |
| 312 | * In case the {@code targetObject} is not an instance of {@link Parameter} and {@code arguments} | |
| 313 | * contain no {@code Parameter} object, the function will simply ignore the input passed to it. | |
| 314 | * | |
| 315 | * To pass an input value given to an entry point method, such as `TestAssertions.assertThat`, to the method, use a place-holder value returned by {@link Functions#parameter()}. | |
| 316 | * | |
| 317 | * // @formatter:on | |
| 318 | * | |
| 319 | * @param targetObject An object on which methods matching returned query should be invoked. | |
| 320 | * @param methodName A name of method. | |
| 321 | * @param arguments Arguments passed to the method. | |
| 322 | * @return A method query for instance methods specified by arguments. | |
| 323 | * @see Functions#classMethod(Class, String, Object[]) | |
| 324 | * @see Functions#parameter() | |
| 325 | */ | |
| 326 | public static MethodQuery instanceMethod(Object targetObject, String methodName, Object... arguments) { | |
| 327 |
1
1. instanceMethod : replaced return value with null for com/github/valid8j/pcond/forms/Functions::instanceMethod → KILLED |
return MethodQuery.instanceMethod(targetObject, methodName, arguments); |
| 328 | } | |
| 329 | ||
| 330 | /** | |
| 331 | * // @formatter:off | |
| 332 | * A short hand method to call | |
| 333 | * | |
| 334 | * [source, java] | |
| 335 | * --- | |
| 336 | * call(instanceMethod(object, methodName, args)) | |
| 337 | * --- | |
| 338 | * // @formatter:on | |
| 339 | * | |
| 340 | * To pass an input value given to an entry point method, such as `TestAssertions.assertThat`, to the method, use a place-holder value returned by {@link Functions#parameter()}. | |
| 341 | * | |
| 342 | * @param targetObject An object on which methods matching returned query should be invoked. | |
| 343 | * @param methodName A name of method. | |
| 344 | * @param arguments Arguments passed to the method. | |
| 345 | * @param <T> The type of the input to the returned function. | |
| 346 | * @param <R> The type of the output from the returned function. | |
| 347 | * @return The function that calls a method matching a query built from the given arguments. | |
| 348 | * @see Functions#call(MethodQuery) | |
| 349 | * @see Functions#instanceMethod(Object, String, Object[]) | |
| 350 | * @see Functions#parameter() | |
| 351 | */ | |
| 352 | private static <T, R> Function<T, R> callInstanceMethod(Object targetObject, String methodName, Object... arguments) { | |
| 353 |
1
1. callInstanceMethod : replaced return value with null for com/github/valid8j/pcond/forms/Functions::callInstanceMethod → RUN_ERROR |
return call(instanceMethod(targetObject, methodName, arguments)); |
| 354 | } | |
| 355 | ||
| 356 | /** | |
| 357 | * Returns a function that calls a method which matches the given {@code methodName} | |
| 358 | * and {@code args} on the object given as input to it. | |
| 359 | * | |
| 360 | * Note that method look up is done when the predicate is applied. | |
| 361 | * This means this method does not throw any exception by itself and in case | |
| 362 | * you give wrong {@code methodName} or {@code arguments}, an exception will be | |
| 363 | * thrown when the returned function is applied. | |
| 364 | * | |
| 365 | * // @formatter:off | |
| 366 | * [source, java] | |
| 367 | * ---- | |
| 368 | * public class Example { | |
| 369 | * public void method() { | |
| 370 | * assertThat(value, transform(call("toString")).check(isNotNull())); | |
| 371 | * } | |
| 372 | * } | |
| 373 | * ---- | |
| 374 | * | |
| 375 | * To pass an input value given to an entry point method, such as `TestAssertions.assertThat`, to the method, use a place-holder value returned by {@link Functions#parameter()}. | |
| 376 | * | |
| 377 | * // @formatter:on | |
| 378 | * | |
| 379 | * @param methodName The method name | |
| 380 | * @param arguments Arguments passed to the method. | |
| 381 | * @param <T> The type of input to the returned function | |
| 382 | * @param <R> The type of output from the returned function | |
| 383 | * @return A function that invokes the method matching the {@code methodName} and {@code args} | |
| 384 | * @see Functions#parameter() | |
| 385 | */ | |
| 386 | public static <T, R> Function<T, R> call(String methodName, Object... arguments) { | |
| 387 |
1
1. call : replaced return value with null for com/github/valid8j/pcond/forms/Functions::call → RUN_ERROR |
return callInstanceMethod(parameter(), methodName, arguments); |
| 388 | } | |
| 389 | ||
| 390 | /** | |
| 391 | * Returns a function that converts an input value to an exception object, which is thrown by `func`, when it is applied. | |
| 392 | * If it does not throw an exception, or even if thrown, it is not an instance of {@code exceptionClass}, an assertion executed inside this method will fail and an exception | |
| 393 | * to indicate it will be thrown. | |
| 394 | * The exception will be typically an {@link AssertionError}. | |
| 395 | * | |
| 396 | * @param exceptionClass An exception class to be thrown. | |
| 397 | * @param func A function to be exercised | |
| 398 | * @param <T> A type of exception value to be thrown by {@code func}. | |
| 399 | * @param <E> An input value type of {@code func}. | |
| 400 | * @return A function that maps an input value to an exception. | |
| 401 | */ | |
| 402 | @SuppressWarnings("unchecked") | |
| 403 | public static <T, E extends Throwable> Function<T, E> expectingException(Class<E> exceptionClass, Function<? super T, ?> func) { | |
| 404 |
1
1. expectingException : replaced return value with null for com/github/valid8j/pcond/forms/Functions::expectingException → KILLED |
return Printables.function( |
| 405 |
1
1. lambda$expectingException$5 : replaced return value with "" for com/github/valid8j/pcond/forms/Functions::lambda$expectingException$5 → SURVIVED |
() -> String.format("expectingException(%s,%s)", exceptionClass.getSimpleName(), func), |
| 406 | in -> { | |
| 407 | Object out; | |
| 408 | try { | |
| 409 | out = func.apply(in); | |
| 410 | } catch (Throwable e) { | |
| 411 |
1
1. lambda$expectingException$6 : removed call to com/github/valid8j/pcond/validator/Validator::assertThat → KILLED |
Validator.instance().assertThat(e, isInstanceOf(exceptionClass)); |
| 412 |
1
1. lambda$expectingException$6 : replaced return value with null for com/github/valid8j/pcond/forms/Functions::lambda$expectingException$6 → KILLED |
return (E) e; |
| 413 | } | |
| 414 |
1
1. lambda$expectingException$6 : removed call to com/github/valid8j/pcond/validator/Validator::assertThat → KILLED |
Validator.instance().assertThat( |
| 415 | String.format("%s(%s)->%s", func, InternalUtils.formatObject(in, 12), InternalUtils.formatObject(out, 12)), | |
| 416 | allOf(exceptionThrown(), exceptionClassWas(exceptionClass))); | |
| 417 | throw new AssertionError("A line that shouldn't be reached. File a ticket."); | |
| 418 | }); | |
| 419 | } | |
| 420 | ||
| 421 | /** | |
| 422 | * Returns a {@link Parameter} object, which is used in combination with {@link Functions#instanceMethod(Object, String, Object[])}, | |
| 423 | * {@link Functions#classMethod(Class, String, Object[])}, or their shorthand methods. | |
| 424 | * The object returned by this method is replaced with the actual input value passed to a function built | |
| 425 | * through {@link Functions#call(MethodQuery)} or {@link Predicates#callp(MethodQuery)} | |
| 426 | * when it is applied. | |
| 427 | * | |
| 428 | * @return a {@code Parameter} object | |
| 429 | * @see Functions#classMethod(Class, String, Object[]) | |
| 430 | * @see Functions#instanceMethod(Object, String, Object[]) | |
| 431 | * @see Functions#call(MethodQuery) | |
| 432 | * @see Functions#call(String, Object[]) | |
| 433 | * @see Predicates#callp(MethodQuery) | |
| 434 | * @see Predicates#callp(String, Object[]) | |
| 435 | */ | |
| 436 | public static Parameter parameter() { | |
| 437 |
1
1. parameter : replaced return value with null for com/github/valid8j/pcond/forms/Functions::parameter → KILLED |
return Parameter.INSTANCE; |
| 438 | } | |
| 439 | ||
| 440 | private static Predicate<Object> exceptionThrown() { | |
| 441 |
2
1. lambda$exceptionThrown$7 : replaced boolean return with true for com/github/valid8j/pcond/forms/Functions::lambda$exceptionThrown$7 → SURVIVED 2. exceptionThrown : replaced return value with null for com/github/valid8j/pcond/forms/Functions::exceptionThrown → KILLED |
return Printables.predicate("exceptionThrown", v -> false); |
| 442 | } | |
| 443 | ||
| 444 | private static Predicate<Object> exceptionClassWas(Class<? extends Throwable> exceptionClass) { | |
| 445 |
3
1. exceptionClassWas : replaced return value with null for com/github/valid8j/pcond/forms/Functions::exceptionClassWas → KILLED 2. lambda$exceptionClassWas$8 : replaced return value with "" for com/github/valid8j/pcond/forms/Functions::lambda$exceptionClassWas$8 → KILLED 3. lambda$exceptionClassWas$9 : replaced boolean return with true for com/github/valid8j/pcond/forms/Functions::lambda$exceptionClassWas$9 → KILLED |
return Printables.predicate(() -> "exceptionClass:" + requireNonNull(exceptionClass).getSimpleName(), v -> false); |
| 446 | } | |
| 447 | ||
| 448 | /** | |
| 449 | * A method to return a value for a "casting placeholder value". | |
| 450 | * | |
| 451 | * @param <E> Type to cast to. | |
| 452 | * @return Casting placeholder value | |
| 453 | */ | |
| 454 | public static <E> E value() { | |
| 455 | return null; | |
| 456 | } | |
| 457 | } | |
Mutations | ||
| 46 |
1.1 |
|
| 57 |
1.1 |
|
| 66 |
1.1 |
|
| 72 |
1.1 |
|
| 81 |
1.1 |
|
| 91 |
1.1 |
|
| 102 |
1.1 |
|
| 113 |
1.1 |
|
| 124 |
1.1 |
|
| 143 |
1.1 |
|
| 154 |
1.1 |
|
| 164 |
1.1 |
|
| 173 |
1.1 |
|
| 194 |
1.1 |
|
| 195 |
1.1 |
|
| 198 |
1.1 2.2 |
|
| 199 |
1.1 2.2 |
|
| 214 |
1.1 |
|
| 225 |
1.1 |
|
| 229 |
1.1 |
|
| 246 |
1.1 2.2 3.3 4.4 5.5 |
|
| 292 |
1.1 |
|
| 327 |
1.1 |
|
| 353 |
1.1 |
|
| 387 |
1.1 |
|
| 404 |
1.1 |
|
| 405 |
1.1 |
|
| 411 |
1.1 |
|
| 412 |
1.1 |
|
| 414 |
1.1 |
|
| 437 |
1.1 |
|
| 441 |
1.1 2.2 |
|
| 445 |
1.1 2.2 3.3 |