[JAVA-12620] Split core-java-exceptions module
This commit is contained in:
@@ -1,22 +0,0 @@
|
||||
package com.baeldung.exceptions.sneakythrows;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
|
||||
public class SneakyThrowsExamples {
|
||||
|
||||
public static <E extends Throwable> void sneakyThrow(Throwable e) throws E {
|
||||
throw (E) e;
|
||||
}
|
||||
|
||||
public static void throwSneakyIOException() {
|
||||
sneakyThrow(new IOException("sneaky"));
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public static void throwSneakyIOExceptionUsingLombok() {
|
||||
throw new IOException("lombok sneaky");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package com.baeldung.exceptions.sneakythrows;
|
||||
|
||||
import static com.baeldung.exceptions.sneakythrows.SneakyThrowsExamples.throwSneakyIOException;
|
||||
import static com.baeldung.exceptions.sneakythrows.SneakyThrowsExamples.throwSneakyIOExceptionUsingLombok;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class SneakyThrowsExamplesUnitTest {
|
||||
|
||||
@Test
|
||||
public void throwSneakyIOException_IOExceptionShouldBeThrown() {
|
||||
assertThatThrownBy(() -> throwSneakyIOException())
|
||||
.isInstanceOf(IOException.class)
|
||||
.hasMessage("sneaky")
|
||||
.hasStackTraceContaining("SneakyThrowsExamples.throwSneakyIOException");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void throwSneakyIOExceptionUsingLombok_IOExceptionShouldBeThrown() {
|
||||
assertThatThrownBy(() -> throwSneakyIOExceptionUsingLombok())
|
||||
.isInstanceOf(IOException.class)
|
||||
.hasMessage("lombok sneaky")
|
||||
.hasStackTraceContaining("SneakyThrowsExamples.throwSneakyIOExceptionUsingLombok");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user