Skip to content

Commit 1c1885d

Browse files
buddhini81pedja4
authored andcommitted
Code for BAEL-876 (eugenp#1800)
* Create new folder stackoverflowerror * Committing code for BAEL-876 * Delete the file * Feature/beal 642 classtoinstancemap (eugenp#1801) * BAEL-642 ClassToInstanceMap example added * BAEL-642 Improved example for ClassToInstanceMap * Reverted change in pom.xml * BAEL-642 Move the ClassToInstanceMap examples to guava module as unit tests * BAEL-642 changed test names to given_when * Fix tests * Fix tests * BAEL-521 (eugenp#1799) * refactor: Moved JHipster Monolithic to a subfolder * feat: Add JHipster Microservice modules closes BAEL-521 * BAEL-926 Upgrade Junit 5 dependencies to use M4 (eugenp#1802) * BAEL-88 Testing in Spring Boot * BAEL-88 Integration tests fixed. * BAEL-905 Improvement task for spring boot testing * BAEL-905 Improvement task for spring boot testing * BAEL-926 Upgrade Junit 5 dependencies to use M4 * BAEL-252 A Java Client to Consume a WebSockets API (eugenp#1805) * @BAEL-252 - Initial checkin * BAEL-252 : Added junit tests * @BAEL-252(A Java Client to consume a WebSockets API) : Fixed the junit name * BAEL-252 A Java Client to Consume a WebSockets API Fixed junit test name as per the standard * Double brace (eugenp#1798) * BAL-36 File size api in java and apache commons IO * BAEL-282 grep in java - fixes after code review * BAEL-519 Added support for disruptor library * BAEL-519 Added support for disruptor library * BAEL-519 Added support for disruptor library * BAEL-519 Added support for disruptor library * BAEL-519 Added support for disruptor library * BAEL-519 Added support for disruptor library * BAEL-519 Added support for disruptor * BAEL-519 Moved all supporting classes to main source * BAEL-519 Moved all supporting classes to main source * BAEL-519 Moved asserts and test classes in test folder. * BAEL-519 moved test related producer and consumer to src. * BAEL-586 Guide to Guava BiMap. * BAEL-587 formatted code. * BAEL-519 LMAX Disruptor * BAEL-587 resolved merge * BAEL-587 Resolved merge * BAEL-519 Removed disruptor link. * BAEL-519 Reverted Guava changes * RFQ-587 Added disruptor as a separate module. * BAEL-519 Disruptor changes. * BAEL-519 Removed disruptor from core-java module. * BAEL-729 Expose additional information programmatically in /info endpoint of actuator. * BAEL-824 Usage of Double braces in Java. * Deleted sample project * updated test and names. * BAEL-870 How to Call a Method During Runtime Using Reflection (eugenp#1806) * small fix (eugenp#1809) * BAEL-870 README (eugenp#1810) * Add files via upload * Update pom.xml * Update RunGuice.java * Update Communication.java * Update CommunicationMode.java * Update DefaultCommunicator.java * Update EmailCommunicationMode.java * Update IMCommunicationMode.java * Update SMSCommunicationMode.java * Update MessageLogger.java * Update MessageSentLoggable.java * Update AOPModule.java * Update BasicModule.java * Update CommunicationModel.java * Update Communicator.java * Update BasicModule.java * Update RunGuice.java * Update MessageLogger.java * Update Communicator.java * Update pom.xml * BAEL-278: Updated README.md * BAEL-554: Add and update README.md files * Update pom.xml * Update pom.xml * Update pom.xml * BAEL-345: fixed assertion * BAEL-109: Updated README.md * BAEL-345: Added README.md * Reinstating reactor-core module in root-level pom * BAEL-393: Adding guide-intro module to root pom * BAEL-9: Updated README.md * BAEL-157: README.md updated * Changed project name * Update RunGuice.java Removed references to message logging and output * Update Communication.java Removed message logging-related code * BAEL-566: Updated README.md * New project name * BAEL-393: removing guice-intro directory * BAEL-393: renamed module guice-intro to guice in root pom.xml * BAEL-393 and BAEL-541 README.md files * BAEL-731: Updated README.md * BAEL-680: renamed test methods * BAEL-714: Updated README.md * BAEL-737: Updated README.md * BAEL-680 and BAEL-756 README.md updates * BAEL-666: Updated README * BAEL-415: Custom Scope * BAEL-415: Custom Scope - renamed classes to reflect TenantScope * README file updates for BAEL-723, BAEL-763, and BAEL-415 * BAEL-735: README * BAEL-567: README * BAEL-736: README * BAEL-766: Update README * BAEL-555: README update * BAEL-761: README update * BAEL-742: Stripe API for Java README file * BAEL-86: Correction to README file * BAEL-828: Updated README.md * BAEL-830: Updated README * BAEL-870: Switched from TestNG to JUnit due to build errors * BAEL-870: Update README * DoubleBraceTest refactor * Bael 883 phaser (eugenp#1794) * BAEL-883 Code for the Phaser * BAEL-883 remove comments * Refactoring code for BAEL-876 * Refactoring code for BAEL-876 * Refactoring code for BAEL-876 * Delete the class * Refactor code for BAEL-876 * Refactor code for BAEL-876 * Refactor code for BAEL-876 * Create new folder * Unit tests for BAEL-876 * Delete .test * BAEL-876 Formatting
1 parent 1303533 commit 1c1885d

10 files changed

Lines changed: 154 additions & 0 deletions
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.baeldung.stackoverflowerror;
2+
3+
public class AccountHolder {
4+
private String firstName;
5+
private String lastName;
6+
7+
AccountHolder jointAccountHolder = new AccountHolder();
8+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.baeldung.stackoverflowerror;
2+
3+
public class ClassOne {
4+
private int oneValue;
5+
private ClassTwo clsTwoInstance = null;
6+
7+
public ClassOne() {
8+
oneValue = 0;
9+
clsTwoInstance = new ClassTwo();
10+
}
11+
12+
public ClassOne(int oneValue, ClassTwo clsTwoInstance) {
13+
this.oneValue = oneValue;
14+
this.clsTwoInstance = clsTwoInstance;
15+
}
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.baeldung.stackoverflowerror;
2+
3+
public class ClassTwo {
4+
private int twoValue;
5+
private ClassOne clsOneInstance = null;
6+
7+
public ClassTwo() {
8+
twoValue = 10;
9+
clsOneInstance = new ClassOne();
10+
}
11+
12+
public ClassTwo(int twoValue, ClassOne clsOneInstance) {
13+
this.twoValue = twoValue;
14+
this.clsOneInstance = clsOneInstance;
15+
}
16+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.baeldung.stackoverflowerror;
2+
3+
public class InfiniteRecursionWithTerminationCondition {
4+
public int calculateFactorial(final int number) {
5+
return number == 1 ? 1 : number * calculateFactorial(number - 1);
6+
}
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.baeldung.stackoverflowerror;
2+
3+
public class RecursionWithCorrectTerminationCondition {
4+
public static int calculateFactorial(final int number) {
5+
return number <= 1 ? 1 : number * calculateFactorial(number - 1);
6+
}
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.baeldung.stackoverflowerror;
2+
3+
public class UnintendedInfiniteRecursion {
4+
public int calculateFactorial(int number) {
5+
return number * calculateFactorial(number - 1);
6+
}
7+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.baeldung.stackoverflowerror;
2+
3+
import org.junit.Test;
4+
5+
public class AccountHolderUnitTest {
6+
@Test(expected = StackOverflowError.class)
7+
public void whenInstanciatingAccountHolder_thenThrowsException() {
8+
AccountHolder holder = new AccountHolder();
9+
}
10+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.baeldung.stackoverflowerror;
2+
3+
import static org.junit.Assert.fail;
4+
5+
import org.junit.Test;
6+
7+
public class CyclicDependancyUnitTest {
8+
@Test
9+
public void whenInstanciatingClassOne_thenThrowsException() {
10+
try {
11+
ClassOne obj = new ClassOne();
12+
fail();
13+
} catch (StackOverflowError soe) {
14+
soe.printStackTrace();
15+
}
16+
}
17+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.baeldung.stackoverflowerror;
2+
3+
import static junit.framework.TestCase.assertEquals;
4+
import static org.junit.Assert.fail;
5+
6+
import org.junit.Test;
7+
8+
public class InfiniteRecursionWithTerminationConditionUnitTest {
9+
@Test
10+
public void givenPositiveIntNoOne_whenCalcFact_thenThrowsException() {
11+
int numToCalcFactorial = 1;
12+
InfiniteRecursionWithTerminationCondition irtc = new InfiniteRecursionWithTerminationCondition();
13+
14+
assertEquals(1, irtc.calculateFactorial(numToCalcFactorial));
15+
}
16+
17+
@Test
18+
public void givenPositiveIntGtOne_whenCalcFact_thenThrowsException() {
19+
int numToCalcFactorial = 5;
20+
InfiniteRecursionWithTerminationCondition irtc = new InfiniteRecursionWithTerminationCondition();
21+
22+
assertEquals(120, irtc.calculateFactorial(numToCalcFactorial));
23+
}
24+
25+
@Test
26+
public void givenNegativeInt_whenCalcFact_thenThrowsException() {
27+
try {
28+
int numToCalcFactorial = -1;
29+
InfiniteRecursionWithTerminationCondition irtc = new InfiniteRecursionWithTerminationCondition();
30+
31+
irtc.calculateFactorial(numToCalcFactorial);
32+
fail();
33+
} catch (StackOverflowError soe) {
34+
soe.printStackTrace();
35+
}
36+
}
37+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.baeldung.stackoverflowerror;
2+
3+
import org.junit.Test;
4+
5+
public class UnintendedInfiniteRecursionUnitTest {
6+
@Test(expected = StackOverflowError.class)
7+
public void givenPositiveIntNoOne_whenCalFact_thenThrowsException() {
8+
int numToCalcFactorial = 1;
9+
UnintendedInfiniteRecursion uir = new UnintendedInfiniteRecursion();
10+
11+
uir.calculateFactorial(numToCalcFactorial);
12+
}
13+
14+
@Test(expected = StackOverflowError.class)
15+
public void givenPositiveIntGtOne_whenCalcFact_thenThrowsException() {
16+
int numToCalcFactorial = 2;
17+
UnintendedInfiniteRecursion uir = new UnintendedInfiniteRecursion();
18+
19+
uir.calculateFactorial(numToCalcFactorial);
20+
}
21+
22+
@Test(expected = StackOverflowError.class)
23+
public void givenNegativeInt_whenCalcFact_thenThrowsException() {
24+
int numToCalcFactorial = -1;
25+
UnintendedInfiniteRecursion uir = new UnintendedInfiniteRecursion();
26+
27+
uir.calculateFactorial(numToCalcFactorial);
28+
}
29+
}

0 commit comments

Comments
 (0)