From f1801bbd6f7c824e069b81847594808cf15499cd Mon Sep 17 00:00:00 2001 From: Alex Golub Date: Thu, 21 Apr 2022 10:29:26 +0300 Subject: [PATCH 1/3] JUnit5 test classes and methods should have default package visibility --- .../assertexception/ExceptionAssertionUnitTest.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/testing-modules/junit-5-basics/src/test/java/com/baeldung/assertexception/ExceptionAssertionUnitTest.java b/testing-modules/junit-5-basics/src/test/java/com/baeldung/assertexception/ExceptionAssertionUnitTest.java index ee2f696408..32e0e4a1cb 100644 --- a/testing-modules/junit-5-basics/src/test/java/com/baeldung/assertexception/ExceptionAssertionUnitTest.java +++ b/testing-modules/junit-5-basics/src/test/java/com/baeldung/assertexception/ExceptionAssertionUnitTest.java @@ -1,13 +1,14 @@ 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.assertTrue; -import org.junit.jupiter.api.Test; +class ExceptionAssertionUnitTest { -public class ExceptionAssertionUnitTest { @Test - public void whenExceptionThrown_thenAssertionSucceeds() { + void whenExceptionThrown_thenAssertionSucceeds() { Exception exception = assertThrows(NumberFormatException.class, () -> { Integer.parseInt("1a"); }); @@ -19,7 +20,7 @@ public class ExceptionAssertionUnitTest { } @Test - public void whenDerivedExceptionThrown_thenAssertionSucceds() { + void whenDerivedExceptionThrown_thenAssertionSucceds() { Exception exception = assertThrows(RuntimeException.class, () -> { Integer.parseInt("1a"); }); @@ -29,4 +30,5 @@ public class ExceptionAssertionUnitTest { assertTrue(actualMessage.contains(expectedMessage)); } -} \ No newline at end of file + +} From 0af6112abf7cd85fda1bda273df2e22e60a3baa1 Mon Sep 17 00:00:00 2001 From: Alex Golub Date: Thu, 21 Apr 2022 10:30:28 +0300 Subject: [PATCH 2/3] Delete redundant curly braces when using single lambda statement --- .../assertexception/ExceptionAssertionUnitTest.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/testing-modules/junit-5-basics/src/test/java/com/baeldung/assertexception/ExceptionAssertionUnitTest.java b/testing-modules/junit-5-basics/src/test/java/com/baeldung/assertexception/ExceptionAssertionUnitTest.java index 32e0e4a1cb..4a9e7e7f84 100644 --- a/testing-modules/junit-5-basics/src/test/java/com/baeldung/assertexception/ExceptionAssertionUnitTest.java +++ b/testing-modules/junit-5-basics/src/test/java/com/baeldung/assertexception/ExceptionAssertionUnitTest.java @@ -9,9 +9,7 @@ class ExceptionAssertionUnitTest { @Test void whenExceptionThrown_thenAssertionSucceeds() { - Exception exception = assertThrows(NumberFormatException.class, () -> { - Integer.parseInt("1a"); - }); + Exception exception = assertThrows(NumberFormatException.class, () -> Integer.parseInt("1a")); String expectedMessage = "For input string"; String actualMessage = exception.getMessage(); @@ -21,9 +19,7 @@ class ExceptionAssertionUnitTest { @Test void whenDerivedExceptionThrown_thenAssertionSucceds() { - Exception exception = assertThrows(RuntimeException.class, () -> { - Integer.parseInt("1a"); - }); + Exception exception = assertThrows(RuntimeException.class, () -> Integer.parseInt("1a")); String expectedMessage = "For input string"; String actualMessage = exception.getMessage(); From 95aff67d58d1e0eefd916839f33ed007777dc654 Mon Sep 17 00:00:00 2001 From: Alex Golub Date: Thu, 21 Apr 2022 10:30:44 +0300 Subject: [PATCH 3/3] Method name typo --- .../baeldung/assertexception/ExceptionAssertionUnitTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing-modules/junit-5-basics/src/test/java/com/baeldung/assertexception/ExceptionAssertionUnitTest.java b/testing-modules/junit-5-basics/src/test/java/com/baeldung/assertexception/ExceptionAssertionUnitTest.java index 4a9e7e7f84..5203a3f202 100644 --- a/testing-modules/junit-5-basics/src/test/java/com/baeldung/assertexception/ExceptionAssertionUnitTest.java +++ b/testing-modules/junit-5-basics/src/test/java/com/baeldung/assertexception/ExceptionAssertionUnitTest.java @@ -18,7 +18,7 @@ class ExceptionAssertionUnitTest { } @Test - void whenDerivedExceptionThrown_thenAssertionSucceds() { + void whenDerivedExceptionThrown_thenAssertionSucceeds() { Exception exception = assertThrows(RuntimeException.class, () -> Integer.parseInt("1a")); String expectedMessage = "For input string";