ThrowingRunnable.java

1
/*
2
 * Copyright 2014-2016 Grzegorz Piwowarek, https://4comprehension.com/
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 * https://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
package com.pivovarit.function;
17
18
import java.util.Objects;
19
20
import static java.util.Objects.requireNonNull;
21
22
/**
23
 * Represents an action that can be performed.
24
 * Function might throw a checked exception instance.
25
 *
26
 * @param <E> the type of the thrown checked exception
27
 *
28
 * @author Grzegorz Piwowarek
29
 */
30
@FunctionalInterface
31
public interface ThrowingRunnable<E extends Exception> {
32
    /**
33
     * Performs this operation.
34
     *
35
     * @throws E the checked exception type
36
     */
37
    void run() throws E;
38
39
    /**
40
     * Returns a new Runnable instance which wraps the thrown checked exception instance into a {@link CheckedException}
41
     *
42
     * @param runnable the ThrowingRunnable to wrap
43
     * @return Runnable instance that wraps the checked exception into a {@link CheckedException}
44
     */
45
    static Runnable unchecked(ThrowingRunnable<?> runnable) {
46
        requireNonNull(runnable);
47 1 1. unchecked : replaced return value with null for com/pivovarit/function/ThrowingRunnable::unchecked → KILLED
        return () -> {
48
            try {
49 1 1. lambda$unchecked$0 : removed call to com/pivovarit/function/ThrowingRunnable::run → KILLED
                runnable.run();
50
            } catch (final Exception e) {
51
                throw new CheckedException(e);
52
            }
53
        };
54
    }
55
56
    /**
57
     * Returns a new Runnable instance which rethrows the checked exception using the Sneaky Throws pattern
58
     *
59
     * @param runnable the ThrowingRunnable to wrap
60
     * @return Runnable instance that rethrows the checked exception using the Sneaky Throws pattern
61
     */
62
    static Runnable sneaky(ThrowingRunnable<?> runnable) {
63
        Objects.requireNonNull(runnable);
64 1 1. sneaky : replaced return value with null for com/pivovarit/function/ThrowingRunnable::sneaky → KILLED
        return () -> {
65
            try {
66 1 1. lambda$sneaky$0 : removed call to com/pivovarit/function/ThrowingRunnable::run → KILLED
                runnable.run();
67
            } catch (Exception e) {
68
                SneakyThrowUtil.sneakyThrow(e);
69
            }
70
        };
71
    }
72
}

Mutations

47

1.1
Location : unchecked
Killed by : com.pivovarit.function.ThrowingRunnableTest.[engine:junit-jupiter]/[class:com.pivovarit.function.ThrowingRunnableTest]/[method:shouldRunWhenNoExceptionThrownWithUnchecked()]
replaced return value with null for com/pivovarit/function/ThrowingRunnable::unchecked → KILLED

49

1.1
Location : lambda$unchecked$0
Killed by : com.pivovarit.function.ThrowingRunnableTest.[engine:junit-jupiter]/[class:com.pivovarit.function.ThrowingRunnableTest]/[method:shouldRunWhenNoExceptionThrownWithUnchecked()]
removed call to com/pivovarit/function/ThrowingRunnable::run → KILLED

64

1.1
Location : sneaky
Killed by : com.pivovarit.function.ThrowingRunnableTest.[engine:junit-jupiter]/[class:com.pivovarit.function.ThrowingRunnableTest]/[method:shouldSneakyThrow()]
replaced return value with null for com/pivovarit/function/ThrowingRunnable::sneaky → KILLED

66

1.1
Location : lambda$sneaky$0
Killed by : com.pivovarit.function.ThrowingRunnableTest.[engine:junit-jupiter]/[class:com.pivovarit.function.ThrowingRunnableTest]/[method:shouldSneakyThrow()]
removed call to com/pivovarit/function/ThrowingRunnable::run → KILLED

Active mutators

Tests examined


Report generated by PIT 1.30.0 support