diff --git a/core-java-lang/src/main/java/com/baeldung/error/ErrorGenerator.java b/core-java-lang/src/main/java/com/baeldung/error/ErrorGenerator.java deleted file mode 100644 index 58cbe22df5..0000000000 --- a/core-java-lang/src/main/java/com/baeldung/error/ErrorGenerator.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.baeldung.error; - -public class ErrorGenerator { - public void throwException() throws Exception { - throw new Exception("checked"); - } - - public void throwRuntimeException() { - throw new RuntimeException("unchecked"); - } - - public void throwError() { - throw new Error("unchecked"); - } -} diff --git a/core-java-lang/src/test/java/com/baeldung/error/ErrorGeneratorUnitTest.java b/core-java-lang/src/test/java/com/baeldung/error/ErrorGeneratorUnitTest.java deleted file mode 100644 index 2a7c24f5fa..0000000000 --- a/core-java-lang/src/test/java/com/baeldung/error/ErrorGeneratorUnitTest.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.baeldung.error; - -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -public class ErrorGeneratorUnitTest { - - private ErrorGenerator errorGenerator; - - @Before - public void setUp() { - errorGenerator = new ErrorGenerator(); - } - - @Test - public void whenCheckedException_thenIsCaughtByCatchException() { - try { - errorGenerator.throwException(); - } catch (Exception e) { - // caught! -> test pass - } - } - - @Test - public void whenUncheckedException_thenIsCaughtByCatchException() { - try { - errorGenerator.throwRuntimeException(); - } catch (Exception e) { - // caught! -> test pass - } - } - - @Test(expected = Error.class) - public void whenError_thenIsNotCaughtByCatchException() { - try { - errorGenerator.throwError(); - } catch (Exception e) { - Assert.fail(); // errors are not caught by catch exception - } - } - - @Test - public void whenError_thenIsCaughtByCatchError() { - try { - errorGenerator.throwError(); - } catch (Error e) { - // caught! -> test pass - } - } -} \ No newline at end of file diff --git a/core-java-modules/core-java-exceptions/src/test/java/com/baeldung/exception/error/ErrorGeneratorUnitTest.java b/core-java-modules/core-java-exceptions/src/test/java/com/baeldung/exception/error/ErrorGeneratorUnitTest.java new file mode 100644 index 0000000000..de56fb7113 --- /dev/null +++ b/core-java-modules/core-java-exceptions/src/test/java/com/baeldung/exception/error/ErrorGeneratorUnitTest.java @@ -0,0 +1,26 @@ +package com.baeldung.error; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +public class ErrorGeneratorUnitTest { + + @Test(expected = AssertionError.class) + public void whenError_thenIsNotCaughtByCatchException() { + try { + throw new AssertionError(); + } catch (Exception e) { + Assert.fail(); // errors are not caught by catch exception + } + } + + @Test + public void whenError_thenIsCaughtByCatchError() { + try { + throw new AssertionError(); + } catch (Error e) { + // caught! -> test pass + } + } +} \ No newline at end of file