Code for BAEL-876 (#1800)
* Create new folder stackoverflowerror * Committing code for BAEL-876 * Delete the file * Feature/beal 642 classtoinstancemap (#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 (#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 (#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 (#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 (#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 (#1806) * small fix (#1809) * BAEL-870 README (#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 (#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
This commit is contained in:
parent
13035331e3
commit
1c1885d37a
|
@ -0,0 +1,8 @@
|
|||
package com.baeldung.stackoverflowerror;
|
||||
|
||||
public class AccountHolder {
|
||||
private String firstName;
|
||||
private String lastName;
|
||||
|
||||
AccountHolder jointAccountHolder = new AccountHolder();
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package com.baeldung.stackoverflowerror;
|
||||
|
||||
public class ClassOne {
|
||||
private int oneValue;
|
||||
private ClassTwo clsTwoInstance = null;
|
||||
|
||||
public ClassOne() {
|
||||
oneValue = 0;
|
||||
clsTwoInstance = new ClassTwo();
|
||||
}
|
||||
|
||||
public ClassOne(int oneValue, ClassTwo clsTwoInstance) {
|
||||
this.oneValue = oneValue;
|
||||
this.clsTwoInstance = clsTwoInstance;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package com.baeldung.stackoverflowerror;
|
||||
|
||||
public class ClassTwo {
|
||||
private int twoValue;
|
||||
private ClassOne clsOneInstance = null;
|
||||
|
||||
public ClassTwo() {
|
||||
twoValue = 10;
|
||||
clsOneInstance = new ClassOne();
|
||||
}
|
||||
|
||||
public ClassTwo(int twoValue, ClassOne clsOneInstance) {
|
||||
this.twoValue = twoValue;
|
||||
this.clsOneInstance = clsOneInstance;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package com.baeldung.stackoverflowerror;
|
||||
|
||||
public class InfiniteRecursionWithTerminationCondition {
|
||||
public int calculateFactorial(final int number) {
|
||||
return number == 1 ? 1 : number * calculateFactorial(number - 1);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package com.baeldung.stackoverflowerror;
|
||||
|
||||
public class RecursionWithCorrectTerminationCondition {
|
||||
public static int calculateFactorial(final int number) {
|
||||
return number <= 1 ? 1 : number * calculateFactorial(number - 1);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package com.baeldung.stackoverflowerror;
|
||||
|
||||
public class UnintendedInfiniteRecursion {
|
||||
public int calculateFactorial(int number) {
|
||||
return number * calculateFactorial(number - 1);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package com.baeldung.stackoverflowerror;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class AccountHolderUnitTest {
|
||||
@Test(expected = StackOverflowError.class)
|
||||
public void whenInstanciatingAccountHolder_thenThrowsException() {
|
||||
AccountHolder holder = new AccountHolder();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package com.baeldung.stackoverflowerror;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class CyclicDependancyUnitTest {
|
||||
@Test
|
||||
public void whenInstanciatingClassOne_thenThrowsException() {
|
||||
try {
|
||||
ClassOne obj = new ClassOne();
|
||||
fail();
|
||||
} catch (StackOverflowError soe) {
|
||||
soe.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package com.baeldung.stackoverflowerror;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class InfiniteRecursionWithTerminationConditionUnitTest {
|
||||
@Test
|
||||
public void givenPositiveIntNoOne_whenCalcFact_thenThrowsException() {
|
||||
int numToCalcFactorial = 1;
|
||||
InfiniteRecursionWithTerminationCondition irtc = new InfiniteRecursionWithTerminationCondition();
|
||||
|
||||
assertEquals(1, irtc.calculateFactorial(numToCalcFactorial));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenPositiveIntGtOne_whenCalcFact_thenThrowsException() {
|
||||
int numToCalcFactorial = 5;
|
||||
InfiniteRecursionWithTerminationCondition irtc = new InfiniteRecursionWithTerminationCondition();
|
||||
|
||||
assertEquals(120, irtc.calculateFactorial(numToCalcFactorial));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenNegativeInt_whenCalcFact_thenThrowsException() {
|
||||
try {
|
||||
int numToCalcFactorial = -1;
|
||||
InfiniteRecursionWithTerminationCondition irtc = new InfiniteRecursionWithTerminationCondition();
|
||||
|
||||
irtc.calculateFactorial(numToCalcFactorial);
|
||||
fail();
|
||||
} catch (StackOverflowError soe) {
|
||||
soe.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package com.baeldung.stackoverflowerror;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class UnintendedInfiniteRecursionUnitTest {
|
||||
@Test(expected = StackOverflowError.class)
|
||||
public void givenPositiveIntNoOne_whenCalFact_thenThrowsException() {
|
||||
int numToCalcFactorial = 1;
|
||||
UnintendedInfiniteRecursion uir = new UnintendedInfiniteRecursion();
|
||||
|
||||
uir.calculateFactorial(numToCalcFactorial);
|
||||
}
|
||||
|
||||
@Test(expected = StackOverflowError.class)
|
||||
public void givenPositiveIntGtOne_whenCalcFact_thenThrowsException() {
|
||||
int numToCalcFactorial = 2;
|
||||
UnintendedInfiniteRecursion uir = new UnintendedInfiniteRecursion();
|
||||
|
||||
uir.calculateFactorial(numToCalcFactorial);
|
||||
}
|
||||
|
||||
@Test(expected = StackOverflowError.class)
|
||||
public void givenNegativeInt_whenCalcFact_thenThrowsException() {
|
||||
int numToCalcFactorial = -1;
|
||||
UnintendedInfiniteRecursion uir = new UnintendedInfiniteRecursion();
|
||||
|
||||
uir.calculateFactorial(numToCalcFactorial);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue