This commit is contained in:
Loredana
2020-07-05 19:32:46 +03:00
13 changed files with 90 additions and 2 deletions
-1
View File
@@ -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();
}
}