Changes done in tests for BAEL-876 (#1843)
* Correction in first two tests * Add new test for RecursionWithCorrectTerminationCondition * BAEL-876 Removed static method qualifier
This commit is contained in:
parent
98ec0ac0b3
commit
b2828f59e1
|
@ -1,7 +1,7 @@
|
||||||
package com.baeldung.stackoverflowerror;
|
package com.baeldung.stackoverflowerror;
|
||||||
|
|
||||||
public class RecursionWithCorrectTerminationCondition {
|
public class RecursionWithCorrectTerminationCondition {
|
||||||
public static int calculateFactorial(final int number) {
|
public int calculateFactorial(final int number) {
|
||||||
return number <= 1 ? 1 : number * calculateFactorial(number - 1);
|
return number <= 1 ? 1 : number * calculateFactorial(number - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ import org.junit.Test;
|
||||||
|
|
||||||
public class InfiniteRecursionWithTerminationConditionManualTest {
|
public class InfiniteRecursionWithTerminationConditionManualTest {
|
||||||
@Test
|
@Test
|
||||||
public void givenPositiveIntNoOne_whenCalcFact_thenThrowsException() {
|
public void givenPositiveIntNoOne_whenCalcFact_thenCorrectlyCalc() {
|
||||||
int numToCalcFactorial = 1;
|
int numToCalcFactorial = 1;
|
||||||
InfiniteRecursionWithTerminationCondition irtc = new InfiniteRecursionWithTerminationCondition();
|
InfiniteRecursionWithTerminationCondition irtc = new InfiniteRecursionWithTerminationCondition();
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ public class InfiniteRecursionWithTerminationConditionManualTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenPositiveIntGtOne_whenCalcFact_thenThrowsException() {
|
public void givenPositiveIntGtOne_whenCalcFact_thenCorrectlyCalc() {
|
||||||
int numToCalcFactorial = 5;
|
int numToCalcFactorial = 5;
|
||||||
InfiniteRecursionWithTerminationCondition irtc = new InfiniteRecursionWithTerminationCondition();
|
InfiniteRecursionWithTerminationCondition irtc = new InfiniteRecursionWithTerminationCondition();
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
package com.baeldung.stackoverflowerror;
|
||||||
|
|
||||||
|
import static junit.framework.TestCase.assertEquals;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class RecursionWithCorrectTerminationConditionManualTest {
|
||||||
|
@Test
|
||||||
|
public void givenNegativeInt_whenCalcFact_thenCorrectlyCalc() {
|
||||||
|
int numToCalcFactorial = -1;
|
||||||
|
RecursionWithCorrectTerminationCondition rctc = new RecursionWithCorrectTerminationCondition();
|
||||||
|
|
||||||
|
assertEquals(1, rctc.calculateFactorial(numToCalcFactorial));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue