JUnit5 test classes and methods should have default package visibility

This commit is contained in:
Alex Golub 2022-04-21 10:29:26 +03:00
parent 4bcb36ff41
commit f1801bbd6f
1 changed files with 7 additions and 5 deletions

View File

@ -1,13 +1,14 @@
package com.baeldung.assertexception; package com.baeldung.assertexception;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test; class ExceptionAssertionUnitTest {
public class ExceptionAssertionUnitTest {
@Test @Test
public void whenExceptionThrown_thenAssertionSucceeds() { void whenExceptionThrown_thenAssertionSucceeds() {
Exception exception = assertThrows(NumberFormatException.class, () -> { Exception exception = assertThrows(NumberFormatException.class, () -> {
Integer.parseInt("1a"); Integer.parseInt("1a");
}); });
@ -19,7 +20,7 @@ public class ExceptionAssertionUnitTest {
} }
@Test @Test
public void whenDerivedExceptionThrown_thenAssertionSucceds() { void whenDerivedExceptionThrown_thenAssertionSucceds() {
Exception exception = assertThrows(RuntimeException.class, () -> { Exception exception = assertThrows(RuntimeException.class, () -> {
Integer.parseInt("1a"); Integer.parseInt("1a");
}); });
@ -29,4 +30,5 @@ public class ExceptionAssertionUnitTest {
assertTrue(actualMessage.contains(expectedMessage)); assertTrue(actualMessage.contains(expectedMessage));
} }
}
}