Skip to content

Commit 2b67a1b

Browse files
committed
BALE-2154 - Fix Junit.
1 parent b941475 commit 2b67a1b

3 files changed

Lines changed: 27 additions & 29 deletions

File tree

‎java-numbers/src/main/java/com/baeldung/maths/BigDecimalDemo.java‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
package com.baeldung.maths;
2+
13
import java.math.BigDecimal;
24
import java.math.RoundingMode;
35

@@ -11,16 +13,16 @@ public class BigDecimalDemo {
1113
* @return
1214
*/
1315
public static BigDecimal calculateTotalAmount(BigDecimal quantity,
14-
BigDecimal unitPrice, BigDecimal discountRate, BigDecimal taxRate) {
16+
BigDecimal unitPrice, BigDecimal discountRate, BigDecimal taxRate) {
1517
BigDecimal amount = quantity.multiply(unitPrice);
1618
BigDecimal discount = amount.multiply(discountRate);
1719
BigDecimal discountedAmount = amount.subtract(discount);
18-
BigDecimal tax = taxRate.multiply(taxRate);
20+
BigDecimal tax = discountedAmount.multiply(taxRate);
1921
BigDecimal total = discountedAmount.add(tax);
2022

2123
// round to 2 decimal places using HALF_EVEN
2224
BigDecimal roundedTotal = total.setScale(2, RoundingMode.HALF_EVEN);
23-
25+
2426
return roundedTotal;
2527
}
2628

‎java-numbers/src/test/java/com/baeldung/maths/BigDecimalDemoUnitTest.java‎

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
package com.baeldung.maths;
2+
13
import static org.junit.Assert.assertFalse;
24
import static org.junit.Assert.assertNotEquals;
35
import static org.junit.Assert.assertTrue;
@@ -14,14 +16,7 @@
1416
public class BigDecimalDemoUnitTest {
1517

1618
@Test
17-
void test() {
18-
System.out.println(BigDecimal.ONE
19-
.divide(BigDecimal.valueOf(3), 4, RoundingMode.CEILING)
20-
.precision());
21-
}
22-
23-
@Test
24-
void whenBigDecimalCreated_thenValueMatches() {
19+
public void whenBigDecimalCreated_thenValueMatches() {
2520
BigDecimal bdFromString = new BigDecimal("0.1");
2621
BigDecimal bdFromCharArray = new BigDecimal(
2722
new char[] { '3', '.', '1', '6', '1', '5' });
@@ -38,13 +33,13 @@ void whenBigDecimalCreated_thenValueMatches() {
3833
}
3934

4035
@Test
41-
void whenBigDecimalCreatedFromDouble_thenValueMayNotMatch() {
36+
public void whenBigDecimalCreatedFromDouble_thenValueMayNotMatch() {
4237
BigDecimal bdFromDouble = new BigDecimal(0.1d);
4338
assertNotEquals("0.1", bdFromDouble.toString());
4439
}
4540

4641
@Test
47-
void whenBigDecimalCreatedUsingValueOf_thenValueMatches() {
42+
public void whenBigDecimalCreatedUsingValueOf_thenValueMatches() {
4843
BigDecimal bdFromLong1 = BigDecimal.valueOf(123412345678901L);
4944
BigDecimal bdFromLong2 = BigDecimal.valueOf(123412345678901L, 2);
5045
BigDecimal bdFromDouble = BigDecimal.valueOf(0.1d);
@@ -55,15 +50,15 @@ void whenBigDecimalCreatedUsingValueOf_thenValueMatches() {
5550
}
5651

5752
@Test
58-
void whenEqualsCalled_thenSizeAndScaleMatched() {
53+
public void whenEqualsCalled_thenSizeAndScaleMatched() {
5954
BigDecimal bd1 = new BigDecimal("1.0");
6055
BigDecimal bd2 = new BigDecimal("1.00");
6156

6257
assertFalse(bd1.equals(bd2));
6358
}
6459

6560
@Test
66-
void whenComparingBigDecimals_thenExpectedResult() {
61+
public void whenComparingBigDecimals_thenExpectedResult() {
6762
BigDecimal bd1 = new BigDecimal("1.0");
6863
BigDecimal bd2 = new BigDecimal("1.00");
6964
BigDecimal bd3 = new BigDecimal("2.0");
@@ -77,7 +72,7 @@ void whenComparingBigDecimals_thenExpectedResult() {
7772
}
7873

7974
@Test
80-
void whenPerformingArithmetic_thenExpectedResult() {
75+
public void whenPerformingArithmetic_thenExpectedResult() {
8176
BigDecimal bd1 = new BigDecimal("4.0");
8277
BigDecimal bd2 = new BigDecimal("2.0");
8378

@@ -93,7 +88,7 @@ void whenPerformingArithmetic_thenExpectedResult() {
9388
}
9489

9590
@Test
96-
void whenGettingAttributes_thenExpectedResult() {
91+
public void whenGettingAttributes_thenExpectedResult() {
9792
BigDecimal bd = new BigDecimal("-12345.6789");
9893

9994
assertEquals(9, bd.precision());
@@ -102,7 +97,7 @@ void whenGettingAttributes_thenExpectedResult() {
10297
}
10398

10499
@Test
105-
void whenRoundingDecimal_thenExpectedResult() {
100+
public void whenRoundingDecimal_thenExpectedResult() {
106101
BigDecimal bd = new BigDecimal("2.5");
107102
// Round to 1 digit using HALF_EVEN
108103
BigDecimal rounded = bd
@@ -112,15 +107,14 @@ void whenRoundingDecimal_thenExpectedResult() {
112107
}
113108

114109
@Test
115-
void givenPurchaseTxn_whenCalculatingTotalAmount_thenExpectedResult() {
110+
public void givenPurchaseTxn_whenCalculatingTotalAmount_thenExpectedResult() {
116111
BigDecimal quantity = new BigDecimal("4.5");
117112
BigDecimal unitPrice = new BigDecimal("2.69");
118113
BigDecimal discountRate = new BigDecimal("0.10");
119114
BigDecimal taxRate = new BigDecimal("0.0725");
120115

121116
BigDecimal amountToBePaid = BigDecimalDemo
122117
.calculateTotalAmount(quantity, unitPrice, discountRate, taxRate);
123-
124-
assertEquals("10.90", amountToBePaid.toString());
118+
assertEquals("11.68", amountToBePaid.toString());
125119
}
126120
}

‎java-numbers/src/test/java/com/baeldung/maths/BigIntegerDemoUnitTest.java‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
package com.baeldung.maths;
2+
13
import static org.junit.Assert.assertEquals;
24
import static org.junit.Assert.assertTrue;
35

@@ -9,7 +11,7 @@
911
public class BigIntegerDemoUnitTest {
1012

1113
@Test
12-
void whenBigIntegerCreatedFromConstructor_thenExpectedResult() {
14+
public void whenBigIntegerCreatedFromConstructor_thenExpectedResult() {
1315
BigInteger biFromString = new BigInteger("1234567890987654321");
1416
BigInteger biFromByteArray = new BigInteger(
1517
new byte[] { 64, 64, 64, 64, 64, 64 });
@@ -22,14 +24,14 @@ void whenBigIntegerCreatedFromConstructor_thenExpectedResult() {
2224
}
2325

2426
@Test
25-
void whenLongConvertedToBigInteger_thenValueMatches() {
27+
public void whenLongConvertedToBigInteger_thenValueMatches() {
2628
BigInteger bi = BigInteger.valueOf(2305843009213693951L);
2729

2830
assertEquals("2305843009213693951", bi.toString());
2931
}
3032

3133
@Test
32-
void givenBigIntegers_whentCompared_thenExpectedResult() {
34+
public void givenBigIntegers_whentCompared_thenExpectedResult() {
3335
BigInteger i = new BigInteger("123456789012345678901234567890");
3436
BigInteger j = new BigInteger("123456789012345678901234567891");
3537
BigInteger k = new BigInteger("123456789012345678901234567892");
@@ -40,7 +42,7 @@ void givenBigIntegers_whentCompared_thenExpectedResult() {
4042
}
4143

4244
@Test
43-
void givenBigIntegers_whenPerformingArithmetic_thenExpectedResult() {
45+
public void givenBigIntegers_whenPerformingArithmetic_thenExpectedResult() {
4446
BigInteger i = new BigInteger("4");
4547
BigInteger j = new BigInteger("2");
4648

@@ -56,7 +58,7 @@ void givenBigIntegers_whenPerformingArithmetic_thenExpectedResult() {
5658
}
5759

5860
@Test
59-
void givenBigIntegers_whenPerformingBitOperations_thenExpectedResult() {
61+
public void givenBigIntegers_whenPerformingBitOperations_thenExpectedResult() {
6062
BigInteger i = new BigInteger("17");
6163
BigInteger j = new BigInteger("7");
6264

@@ -78,7 +80,7 @@ void givenBigIntegers_whenPerformingBitOperations_thenExpectedResult() {
7880
}
7981

8082
@Test
81-
void givenBigIntegers_whenPerformingBitManipulations_thenExpectedResult() {
83+
public void givenBigIntegers_whenPerformingBitManipulations_thenExpectedResult() {
8284
BigInteger i = new BigInteger("1018");
8385

8486
int bitCount = i.bitCount();
@@ -99,7 +101,7 @@ void givenBigIntegers_whenPerformingBitManipulations_thenExpectedResult() {
99101
}
100102

101103
@Test
102-
void givenBigIntegers_whenModularCalculation_thenExpectedResult() {
104+
public void givenBigIntegers_whenModularCalculation_thenExpectedResult() {
103105
BigInteger i = new BigInteger("31");
104106
BigInteger j = new BigInteger("24");
105107
BigInteger k = new BigInteger("16");
@@ -117,7 +119,7 @@ void givenBigIntegers_whenModularCalculation_thenExpectedResult() {
117119
}
118120

119121
@Test
120-
void givenBigIntegers_whenPrimeOperations_thenExpectedResult() {
122+
public void givenBigIntegers_whenPrimeOperations_thenExpectedResult() {
121123
BigInteger i = BigInteger.probablePrime(100, new Random());
122124

123125
boolean isProbablePrime = i.isProbablePrime(1000);

0 commit comments

Comments
 (0)