Merge branch 'guava' of https://github.com/eugenp/tutorials
This commit is contained in:
@@ -12,5 +12,4 @@ This module contains articles a Google Guava
|
||||
- [Guide to Mathematical Utilities in Guava](https://www.baeldung.com/guava-math)
|
||||
- [Bloom Filter in Java using Guava](https://www.baeldung.com/guava-bloom-filter)
|
||||
- [Quick Guide to the Guava RateLimiter](https://www.baeldung.com/guava-rate-limiter)
|
||||
- [Introduction to Guava Throwables](https://www.baeldung.com/guava-throwables)
|
||||
- [Guava Cache](https://www.baeldung.com/guava-cache)
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
package com.baeldung.guava;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class ThrowablesUnitTest {
|
||||
|
||||
@Test(expected = RuntimeException.class)
|
||||
public void whenThrowable_shouldWrapItInRuntimeException() throws Exception {
|
||||
try {
|
||||
throwThrowable(Throwable::new);
|
||||
} catch (Throwable t) {
|
||||
Throwables.propagateIfPossible(t, Exception.class);
|
||||
throw new RuntimeException(t);
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = Error.class)
|
||||
public void whenError_shouldPropagateAsIs() throws Exception {
|
||||
try {
|
||||
throwThrowable(Error::new);
|
||||
} catch (Throwable t) {
|
||||
Throwables.propagateIfPossible(t, Exception.class);
|
||||
throw new RuntimeException(t);
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = Exception.class)
|
||||
public void whenException_shouldPropagateAsIs() throws Exception {
|
||||
try {
|
||||
throwThrowable(Exception::new);
|
||||
} catch (Throwable t) {
|
||||
Throwables.propagateIfPossible(t, Exception.class);
|
||||
throw new RuntimeException(t);
|
||||
}
|
||||
}
|
||||
|
||||
private <T extends Throwable> void throwThrowable(Supplier<T> exceptionSupplier) throws Throwable {
|
||||
throw exceptionSupplier.get();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user