Changes for "Guide to finally in Java" (BAEL-3526) (#8237)

* Adding files for finally keyword

* Adding returnFromCatch example.

* Adding empty braces instead of dangling ;

* Return from try, removing the catch block.

* moving to to core-java module

* moving to core-java-lang-2
This commit is contained in:
rahulgul8
2020-01-01 16:41:12 +05:30
committed by ashleyfrieze
parent 829e4f780e
commit 11aa367292
5 changed files with 181 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
package com.baeldung.finallykeyword;
import static org.junit.Assert.*;
import org.junit.Test;
public class PitfallsWhenUsingFinallyUnitTest {
PitfallsWhenUsingFinally instance = new PitfallsWhenUsingFinally();
@Test
public void testIgnoresException() {
String result = instance.disregardsUnCaughtException();
assertEquals("from finally", result);
}
@Test
public void testIgnoresOtherReturns() {
String result = instance.ignoringOtherReturns();
assertEquals("from finally", result);
}
@Test(expected = RuntimeException.class)
public void testThrowsException() {
instance.throwsException();
}
}