[JAVA-12620] Split core-java-exceptions module

This commit is contained in:
Haroon Khan
2022-06-14 21:56:25 +01:00
parent e31a4dff8d
commit 18bcb72f85
8 changed files with 30 additions and 18 deletions

View File

@@ -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");
}
}

View File

@@ -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");
}
}