Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
assertArg
overload for consumers throwing checked exceptions (#…
- Loading branch information
1 parent
d6e4f07
commit 6e0c228
Showing
3 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright (c) 2023 Mockito contributors | ||
* This program is made available under the terms of the MIT License. | ||
*/ | ||
package org.mockito; | ||
|
||
import java.util.function.Consumer; | ||
|
||
@SuppressWarnings("FunctionalInterfaceMethodChanged") | ||
@FunctionalInterface | ||
public interface ThrowingConsumer<T> extends Consumer<T> { | ||
@Override | ||
default void accept(final T input) { | ||
try { | ||
acceptThrows(input); | ||
} catch (final RuntimeException | AssertionError e) { | ||
throw e; | ||
} catch (Throwable e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
void acceptThrows(T input) throws Throwable; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters