diff --git a/pom.xml b/pom.xml index ed7be80..e2e317d 100644 --- a/pom.xml +++ b/pom.xml @@ -520,17 +520,11 @@ true - junit - junit + org.junit.jupiter + junit-jupiter ${junit.version} test - - com.tngtech.java - junit-dataprovider - ${junit-dataprovider.version} - test - @@ -791,9 +785,8 @@ - 1.13.1 2.2.3 - 4.13.2 + 5.11.0 org.joda.money.* diff --git a/src/test/java/org/joda/money/TestBigMoney.java b/src/test/java/org/joda/money/TestBigMoney.java index 410cc3e..400efb7 100644 --- a/src/test/java/org/joda/money/TestBigMoney.java +++ b/src/test/java/org/joda/money/TestBigMoney.java @@ -15,12 +15,16 @@ */ package org.joda.money; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; +import java.io.IOException; import java.io.InvalidObjectException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; @@ -33,18 +37,14 @@ import java.util.Arrays; import java.util.Collections; -import org.junit.Test; -import org.junit.runner.RunWith; - -import com.tngtech.java.junit.dataprovider.DataProvider; -import com.tngtech.java.junit.dataprovider.DataProviderRunner; -import com.tngtech.java.junit.dataprovider.UseDataProvider; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; /** * Test BigMoney. */ -@RunWith(DataProviderRunner.class) -public class TestBigMoney { +class TestBigMoney { private static final CurrencyUnit GBP = CurrencyUnit.of("GBP"); private static final CurrencyUnit EUR = CurrencyUnit.of("EUR"); @@ -94,25 +94,29 @@ private static BigDecimal bd(String str) { // of(Currency,BigDecimal) //----------------------------------------------------------------------- @Test - public void test_factory_of_Currency_BigDecimal() { + void test_factory_of_Currency_BigDecimal() { BigMoney test = BigMoney.of(GBP, BIGDEC_2_345); assertEquals(GBP, test.getCurrencyUnit()); assertEquals(BIGDEC_2_345, test.getAmount()); assertEquals(3, test.getScale()); } - @Test(expected = NullPointerException.class) - public void test_factory_of_Currency_BigDecimal_nullCurrency() { - BigMoney.of((CurrencyUnit) null, BIGDEC_2_345); + @Test + void test_factory_of_Currency_BigDecimal_nullCurrency() { + assertThrows(NullPointerException.class, () -> { + BigMoney.of((CurrencyUnit) null, BIGDEC_2_345); + }); } - @Test(expected = NullPointerException.class) - public void test_factory_of_Currency_BigDecimal_nullBigDecimal() { - BigMoney.of(GBP, (BigDecimal) null); + @Test + void test_factory_of_Currency_BigDecimal_nullBigDecimal() { + assertThrows(NullPointerException.class, () -> { + BigMoney.of(GBP, (BigDecimal) null); + }); } - @Test(expected = IllegalArgumentException.class) - public void test_factory_of_Currency_subClass1() { + @Test + void test_factory_of_Currency_subClass1() { class BadDecimal extends BigDecimal { private static final long serialVersionUID = 1L; @@ -131,11 +135,13 @@ public int scale() { } } BigDecimal sub = new BadDecimal(); - BigMoney.of(GBP, sub); + assertThrows(IllegalArgumentException.class, () -> { + BigMoney.of(GBP, sub); + }); } @Test - public void test_factory_of_Currency_subClass2() { + void test_factory_of_Currency_subClass2() { class BadInteger extends BigInteger { private static final long serialVersionUID = 1L; @@ -165,14 +171,14 @@ public int scale() { assertEquals(GBP, test.getCurrencyUnit()); assertEquals(bd("12.3"), test.getAmount()); assertEquals(1, test.getScale()); - assertEquals(true, test.getAmount().getClass() == BigDecimal.class); + assertEquals(BigDecimal.class, test.getAmount().getClass()); } //----------------------------------------------------------------------- // of(Currency,double) //----------------------------------------------------------------------- @Test - public void test_factory_of_Currency_double() { + void test_factory_of_Currency_double() { BigMoney test = BigMoney.of(GBP, 2.345d); assertEquals(GBP, test.getCurrencyUnit()); assertEquals(BIGDEC_2_345, test.getAmount()); @@ -180,7 +186,7 @@ public void test_factory_of_Currency_double() { } @Test - public void test_factory_of_Currency_double_trailingZero1() { + void test_factory_of_Currency_double_trailingZero1() { BigMoney test = BigMoney.of(GBP, 1.230d); assertEquals(GBP, test.getCurrencyUnit()); assertEquals(BigDecimal.valueOf(123L, 2), test.getAmount()); @@ -188,7 +194,7 @@ public void test_factory_of_Currency_double_trailingZero1() { } @Test - public void test_factory_of_Currency_double_trailingZero2() { + void test_factory_of_Currency_double_trailingZero2() { BigMoney test = BigMoney.of(GBP, 1.20d); assertEquals(GBP, test.getCurrencyUnit()); assertEquals(BigDecimal.valueOf(12L, 1), test.getAmount()); @@ -196,7 +202,7 @@ public void test_factory_of_Currency_double_trailingZero2() { } @Test - public void test_factory_of_Currency_double_zero() { + void test_factory_of_Currency_double_zero() { assertEquals(BigMoney.of(GBP, BigDecimal.valueOf(0L, 0)), BigMoney.of(GBP, 0d)); assertEquals(BigMoney.of(GBP, BigDecimal.valueOf(0L, 0)), BigMoney.of(GBP, -0d)); assertEquals(BigMoney.of(GBP, BigDecimal.valueOf(0L, 0)), BigMoney.of(GBP, 0.0d)); @@ -205,7 +211,7 @@ public void test_factory_of_Currency_double_zero() { } @Test - public void test_factory_of_Currency_double_medium() { + void test_factory_of_Currency_double_medium() { BigMoney test = BigMoney.of(GBP, 2000d); assertEquals(GBP, test.getCurrencyUnit()); assertEquals(BigDecimal.valueOf(2000L, 0), test.getAmount()); @@ -213,219 +219,249 @@ public void test_factory_of_Currency_double_medium() { } @Test - public void test_factory_of_Currency_double_big() { + void test_factory_of_Currency_double_big() { BigMoney test = BigMoney.of(GBP, 200000000d); assertEquals(GBP, test.getCurrencyUnit()); assertEquals(BigDecimal.valueOf(200000000L, 0), test.getAmount()); assertEquals(0, test.getScale()); } - @Test(expected = NullPointerException.class) - public void test_factory_of_Currency_double_nullCurrency() { - BigMoney.of((CurrencyUnit) null, 2.345d); + @Test + void test_factory_of_Currency_double_nullCurrency() { + assertThrows(NullPointerException.class, () -> { + BigMoney.of((CurrencyUnit) null, 2.345d); + }); } //----------------------------------------------------------------------- // ofScale(Currency,BigDecimal, int) //----------------------------------------------------------------------- @Test - public void test_factory_ofScale_Currency_BigDecimal_int() { + void test_factory_ofScale_Currency_BigDecimal_int() { BigMoney test = BigMoney.ofScale(GBP, BIGDEC_2_34, 4); assertEquals(GBP, test.getCurrencyUnit()); assertEquals(BigDecimal.valueOf(23400, 4), test.getAmount()); } @Test - public void test_factory_ofScale_Currency_BigDecimal_negativeScale() { + void test_factory_ofScale_Currency_BigDecimal_negativeScale() { BigMoney test = BigMoney.ofScale(GBP, BigDecimal.valueOf(23400), -2); assertEquals(GBP, test.getCurrencyUnit()); assertEquals(BigDecimal.valueOf(23400L, 0), test.getAmount()); } - @Test(expected = ArithmeticException.class) - public void test_factory_ofScale_Currency_BigDecimal_invalidScale() { - BigMoney.ofScale(GBP, BIGDEC_2_345, 2); + @Test + void test_factory_ofScale_Currency_BigDecimal_invalidScale() { + assertThrows(ArithmeticException.class, () -> { + BigMoney.ofScale(GBP, BIGDEC_2_345, 2); + }); } - @Test(expected = NullPointerException.class) - public void test_factory_ofScale_Currency_BigDecimal_nullCurrency() { - BigMoney.ofScale((CurrencyUnit) null, BIGDEC_2_34, 2); + @Test + void test_factory_ofScale_Currency_BigDecimal_nullCurrency() { + assertThrows(NullPointerException.class, () -> { + BigMoney.ofScale((CurrencyUnit) null, BIGDEC_2_34, 2); + }); } - @Test(expected = NullPointerException.class) - public void test_factory_ofScale_Currency_BigDecimal_nullBigDecimal() { - BigMoney.ofScale(GBP, (BigDecimal) null, 2); + @Test + void test_factory_ofScale_Currency_BigDecimal_nullBigDecimal() { + assertThrows(NullPointerException.class, () -> { + BigMoney.ofScale(GBP, (BigDecimal) null, 2); + }); } //----------------------------------------------------------------------- // ofScale(Currency,BigDecimal,int,RoundingMode) //----------------------------------------------------------------------- @Test - public void test_factory_ofScale_Currency_BigDecimal_int_RoundingMode_DOWN() { + void test_factory_ofScale_Currency_BigDecimal_int_RoundingMode_DOWN() { BigMoney test = BigMoney.ofScale(GBP, BIGDEC_2_34, 1, RoundingMode.DOWN); assertEquals(GBP, test.getCurrencyUnit()); assertEquals(BigDecimal.valueOf(23, 1), test.getAmount()); } @Test - public void test_factory_ofScale_Currency_BigDecimal_int_JPY_RoundingMode_UP() { + void test_factory_ofScale_Currency_BigDecimal_int_JPY_RoundingMode_UP() { BigMoney test = BigMoney.ofScale(JPY, BIGDEC_2_34, 0, RoundingMode.UP); assertEquals(JPY, test.getCurrencyUnit()); assertEquals(BigDecimal.valueOf(3, 0), test.getAmount()); } @Test - public void test_factory_ofScale_Currency_BigDecimal_int_RoundingMode_negativeScale() { + void test_factory_ofScale_Currency_BigDecimal_int_RoundingMode_negativeScale() { BigMoney test = BigMoney.ofScale(GBP, BigDecimal.valueOf(23400), -2, RoundingMode.DOWN); assertEquals(GBP, test.getCurrencyUnit()); assertEquals(BigDecimal.valueOf(23400L, 0), test.getAmount()); } - @Test(expected = ArithmeticException.class) - public void test_factory_ofScale_Currency_BigDecimal_int_RoundingMode_UNNECESSARY() { - BigMoney.ofScale(JPY, BIGDEC_2_34, 1, RoundingMode.UNNECESSARY); + @Test + void test_factory_ofScale_Currency_BigDecimal_int_RoundingMode_UNNECESSARY() { + assertThrows(ArithmeticException.class, () -> { + BigMoney.ofScale(JPY, BIGDEC_2_34, 1, RoundingMode.UNNECESSARY); + }); } - @Test(expected = NullPointerException.class) - public void test_factory_ofScale_Currency_BigDecimal_int_RoundingMode_nullCurrency() { - BigMoney.ofScale((CurrencyUnit) null, BIGDEC_2_34, 2, RoundingMode.DOWN); + @Test + void test_factory_ofScale_Currency_BigDecimal_int_RoundingMode_nullCurrency() { + assertThrows(NullPointerException.class, () -> { + BigMoney.ofScale((CurrencyUnit) null, BIGDEC_2_34, 2, RoundingMode.DOWN); + }); } - @Test(expected = NullPointerException.class) - public void test_factory_ofScale_Currency_BigDecimal_int_RoundingMode_nullBigDecimal() { - BigMoney.ofScale(GBP, (BigDecimal) null, 2, RoundingMode.DOWN); + @Test + void test_factory_ofScale_Currency_BigDecimal_int_RoundingMode_nullBigDecimal() { + assertThrows(NullPointerException.class, () -> { + BigMoney.ofScale(GBP, (BigDecimal) null, 2, RoundingMode.DOWN); + }); } - @Test(expected = NullPointerException.class) - public void test_factory_ofScale_Currency_BigDecimal_int_RoundingMode_nullRoundingMode() { - BigMoney.ofScale(GBP, BIGDEC_2_34, 2, (RoundingMode) null); + @Test + void test_factory_ofScale_Currency_BigDecimal_int_RoundingMode_nullRoundingMode() { + assertThrows(NullPointerException.class, () -> { + BigMoney.ofScale(GBP, BIGDEC_2_34, 2, (RoundingMode) null); + }); } //----------------------------------------------------------------------- // ofScale(Currency,long, int) //----------------------------------------------------------------------- @Test - public void test_factory_ofScale_Currency_long_int() { + void test_factory_ofScale_Currency_long_int() { BigMoney test = BigMoney.ofScale(GBP, 234, 4); assertEquals(GBP, test.getCurrencyUnit()); assertEquals(BigDecimal.valueOf(234, 4), test.getAmount()); } @Test - public void test_factory_ofScale_Currency_long_int_negativeScale() { + void test_factory_ofScale_Currency_long_int_negativeScale() { BigMoney test = BigMoney.ofScale(GBP, 234, -4); assertEquals(GBP, test.getCurrencyUnit()); assertEquals(BigDecimal.valueOf(2340000, 0), test.getAmount()); } - @Test(expected = NullPointerException.class) - public void test_factory_ofScale_Currency_long_int_nullCurrency() { - BigMoney.ofScale((CurrencyUnit) null, 234, 2); + @Test + void test_factory_ofScale_Currency_long_int_nullCurrency() { + assertThrows(NullPointerException.class, () -> { + BigMoney.ofScale((CurrencyUnit) null, 234, 2); + }); } //----------------------------------------------------------------------- // ofMajor(Currency,long) //----------------------------------------------------------------------- @Test - public void test_factory_ofMajor_Currency_long() { + void test_factory_ofMajor_Currency_long() { BigMoney test = BigMoney.ofMajor(GBP, 234); assertEquals(GBP, test.getCurrencyUnit()); assertEquals(bd("234"), test.getAmount()); assertEquals(0, test.getScale()); } - @Test(expected = NullPointerException.class) - public void test_factory_ofMajor_Currency_long_nullCurrency() { - BigMoney.ofMajor((CurrencyUnit) null, 234); + @Test + void test_factory_ofMajor_Currency_long_nullCurrency() { + assertThrows(NullPointerException.class, () -> { + BigMoney.ofMajor((CurrencyUnit) null, 234); + }); } //----------------------------------------------------------------------- // ofMinor(Currency,long) //----------------------------------------------------------------------- @Test - public void test_factory_ofMinor_Currency_long() { + void test_factory_ofMinor_Currency_long() { BigMoney test = BigMoney.ofMinor(GBP, 234); assertEquals(GBP, test.getCurrencyUnit()); assertEquals(bd("2.34"), test.getAmount()); assertEquals(2, test.getScale()); } - @Test(expected = NullPointerException.class) - public void test_factory_ofMinor_Currency_long_nullCurrency() { - BigMoney.ofMinor((CurrencyUnit) null, 234); + @Test + void test_factory_ofMinor_Currency_long_nullCurrency() { + assertThrows(NullPointerException.class, () -> { + BigMoney.ofMinor((CurrencyUnit) null, 234); + }); } //----------------------------------------------------------------------- // zero(Currency) //----------------------------------------------------------------------- @Test - public void test_factory_zero_Currency() { + void test_factory_zero_Currency() { BigMoney test = BigMoney.zero(GBP); assertEquals(GBP, test.getCurrencyUnit()); assertEquals(BigDecimal.ZERO, test.getAmount()); assertEquals(0, test.getScale()); } - @Test(expected = NullPointerException.class) - public void test_factory_zero_Currency_nullCurrency() { - BigMoney.zero((CurrencyUnit) null); + @Test + void test_factory_zero_Currency_nullCurrency() { + assertThrows(NullPointerException.class, () -> { + BigMoney.zero((CurrencyUnit) null); + }); } //----------------------------------------------------------------------- // zero(Currency, int) //----------------------------------------------------------------------- @Test - public void test_factory_zero_Currency_int() { + void test_factory_zero_Currency_int() { BigMoney test = BigMoney.zero(GBP, 3); assertEquals(GBP, test.getCurrencyUnit()); assertEquals(BigDecimal.valueOf(0, 3), test.getAmount()); } @Test - public void test_factory_zero_Currency_int_negativeScale() { + void test_factory_zero_Currency_int_negativeScale() { BigMoney test = BigMoney.zero(GBP, -3); assertEquals(GBP, test.getCurrencyUnit()); assertEquals(BigDecimal.valueOf(0, 0), test.getAmount()); } - @Test(expected = NullPointerException.class) - public void test_factory_zero_Currency_int_nullCurrency() { - BigMoney.zero((CurrencyUnit) null, 3); + @Test + void test_factory_zero_Currency_int_nullCurrency() { + assertThrows(NullPointerException.class, () -> { + BigMoney.zero((CurrencyUnit) null, 3); + }); } //----------------------------------------------------------------------- // from(BigMoneyProvider) //----------------------------------------------------------------------- @Test - public void test_factory_from_BigMoneyProvider() { + void test_factory_from_BigMoneyProvider() { BigMoney test = BigMoney.of(BigMoney.parse("GBP 104.23")); assertEquals(GBP, test.getCurrencyUnit()); assertEquals(10423, test.getAmountMinorInt()); assertEquals(2, test.getScale()); } - @Test(expected = NullPointerException.class) - public void test_factory_from_BigMoneyProvider_nullBigMoneyProvider() { - BigMoney.of((BigMoneyProvider) null); + @Test + void test_factory_from_BigMoneyProvider_nullBigMoneyProvider() { + assertThrows(NullPointerException.class, () -> { + BigMoney.of((BigMoneyProvider) null); + }); } - @Test(expected = NullPointerException.class) - public void test_factory_from_BigMoneyProvider_badProvider() { - BigMoney.of(BAD_PROVIDER); + @Test + void test_factory_from_BigMoneyProvider_badProvider() { + assertThrows(NullPointerException.class, () -> { + BigMoney.of(BAD_PROVIDER); + }); } //----------------------------------------------------------------------- // total(BigMoneyProvider...) //----------------------------------------------------------------------- @Test - public void test_factory_total_varargs_1BigMoney() { + void test_factory_total_varargs_1BigMoney() { BigMoney test = BigMoney.total(GBP_1_23); assertEquals(GBP, test.getCurrencyUnit()); assertEquals(123, test.getAmountMinorInt()); } @Test - public void test_factory_total_array_1BigMoney() { + void test_factory_total_array_1BigMoney() { BigMoneyProvider[] array = new BigMoneyProvider[] {GBP_1_23}; BigMoney test = BigMoney.total(array); assertEquals(GBP, test.getCurrencyUnit()); @@ -433,14 +469,14 @@ public void test_factory_total_array_1BigMoney() { } @Test - public void test_factory_total_varargs_3Mixed() { + void test_factory_total_varargs_3Mixed() { BigMoney test = BigMoney.total(GBP_1_23, GBP_2_33.toMoney(), GBP_2_36); assertEquals(GBP, test.getCurrencyUnit()); assertEquals(592, test.getAmountMinorInt()); } @Test - public void test_factory_total_array_3Mixed() { + void test_factory_total_array_3Mixed() { BigMoneyProvider[] array = new BigMoneyProvider[] {GBP_1_23, GBP_2_33.toMoney(), GBP_2_36}; BigMoney test = BigMoney.total(array); assertEquals(GBP, test.getCurrencyUnit()); @@ -448,73 +484,93 @@ public void test_factory_total_array_3Mixed() { } @Test - public void test_factory_total_array_3Money() { + void test_factory_total_array_3Money() { Money[] array = new Money[] {GBP_1_23.toMoney(), GBP_2_33.toMoney(), GBP_2_36.toMoney()}; BigMoney test = BigMoney.total(array); assertEquals(GBP, test.getCurrencyUnit()); assertEquals(592, test.getAmountMinorInt()); } - @Test(expected = IllegalArgumentException.class) - public void test_factory_total_varargs_empty() { - BigMoney.total(); + @Test + void test_factory_total_varargs_empty() { + assertThrows(IllegalArgumentException.class, () -> { + BigMoney.total(); + }); } - @Test(expected = IllegalArgumentException.class) - public void test_factory_total_array_empty() { + @Test + void test_factory_total_array_empty() { BigMoneyProvider[] array = new BigMoneyProvider[0]; - BigMoney.total(array); + assertThrows(IllegalArgumentException.class, () -> { + BigMoney.total(array); + }); } - @Test(expected = CurrencyMismatchException.class) - public void test_factory_total_varargs_currenciesDiffer() { - BigMoney.total(GBP_2_33, JPY_423); + @Test + void test_factory_total_varargs_currenciesDiffer() { + assertThrows(CurrencyMismatchException.class, () -> { + BigMoney.total(GBP_2_33, JPY_423); + }); } - @Test(expected = CurrencyMismatchException.class) - public void test_factory_total_array_currenciesDiffer() { + @Test + void test_factory_total_array_currenciesDiffer() { BigMoneyProvider[] array = new BigMoneyProvider[] {GBP_2_33, JPY_423}; - BigMoney.total(array); + assertThrows(CurrencyMismatchException.class, () -> { + BigMoney.total(array); + }); } - @Test(expected = NullPointerException.class) - public void test_factory_total_varargs_nullFirst() { - BigMoney.total((BigMoney) null, GBP_2_33, GBP_2_36); + @Test + void test_factory_total_varargs_nullFirst() { + assertThrows(NullPointerException.class, () -> { + BigMoney.total((BigMoney) null, GBP_2_33, GBP_2_36); + }); } - @Test(expected = NullPointerException.class) - public void test_factory_total_array_nullFirst() { + @Test + void test_factory_total_array_nullFirst() { BigMoneyProvider[] array = new BigMoneyProvider[] {null, GBP_2_33, GBP_2_36}; - BigMoney.total(array); + assertThrows(NullPointerException.class, () -> { + BigMoney.total(array); + }); } - @Test(expected = NullPointerException.class) - public void test_factory_total_varargs_nullNotFirst() { - BigMoney.total(GBP_2_33, null, GBP_2_36); + @Test + void test_factory_total_varargs_nullNotFirst() { + assertThrows(NullPointerException.class, () -> { + BigMoney.total(GBP_2_33, null, GBP_2_36); + }); } - @Test(expected = NullPointerException.class) - public void test_factory_total_array_nullNotFirst() { + @Test + void test_factory_total_array_nullNotFirst() { BigMoneyProvider[] array = new BigMoneyProvider[] {GBP_2_33, null, GBP_2_36}; - BigMoney.total(array); + assertThrows(NullPointerException.class, () -> { + BigMoney.total(array); + }); } - @Test(expected = NullPointerException.class) - public void test_factory_total_varargs_badProvider() { - BigMoney.total(BAD_PROVIDER); + @Test + void test_factory_total_varargs_badProvider() { + assertThrows(NullPointerException.class, () -> { + BigMoney.total(BAD_PROVIDER); + }); } - @Test(expected = NullPointerException.class) - public void test_factory_total_array_badProvider() { + @Test + void test_factory_total_array_badProvider() { BigMoneyProvider[] array = new BigMoneyProvider[] {BAD_PROVIDER}; - BigMoney.total(array); + assertThrows(NullPointerException.class, () -> { + BigMoney.total(array); + }); } //----------------------------------------------------------------------- // total(Iterable) //----------------------------------------------------------------------- @Test - public void test_factory_total_Iterable() { + void test_factory_total_Iterable() { Iterable iterable = Arrays.asList(GBP_1_23, GBP_2_33, BigMoney.of(GBP, 2.361d)); BigMoney test = BigMoney.total(iterable); assertEquals(GBP, test.getCurrencyUnit()); @@ -522,55 +578,65 @@ public void test_factory_total_Iterable() { } @Test - public void test_factory_total_Iterable_Mixed() { + void test_factory_total_Iterable_Mixed() { Iterable iterable = Arrays.asList(GBP_1_23.toMoney(), GBP_2_33); BigMoney test = BigMoney.total(iterable); assertEquals(GBP, test.getCurrencyUnit()); assertEquals(BigDecimal.valueOf(356, 2), test.getAmount()); } - @Test(expected = IllegalArgumentException.class) - public void test_factory_total_Iterable_empty() { + @Test + void test_factory_total_Iterable_empty() { Iterable iterable = Collections.emptyList(); - BigMoney.total(iterable); + assertThrows(IllegalArgumentException.class, () -> { + BigMoney.total(iterable); + }); } - @Test(expected = CurrencyMismatchException.class) - public void test_factory_total_Iterable_currenciesDiffer() { + @Test + void test_factory_total_Iterable_currenciesDiffer() { Iterable iterable = Arrays.asList(GBP_2_33, JPY_423); - BigMoney.total(iterable); + assertThrows(CurrencyMismatchException.class, () -> { + BigMoney.total(iterable); + }); } - @Test(expected = NullPointerException.class) - public void test_factory_total_Iterable_nullFirst() { + @Test + void test_factory_total_Iterable_nullFirst() { Iterable iterable = Arrays.asList(null, GBP_2_33, GBP_2_36); - BigMoney.total(iterable); + assertThrows(NullPointerException.class, () -> { + BigMoney.total(iterable); + }); } - @Test(expected = NullPointerException.class) - public void test_factory_total_Iterable_nullNotFirst() { + @Test + void test_factory_total_Iterable_nullNotFirst() { Iterable iterable = Arrays.asList(GBP_2_33, null, GBP_2_36); - BigMoney.total(iterable); + assertThrows(NullPointerException.class, () -> { + BigMoney.total(iterable); + }); } - @Test(expected = NullPointerException.class) - public void test_factory_total_Iterable_badProvider() { + @Test + void test_factory_total_Iterable_badProvider() { Iterable iterable = Arrays.asList(BAD_PROVIDER); - BigMoney.total(iterable); + assertThrows(NullPointerException.class, () -> { + BigMoney.total(iterable); + }); } //----------------------------------------------------------------------- // total(CurrencyUnit,BigMoneyProvider...) //----------------------------------------------------------------------- @Test - public void test_factory_total_CurrencyUnitVarargs_1() { + void test_factory_total_CurrencyUnitVarargs_1() { BigMoney test = BigMoney.total(GBP, GBP_1_23); assertEquals(GBP, test.getCurrencyUnit()); assertEquals(123, test.getAmountMinorInt()); } @Test - public void test_factory_total_CurrencyUnitArray_1() { + void test_factory_total_CurrencyUnitArray_1() { BigMoney[] array = new BigMoney[] {GBP_1_23}; BigMoney test = BigMoney.total(GBP, array); assertEquals(GBP, test.getCurrencyUnit()); @@ -578,14 +644,14 @@ public void test_factory_total_CurrencyUnitArray_1() { } @Test - public void test_factory_total_CurrencyUnitVarargs_3() { + void test_factory_total_CurrencyUnitVarargs_3() { BigMoney test = BigMoney.total(GBP, GBP_1_23, GBP_2_33, GBP_2_36); assertEquals(GBP, test.getCurrencyUnit()); assertEquals(592, test.getAmountMinorInt()); } @Test - public void test_factory_total_CurrencyUnitArray_3() { + void test_factory_total_CurrencyUnitArray_3() { BigMoney[] array = new BigMoney[] {GBP_1_23, GBP_2_33, GBP_2_36}; BigMoney test = BigMoney.total(GBP, array); assertEquals(GBP, test.getCurrencyUnit()); @@ -593,14 +659,14 @@ public void test_factory_total_CurrencyUnitArray_3() { } @Test - public void test_factory_total_CurrencyUnitVarargs_3Mixed() { + void test_factory_total_CurrencyUnitVarargs_3Mixed() { BigMoney test = BigMoney.total(GBP, GBP_1_23, GBP_2_33.toMoney(), GBP_2_36); assertEquals(GBP, test.getCurrencyUnit()); assertEquals(592, test.getAmountMinorInt()); } @Test - public void test_factory_total_CurrencyUnitArray_3Mixed() { + void test_factory_total_CurrencyUnitArray_3Mixed() { BigMoneyProvider[] array = new BigMoneyProvider[] {GBP_1_23, GBP_2_33.toMoney(), GBP_2_36}; BigMoney test = BigMoney.total(GBP, array); assertEquals(GBP, test.getCurrencyUnit()); @@ -608,7 +674,7 @@ public void test_factory_total_CurrencyUnitArray_3Mixed() { } @Test - public void test_factory_total_CurrencyUnitArray_3Money() { + void test_factory_total_CurrencyUnitArray_3Money() { Money[] array = new Money[] {GBP_1_23.toMoney(), GBP_2_33.toMoney(), GBP_2_36.toMoney()}; BigMoney test = BigMoney.total(GBP, array); assertEquals(GBP, test.getCurrencyUnit()); @@ -616,80 +682,100 @@ public void test_factory_total_CurrencyUnitArray_3Money() { } @Test - public void test_factory_total_CurrencyUnitVarargs_empty() { + void test_factory_total_CurrencyUnitVarargs_empty() { BigMoney test = BigMoney.total(GBP); assertEquals(GBP, test.getCurrencyUnit()); assertEquals(0, test.getAmountMinorInt()); } @Test - public void test_factory_total_CurrencyUnitArray_empty() { + void test_factory_total_CurrencyUnitArray_empty() { BigMoney[] array = new BigMoney[0]; BigMoney test = BigMoney.total(GBP, array); assertEquals(GBP, test.getCurrencyUnit()); assertEquals(0, test.getAmountMinorInt()); } - @Test(expected = CurrencyMismatchException.class) - public void test_factory_total_CurrencyUnitVarargs_currenciesDiffer() { - BigMoney.total(GBP, JPY_423); + @Test + void test_factory_total_CurrencyUnitVarargs_currenciesDiffer() { + assertThrows(CurrencyMismatchException.class, () -> { + BigMoney.total(GBP, JPY_423); + }); } - @Test(expected = CurrencyMismatchException.class) - public void test_factory_total_CurrencyUnitArray_currenciesDiffer() { + @Test + void test_factory_total_CurrencyUnitArray_currenciesDiffer() { BigMoney[] array = new BigMoney[] {JPY_423}; - BigMoney.total(GBP, array); + assertThrows(CurrencyMismatchException.class, () -> { + BigMoney.total(GBP, array); + }); } - @Test(expected = CurrencyMismatchException.class) - public void test_factory_total_CurrencyUnitVarargs_currenciesDifferInArray() { - BigMoney.total(GBP, GBP_2_33, JPY_423); + @Test + void test_factory_total_CurrencyUnitVarargs_currenciesDifferInArray() { + assertThrows(CurrencyMismatchException.class, () -> { + BigMoney.total(GBP, GBP_2_33, JPY_423); + }); } - @Test(expected = CurrencyMismatchException.class) - public void test_factory_total_CurrencyUnitArray_currenciesDifferInArray() { + @Test + void test_factory_total_CurrencyUnitArray_currenciesDifferInArray() { BigMoney[] array = new BigMoney[] {GBP_2_33, JPY_423}; - BigMoney.total(GBP, array); + assertThrows(CurrencyMismatchException.class, () -> { + BigMoney.total(GBP, array); + }); } - @Test(expected = NullPointerException.class) - public void test_factory_total_CurrencyUnitVarargs_nullFirst() { - BigMoney.total(GBP, null, GBP_2_33, GBP_2_36); + @Test + void test_factory_total_CurrencyUnitVarargs_nullFirst() { + assertThrows(NullPointerException.class, () -> { + BigMoney.total(GBP, null, GBP_2_33, GBP_2_36); + }); } - @Test(expected = NullPointerException.class) - public void test_factory_total_CurrencyUnitArray_nullFirst() { + @Test + void test_factory_total_CurrencyUnitArray_nullFirst() { BigMoney[] array = new BigMoney[] {null, GBP_2_33, GBP_2_36}; - BigMoney.total(GBP, array); + assertThrows(NullPointerException.class, () -> { + BigMoney.total(GBP, array); + }); } - @Test(expected = NullPointerException.class) - public void test_factory_total_CurrencyUnitVarargs_nullNotFirst() { - BigMoney.total(GBP, GBP_2_33, null, GBP_2_36); + @Test + void test_factory_total_CurrencyUnitVarargs_nullNotFirst() { + assertThrows(NullPointerException.class, () -> { + BigMoney.total(GBP, GBP_2_33, null, GBP_2_36); + }); } - @Test(expected = NullPointerException.class) - public void test_factory_total_CurrencyUnitArray_nullNotFirst() { + @Test + void test_factory_total_CurrencyUnitArray_nullNotFirst() { BigMoney[] array = new BigMoney[] {GBP_2_33, null, GBP_2_36}; - BigMoney.total(GBP, array); + assertThrows(NullPointerException.class, () -> { + BigMoney.total(GBP, array); + }); } - @Test(expected = NullPointerException.class) - public void test_factory_total_CurrencyUnitVarargs_badProvider() { - BigMoney.total(GBP, BAD_PROVIDER); + @Test + void test_factory_total_CurrencyUnitVarargs_badProvider() { + assertThrows(NullPointerException.class, () -> { + BigMoney.total(GBP, BAD_PROVIDER); + }); } - @Test(expected = NullPointerException.class) - public void test_factory_total_CurrencyUnitArray_badProvider() { + @Test + void test_factory_total_CurrencyUnitArray_badProvider() { BigMoneyProvider[] array = new BigMoneyProvider[] {BAD_PROVIDER}; - BigMoney.total(GBP, array); + assertThrows(NullPointerException.class, () -> { + BigMoney.total(GBP, array); + }); } //----------------------------------------------------------------------- // total(CurrencyUnit,Iterable) //----------------------------------------------------------------------- @Test - public void test_factory_total_CurrencyUnitIterable() { + void test_factory_total_CurrencyUnitIterable() { Iterable iterable = Arrays.asList(GBP_1_23, GBP_2_33, BigMoney.of(GBP, 2.361d)); BigMoney test = BigMoney.total(GBP, iterable); assertEquals(GBP, test.getCurrencyUnit()); @@ -697,7 +783,7 @@ public void test_factory_total_CurrencyUnitIterable() { } @Test - public void test_factory_total_CurrencyUnitIterable_Mixed() { + void test_factory_total_CurrencyUnitIterable_Mixed() { Iterable iterable = Arrays.asList(GBP_1_23.toMoney(), GBP_2_33); BigMoney test = BigMoney.total(GBP, iterable); assertEquals(GBP, test.getCurrencyUnit()); @@ -705,47 +791,56 @@ public void test_factory_total_CurrencyUnitIterable_Mixed() { } @Test - public void test_factory_total_CurrencyUnitIterable_empty() { + void test_factory_total_CurrencyUnitIterable_empty() { Iterable iterable = Collections.emptyList(); BigMoney test = BigMoney.total(GBP, iterable); assertEquals(GBP, test.getCurrencyUnit()); assertEquals(0, test.getAmountMinorInt()); } - @Test(expected = CurrencyMismatchException.class) - public void test_factory_total_CurrencyUnitIterable_currenciesDiffer() { + @Test + void test_factory_total_CurrencyUnitIterable_currenciesDiffer() { Iterable iterable = Arrays.asList(JPY_423); - BigMoney.total(GBP, iterable); + assertThrows(CurrencyMismatchException.class, () -> { + BigMoney.total(GBP, iterable); + }); } - @Test(expected = CurrencyMismatchException.class) - public void test_factory_total_CurrencyUnitIterable_currenciesDifferInIterable() { + @Test + void test_factory_total_CurrencyUnitIterable_currenciesDifferInIterable() { Iterable iterable = Arrays.asList(GBP_2_33, JPY_423); - BigMoney.total(GBP, iterable); + assertThrows(CurrencyMismatchException.class, () -> { + BigMoney.total(GBP, iterable); + }); } - @Test(expected = NullPointerException.class) - public void test_factory_total_CurrencyUnitIterable_nullFirst() { + @Test + void test_factory_total_CurrencyUnitIterable_nullFirst() { Iterable iterable = Arrays.asList(null, GBP_2_33, GBP_2_36); - BigMoney.total(GBP, iterable); + assertThrows(NullPointerException.class, () -> { + BigMoney.total(GBP, iterable); + }); } - @Test(expected = NullPointerException.class) - public void test_factory_total_CurrencyUnitIterable_nullNotFirst() { + @Test + void test_factory_total_CurrencyUnitIterable_nullNotFirst() { Iterable iterable = Arrays.asList(GBP_2_33, null, GBP_2_36); - BigMoney.total(GBP, iterable); + assertThrows(NullPointerException.class, () -> { + BigMoney.total(GBP, iterable); + }); } - @Test(expected = NullPointerException.class) - public void test_factory_total_CurrencyUnitIterable_badProvider() { + @Test + void test_factory_total_CurrencyUnitIterable_badProvider() { Iterable iterable = Arrays.asList(BAD_PROVIDER); - BigMoney.total(GBP, iterable); + assertThrows(NullPointerException.class, () -> { + BigMoney.total(GBP, iterable); + }); } //----------------------------------------------------------------------- // parse(String) //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_parse() { return new Object[][] { {"GBP 2.43", GBP, "2.43", 2}, @@ -769,43 +864,51 @@ public static Object[][] data_parse() { }; } - @Test - @UseDataProvider("data_parse") - public void test_factory_parse(String str, CurrencyUnit currency, String amountStr, int scale) { + @ParameterizedTest + @MethodSource("data_parse") + void test_factory_parse(String str, CurrencyUnit currency, String amountStr, int scale) { BigMoney test = BigMoney.parse(str); assertEquals(currency, test.getCurrencyUnit()); assertEquals(bd(amountStr), test.getAmount()); assertEquals(scale, test.getScale()); } - @Test(expected = IllegalArgumentException.class) - public void test_factory_parse_String_tooShort() { - BigMoney.parse("GBP"); + @Test + void test_factory_parse_String_tooShort() { + assertThrows(IllegalArgumentException.class, () -> { + BigMoney.parse("GBP"); + }); } - @Test(expected = IllegalArgumentException.class) - public void test_factory_parse_String_exponent() { - BigMoney.parse("GBP 234E2"); + @Test + void test_factory_parse_String_exponent() { + assertThrows(IllegalArgumentException.class, () -> { + BigMoney.parse("GBP 234E2"); + }); } - @Test(expected = IllegalArgumentException.class) - public void test_factory_parse_String_badCurrency() { - BigMoney.parse("GBX 2.34"); + @Test + void test_factory_parse_String_badCurrency() { + assertThrows(IllegalArgumentException.class, () -> { + BigMoney.parse("GBX 2.34"); + }); } - @Test(expected = NullPointerException.class) - public void test_factory_parse_String_nullString() { - BigMoney.parse((String) null); + @Test + void test_factory_parse_String_nullString() { + assertThrows(NullPointerException.class, () -> { + BigMoney.parse((String) null); + }); } //----------------------------------------------------------------------- // constructor //----------------------------------------------------------------------- @Test - public void test_constructor_null1() throws Exception { + void test_constructor_null1() throws Exception { Constructor con = BigMoney.class.getDeclaredConstructor(CurrencyUnit.class, BigDecimal.class); - assertEquals(false, Modifier.isPublic(con.getModifiers())); - assertEquals(false, Modifier.isProtected(con.getModifiers())); + assertFalse(Modifier.isPublic(con.getModifiers())); + assertFalse(Modifier.isProtected(con.getModifiers())); try { con.setAccessible(true); con.newInstance(new Object[] {null, BIGDEC_2_34}); @@ -816,7 +919,7 @@ public void test_constructor_null1() throws Exception { } @Test - public void test_constructor_null2() throws Exception { + void test_constructor_null2() throws Exception { Constructor con = BigMoney.class.getDeclaredConstructor(CurrencyUnit.class, BigDecimal.class); try { con.setAccessible(true); @@ -829,49 +932,49 @@ public void test_constructor_null2() throws Exception { //----------------------------------------------------------------------- @Test - public void test_scaleNormalization1() { + void test_scaleNormalization1() { BigMoney a = BigMoney.ofScale(GBP, 100, 0); BigMoney b = BigMoney.ofScale(GBP, 1, -2); assertEquals("GBP 100", a.toString()); assertEquals("GBP 100", b.toString()); - assertEquals(true, a.equals(a)); - assertEquals(true, b.equals(b)); - assertEquals(true, a.equals(b)); - assertEquals(true, b.equals(a)); - assertEquals(true, a.hashCode() == b.hashCode()); + assertTrue(a.equals(a)); + assertTrue(b.equals(b)); + assertTrue(a.equals(b)); + assertTrue(b.equals(a)); + assertTrue(a.hashCode() == b.hashCode()); } @Test - public void test_scaleNormalization2() { + void test_scaleNormalization2() { BigMoney a = BigMoney.ofScale(GBP, 1, 1); BigMoney b = BigMoney.ofScale(GBP, 10, 2); assertEquals("GBP 0.1", a.toString()); assertEquals("GBP 0.10", b.toString()); - assertEquals(true, a.equals(a)); - assertEquals(true, b.equals(b)); - assertEquals(false, a.equals(b)); - assertEquals(false, b.equals(a)); - assertEquals(false, a.hashCode() == b.hashCode()); + assertTrue(a.equals(a)); + assertTrue(b.equals(b)); + assertFalse(a.equals(b)); + assertFalse(b.equals(a)); + assertFalse(a.hashCode() == b.hashCode()); } @Test - public void test_scaleNormalization3() { + void test_scaleNormalization3() { BigMoney a = BigMoney.of(GBP, new BigDecimal("100")); BigMoney b = BigMoney.of(GBP, new BigDecimal("1E+2")); assertEquals("GBP 100", a.toString()); assertEquals("GBP 100", b.toString()); - assertEquals(true, a.equals(a)); - assertEquals(true, b.equals(b)); - assertEquals(true, a.equals(b)); - assertEquals(true, b.equals(a)); - assertEquals(true, a.hashCode() == b.hashCode()); + assertTrue(a.equals(a)); + assertTrue(b.equals(b)); + assertTrue(a.equals(b)); + assertTrue(b.equals(a)); + assertTrue(a.hashCode() == b.hashCode()); } //----------------------------------------------------------------------- // serialization //----------------------------------------------------------------------- @Test - public void test_serialization() throws Exception { + void test_serialization() throws Exception { BigMoney a = BigMoney.parse("GBP 2.34"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (ObjectOutputStream oos = new ObjectOutputStream(baos)) { @@ -883,8 +986,8 @@ public void test_serialization() throws Exception { } } - @Test(expected = InvalidObjectException.class) - public void test_serialization_invalidNumericCode() throws Exception { + @Test + void test_serialization_invalidNumericCode() throws IOException { CurrencyUnit cu = new CurrencyUnit("GBP", (short) 234, (short) 2); BigMoney m = BigMoney.of(cu, 123.43d); ByteArrayOutputStream baos = new ByteArrayOutputStream(); @@ -892,12 +995,14 @@ public void test_serialization_invalidNumericCode() throws Exception { oos.writeObject(m); oos.close(); ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); - ois.readObject(); + assertThrows(InvalidObjectException.class, () -> { + ois.readObject(); + }); } } - @Test(expected = InvalidObjectException.class) - public void test_serialization_invalidDecimalPlaces() throws Exception { + @Test + void test_serialization_invalidDecimalPlaces() throws IOException { CurrencyUnit cu = new CurrencyUnit("GBP", (short) 826, (short) 1); BigMoney m = BigMoney.of(cu, 123.43d); ByteArrayOutputStream baos = new ByteArrayOutputStream(); @@ -905,7 +1010,9 @@ public void test_serialization_invalidDecimalPlaces() throws Exception { oos.writeObject(m); oos.close(); ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); - ois.readObject(); + assertThrows(InvalidObjectException.class, () -> { + ois.readObject(); + }); } } @@ -913,12 +1020,12 @@ public void test_serialization_invalidDecimalPlaces() throws Exception { // getCurrencyUnit() //----------------------------------------------------------------------- @Test - public void test_getCurrencyUnit_GBP() { + void test_getCurrencyUnit_GBP() { assertEquals(GBP, GBP_2_34.getCurrencyUnit()); } @Test - public void test_getCurrencyUnit_EUR() { + void test_getCurrencyUnit_EUR() { assertEquals(EUR, BigMoney.parse("EUR -5.78").getCurrencyUnit()); } @@ -926,38 +1033,40 @@ public void test_getCurrencyUnit_EUR() { // withCurrencyUnit(Currency) //----------------------------------------------------------------------- @Test - public void test_withCurrencyUnit_Currency() { + void test_withCurrencyUnit_Currency() { BigMoney test = GBP_2_34.withCurrencyUnit(USD); assertEquals("USD 2.34", test.toString()); } @Test - public void test_withCurrencyUnit_Currency_same() { + void test_withCurrencyUnit_Currency_same() { BigMoney test = GBP_2_34.withCurrencyUnit(GBP); assertSame(GBP_2_34, test); } @Test - public void test_withCurrencyUnit_Currency_differentCurrencyScale() { + void test_withCurrencyUnit_Currency_differentCurrencyScale() { BigMoney test = GBP_2_34.withCurrencyUnit(JPY); assertEquals("JPY 2.34", test.toString()); } - @Test(expected = NullPointerException.class) - public void test_withCurrencyUnit_Currency_nullCurrency() { - GBP_2_34.withCurrencyUnit((CurrencyUnit) null); + @Test + void test_withCurrencyUnit_Currency_nullCurrency() { + assertThrows(NullPointerException.class, () -> { + GBP_2_34.withCurrencyUnit((CurrencyUnit) null); + }); } //----------------------------------------------------------------------- // getScale() //----------------------------------------------------------------------- @Test - public void test_getScale_GBP() { + void test_getScale_GBP() { assertEquals(2, GBP_2_34.getScale()); } @Test - public void test_getScale_JPY() { + void test_getScale_JPY() { assertEquals(0, JPY_423.getScale()); } @@ -965,54 +1074,56 @@ public void test_getScale_JPY() { // isCurrencyScale() //----------------------------------------------------------------------- @Test - public void test_isCurrencyScale_GBP() { - assertEquals(false, BigMoney.parse("GBP 2").isCurrencyScale()); - assertEquals(false, BigMoney.parse("GBP 2.3").isCurrencyScale()); - assertEquals(true, BigMoney.parse("GBP 2.34").isCurrencyScale()); - assertEquals(false, BigMoney.parse("GBP 2.345").isCurrencyScale()); + void test_isCurrencyScale_GBP() { + assertFalse(BigMoney.parse("GBP 2").isCurrencyScale()); + assertFalse(BigMoney.parse("GBP 2.3").isCurrencyScale()); + assertTrue(BigMoney.parse("GBP 2.34").isCurrencyScale()); + assertFalse(BigMoney.parse("GBP 2.345").isCurrencyScale()); } @Test - public void test_isCurrencyScale_JPY() { - assertEquals(true, BigMoney.parse("JPY 2").isCurrencyScale()); - assertEquals(false, BigMoney.parse("JPY 2.3").isCurrencyScale()); - assertEquals(false, BigMoney.parse("JPY 2.34").isCurrencyScale()); - assertEquals(false, BigMoney.parse("JPY 2.345").isCurrencyScale()); + void test_isCurrencyScale_JPY() { + assertTrue(BigMoney.parse("JPY 2").isCurrencyScale()); + assertFalse(BigMoney.parse("JPY 2.3").isCurrencyScale()); + assertFalse(BigMoney.parse("JPY 2.34").isCurrencyScale()); + assertFalse(BigMoney.parse("JPY 2.345").isCurrencyScale()); } //----------------------------------------------------------------------- // withScale(int) //----------------------------------------------------------------------- @Test - public void test_withScale_int_same() { + void test_withScale_int_same() { BigMoney test = GBP_2_34.withScale(2); assertSame(GBP_2_34, test); } @Test - public void test_withScale_int_more() { + void test_withScale_int_more() { BigMoney test = GBP_2_34.withScale(3); assertEquals(bd("2.340"), test.getAmount()); assertEquals(3, test.getScale()); } - @Test(expected = ArithmeticException.class) - public void test_withScale_int_less() { - BigMoney.parse("GBP 2.345").withScale(2); + @Test + void test_withScale_int_less() { + assertThrows(ArithmeticException.class, () -> { + BigMoney.parse("GBP 2.345").withScale(2); + }); } //----------------------------------------------------------------------- // withScale(int,RoundingMode) //----------------------------------------------------------------------- @Test - public void test_withScale_intRoundingMode_less() { + void test_withScale_intRoundingMode_less() { BigMoney test = GBP_2_34.withScale(1, RoundingMode.UP); assertEquals(bd("2.4"), test.getAmount()); assertEquals(1, test.getScale()); } @Test - public void test_withScale_intRoundingMode_more() { + void test_withScale_intRoundingMode_more() { BigMoney test = GBP_2_34.withScale(3, RoundingMode.UP); assertEquals(bd("2.340"), test.getAmount()); assertEquals(3, test.getScale()); @@ -1022,42 +1133,44 @@ public void test_withScale_intRoundingMode_more() { // withCurrencyScale() //----------------------------------------------------------------------- @Test - public void test_withCurrencyScale_int_same() { + void test_withCurrencyScale_int_same() { BigMoney test = GBP_2_34.withCurrencyScale(); assertSame(GBP_2_34, test); } @Test - public void test_withCurrencyScale_int_more() { + void test_withCurrencyScale_int_more() { BigMoney test = BigMoney.parse("GBP 2.3").withCurrencyScale(); assertEquals(bd("2.30"), test.getAmount()); assertEquals(2, test.getScale()); } - @Test(expected = ArithmeticException.class) - public void test_withCurrencyScale_int_less() { - BigMoney.parse("GBP 2.345").withCurrencyScale(); + @Test + void test_withCurrencyScale_int_less() { + assertThrows(ArithmeticException.class, () -> { + BigMoney.parse("GBP 2.345").withCurrencyScale(); + }); } //----------------------------------------------------------------------- // withCurrencyScale(RoundingMode) //----------------------------------------------------------------------- @Test - public void test_withCurrencyScale_intRoundingMode_less() { + void test_withCurrencyScale_intRoundingMode_less() { BigMoney test = BigMoney.parse("GBP 2.345").withCurrencyScale(RoundingMode.UP); assertEquals(bd("2.35"), test.getAmount()); assertEquals(2, test.getScale()); } @Test - public void test_withCurrencyScale_intRoundingMode_more() { + void test_withCurrencyScale_intRoundingMode_more() { BigMoney test = BigMoney.parse("GBP 2.3").withCurrencyScale(RoundingMode.UP); assertEquals(bd("2.30"), test.getAmount()); assertEquals(2, test.getScale()); } @Test - public void test_withCurrencyScale_intRoundingMode_lessJPY() { + void test_withCurrencyScale_intRoundingMode_lessJPY() { BigMoney test = BigMoney.parse("JPY 2.345").withCurrencyScale(RoundingMode.UP); assertEquals(bd("3"), test.getAmount()); assertEquals(0, test.getScale()); @@ -1067,12 +1180,12 @@ public void test_withCurrencyScale_intRoundingMode_lessJPY() { // getAmount() //----------------------------------------------------------------------- @Test - public void test_getAmount_positive() { + void test_getAmount_positive() { assertEquals(BIGDEC_2_34, GBP_2_34.getAmount()); } @Test - public void test_getAmount_negative() { + void test_getAmount_negative() { assertEquals(BIGDEC_M5_78, GBP_M5_78.getAmount()); } @@ -1080,12 +1193,12 @@ public void test_getAmount_negative() { // getAmountMajor() //----------------------------------------------------------------------- @Test - public void test_getAmountMajor_positive() { + void test_getAmountMajor_positive() { assertEquals(BigDecimal.valueOf(2), GBP_2_34.getAmountMajor()); } @Test - public void test_getAmountMajor_negative() { + void test_getAmountMajor_negative() { assertEquals(BigDecimal.valueOf(-5), GBP_M5_78.getAmountMajor()); } @@ -1093,58 +1206,66 @@ public void test_getAmountMajor_negative() { // getAmountMajorLong() //----------------------------------------------------------------------- @Test - public void test_getAmountMajorLong_positive() { + void test_getAmountMajorLong_positive() { assertEquals(2L, GBP_2_34.getAmountMajorLong()); } @Test - public void test_getAmountMajorLong_negative() { + void test_getAmountMajorLong_negative() { assertEquals(-5L, GBP_M5_78.getAmountMajorLong()); } - @Test(expected = ArithmeticException.class) - public void test_getAmountMajorLong_tooBigPositive() { - GBP_LONG_MAX_MAJOR_PLUS1.getAmountMajorLong(); + @Test + void test_getAmountMajorLong_tooBigPositive() { + assertThrows(ArithmeticException.class, () -> { + GBP_LONG_MAX_MAJOR_PLUS1.getAmountMajorLong(); + }); } - @Test(expected = ArithmeticException.class) - public void test_getAmountMajorLong_tooBigNegative() { - GBP_LONG_MIN_MAJOR_MINUS1.getAmountMajorLong(); + @Test + void test_getAmountMajorLong_tooBigNegative() { + assertThrows(ArithmeticException.class, () -> { + GBP_LONG_MIN_MAJOR_MINUS1.getAmountMajorLong(); + }); } //----------------------------------------------------------------------- // getAmountMajorInt() //----------------------------------------------------------------------- @Test - public void test_getAmountMajorInt_positive() { + void test_getAmountMajorInt_positive() { assertEquals(2, GBP_2_34.getAmountMajorInt()); } @Test - public void test_getAmountMajorInt_negative() { + void test_getAmountMajorInt_negative() { assertEquals(-5, GBP_M5_78.getAmountMajorInt()); } - @Test(expected = ArithmeticException.class) - public void test_getAmountMajorInt_tooBigPositive() { - GBP_INT_MAX_MAJOR_PLUS1.getAmountMajorInt(); + @Test + void test_getAmountMajorInt_tooBigPositive() { + assertThrows(ArithmeticException.class, () -> { + GBP_INT_MAX_MAJOR_PLUS1.getAmountMajorInt(); + }); } - @Test(expected = ArithmeticException.class) - public void test_getAmountMajorInt_tooBigNegative() { - GBP_INT_MIN_MAJOR_MINUS1.getAmountMajorInt(); + @Test + void test_getAmountMajorInt_tooBigNegative() { + assertThrows(ArithmeticException.class, () -> { + GBP_INT_MIN_MAJOR_MINUS1.getAmountMajorInt(); + }); } //----------------------------------------------------------------------- // getAmountMinor() //----------------------------------------------------------------------- @Test - public void test_getAmountMinor_positive() { + void test_getAmountMinor_positive() { assertEquals(BigDecimal.valueOf(234), GBP_2_34.getAmountMinor()); } @Test - public void test_getAmountMinor_negative() { + void test_getAmountMinor_negative() { assertEquals(BigDecimal.valueOf(-578), GBP_M5_78.getAmountMinor()); } @@ -1152,58 +1273,66 @@ public void test_getAmountMinor_negative() { // getAmountMinorLong() //----------------------------------------------------------------------- @Test - public void test_getAmountMinorLong_positive() { + void test_getAmountMinorLong_positive() { assertEquals(234L, GBP_2_34.getAmountMinorLong()); } @Test - public void test_getAmountMinorLong_negative() { + void test_getAmountMinorLong_negative() { assertEquals(-578L, GBP_M5_78.getAmountMinorLong()); } - @Test(expected = ArithmeticException.class) - public void test_getAmountMinorLong_tooBigPositive() { - GBP_LONG_MAX_PLUS1.getAmountMinorLong(); + @Test + void test_getAmountMinorLong_tooBigPositive() { + assertThrows(ArithmeticException.class, () -> { + GBP_LONG_MAX_PLUS1.getAmountMinorLong(); + }); } - @Test(expected = ArithmeticException.class) - public void test_getAmountMinorLong_tooBigNegative() { - GBP_LONG_MIN_MINUS1.getAmountMinorLong(); + @Test + void test_getAmountMinorLong_tooBigNegative() { + assertThrows(ArithmeticException.class, () -> { + GBP_LONG_MIN_MINUS1.getAmountMinorLong(); + }); } //----------------------------------------------------------------------- // getAmountMinorInt() //----------------------------------------------------------------------- @Test - public void test_getAmountMinorInt_positive() { + void test_getAmountMinorInt_positive() { assertEquals(234, GBP_2_34.getAmountMinorInt()); } @Test - public void test_getAmountMinorInt_negative() { + void test_getAmountMinorInt_negative() { assertEquals(-578, GBP_M5_78.getAmountMinorInt()); } - @Test(expected = ArithmeticException.class) - public void test_getAmountMinorInt_tooBigPositive() { - GBP_INT_MAX_PLUS1.getAmountMinorInt(); + @Test + void test_getAmountMinorInt_tooBigPositive() { + assertThrows(ArithmeticException.class, () -> { + GBP_INT_MAX_PLUS1.getAmountMinorInt(); + }); } - @Test(expected = ArithmeticException.class) - public void test_getAmountMinorInt_tooBigNegative() { - GBP_INT_MIN_MINUS1.getAmountMinorInt(); + @Test + void test_getAmountMinorInt_tooBigNegative() { + assertThrows(ArithmeticException.class, () -> { + GBP_INT_MIN_MINUS1.getAmountMinorInt(); + }); } //----------------------------------------------------------------------- // getMinorPart() //----------------------------------------------------------------------- @Test - public void test_getMinorPart_positive() { + void test_getMinorPart_positive() { assertEquals(34, GBP_2_34.getMinorPart()); } @Test - public void test_getMinorPart_negative() { + void test_getMinorPart_negative() { assertEquals(-78, GBP_M5_78.getMinorPart()); } @@ -1211,85 +1340,87 @@ public void test_getMinorPart_negative() { // isZero() //----------------------------------------------------------------------- @Test - public void test_isZero() { - assertEquals(true, GBP_0_00.isZero()); - assertEquals(false, GBP_2_34.isZero()); - assertEquals(false, GBP_M5_78.isZero()); + void test_isZero() { + assertTrue(GBP_0_00.isZero()); + assertFalse(GBP_2_34.isZero()); + assertFalse(GBP_M5_78.isZero()); } //----------------------------------------------------------------------- // isPositive() //----------------------------------------------------------------------- @Test - public void test_isPositive() { - assertEquals(false, GBP_0_00.isPositive()); - assertEquals(true, GBP_2_34.isPositive()); - assertEquals(false, GBP_M5_78.isPositive()); + void test_isPositive() { + assertFalse(GBP_0_00.isPositive()); + assertTrue(GBP_2_34.isPositive()); + assertFalse(GBP_M5_78.isPositive()); } //----------------------------------------------------------------------- // isPositiveOrZero() //----------------------------------------------------------------------- @Test - public void test_isPositiveOrZero() { - assertEquals(true, GBP_0_00.isPositiveOrZero()); - assertEquals(true, GBP_2_34.isPositiveOrZero()); - assertEquals(false, GBP_M5_78.isPositiveOrZero()); + void test_isPositiveOrZero() { + assertTrue(GBP_0_00.isPositiveOrZero()); + assertTrue(GBP_2_34.isPositiveOrZero()); + assertFalse(GBP_M5_78.isPositiveOrZero()); } //----------------------------------------------------------------------- // isNegative() //----------------------------------------------------------------------- @Test - public void test_isNegative() { - assertEquals(false, GBP_0_00.isNegative()); - assertEquals(false, GBP_2_34.isNegative()); - assertEquals(true, GBP_M5_78.isNegative()); + void test_isNegative() { + assertFalse(GBP_0_00.isNegative()); + assertFalse(GBP_2_34.isNegative()); + assertTrue(GBP_M5_78.isNegative()); } //----------------------------------------------------------------------- // isNegativeOrZero() //----------------------------------------------------------------------- @Test - public void test_isNegativeOrZero() { - assertEquals(true, GBP_0_00.isNegativeOrZero()); - assertEquals(false, GBP_2_34.isNegativeOrZero()); - assertEquals(true, GBP_M5_78.isNegativeOrZero()); + void test_isNegativeOrZero() { + assertTrue(GBP_0_00.isNegativeOrZero()); + assertFalse(GBP_2_34.isNegativeOrZero()); + assertTrue(GBP_M5_78.isNegativeOrZero()); } //----------------------------------------------------------------------- // withAmount(BigDecimal) //----------------------------------------------------------------------- @Test - public void test_withAmount_BigDecimal() { + void test_withAmount_BigDecimal() { BigMoney test = GBP_2_34.withAmount(BIGDEC_2_345); assertEquals(bd("2.345"), test.getAmount()); assertEquals(3, test.getScale()); } @Test - public void test_withAmount_BigDecimal_same() { + void test_withAmount_BigDecimal_same() { BigMoney test = GBP_2_34.withAmount(BIGDEC_2_34); assertSame(GBP_2_34, test); } - @Test(expected = NullPointerException.class) - public void test_withAmount_BigDecimal_nullBigDecimal() { - GBP_2_34.withAmount((BigDecimal) null); + @Test + void test_withAmount_BigDecimal_nullBigDecimal() { + assertThrows(NullPointerException.class, () -> { + GBP_2_34.withAmount((BigDecimal) null); + }); } //----------------------------------------------------------------------- // withAmount(double) //----------------------------------------------------------------------- @Test - public void test_withAmount_double() { + void test_withAmount_double() { BigMoney test = GBP_2_34.withAmount(2.345d); assertEquals(bd("2.345"), test.getAmount()); assertEquals(3, test.getScale()); } @Test - public void test_withAmount_double_same() { + void test_withAmount_double_same() { BigMoney test = GBP_2_34.withAmount(2.34d); assertSame(GBP_2_34, test); } @@ -1298,28 +1429,28 @@ public void test_withAmount_double_same() { // plus(Iterable) //----------------------------------------------------------------------- @Test - public void test_plus_Iterable_BigMoneyProvider() { + void test_plus_Iterable_BigMoneyProvider() { Iterable iterable = Arrays.asList(GBP_2_33, GBP_1_23); BigMoney test = GBP_2_34.plus(iterable); assertEquals("GBP 5.90", test.toString()); } @Test - public void test_plus_Iterable_BigMoney() { + void test_plus_Iterable_BigMoney() { Iterable iterable = Arrays.asList(GBP_2_33, GBP_1_23); BigMoney test = GBP_2_34.plus(iterable); assertEquals("GBP 5.90", test.toString()); } @Test - public void test_plus_Iterable_Money() { + void test_plus_Iterable_Money() { Iterable iterable = Arrays.asList(GBP_2_33.toMoney(), GBP_1_23.toMoney()); BigMoney test = GBP_2_34.plus(iterable); assertEquals("GBP 5.90", test.toString()); } @Test - public void test_plus_Iterable_Mixed() { + void test_plus_Iterable_Mixed() { Iterable iterable = Arrays.asList(GBP_2_33.toMoney(), new BigMoneyProvider() { @Override public BigMoney toBigMoney() { @@ -1331,94 +1462,109 @@ public BigMoney toBigMoney() { } @Test - public void test_plus_Iterable_zero() { + void test_plus_Iterable_zero() { Iterable iterable = Arrays.asList(GBP_0_00); BigMoney test = GBP_2_34.plus(iterable); assertEquals(GBP_2_34, test); } - @Test(expected = CurrencyMismatchException.class) - public void test_plus_Iterable_currencyMismatch() { + @Test + void test_plus_Iterable_currencyMismatch() { Iterable iterable = Arrays.asList(GBP_2_33, JPY_423); - GBP_M5_78.plus(iterable); + assertThrows(CurrencyMismatchException.class, () -> { + GBP_M5_78.plus(iterable); + }); } - @Test(expected = NullPointerException.class) - public void test_plus_Iterable_nullEntry() { + @Test + void test_plus_Iterable_nullEntry() { Iterable iterable = Arrays.asList(GBP_2_33, null); - GBP_M5_78.plus(iterable); + assertThrows(NullPointerException.class, () -> { + GBP_M5_78.plus(iterable); + }); } - @Test(expected = NullPointerException.class) - public void test_plus_Iterable_nullIterable() { - GBP_M5_78.plus((Iterable) null); + @Test + void test_plus_Iterable_nullIterable() { + assertThrows(NullPointerException.class, () -> { + GBP_M5_78.plus((Iterable) null); + }); } - @Test(expected = NullPointerException.class) - public void test_plus_Iterable_badProvider() { + @Test + void test_plus_Iterable_badProvider() { Iterable iterable = Arrays.asList(new BigMoneyProvider() { @Override public BigMoney toBigMoney() { return null; } }); - GBP_M5_78.plus(iterable); + assertThrows(NullPointerException.class, () -> { + GBP_M5_78.plus(iterable); + }); } //----------------------------------------------------------------------- // plus(BigMoneyProvider) //----------------------------------------------------------------------- @Test - public void test_plus_BigMoneyProvider_zero() { + void test_plus_BigMoneyProvider_zero() { BigMoney test = GBP_2_34.plus(GBP_0_00); assertSame(GBP_2_34, test); } @Test - public void test_plus_BigMoneyProvider_positive() { + void test_plus_BigMoneyProvider_positive() { BigMoney test = GBP_2_34.plus(GBP_1_23); assertEquals("GBP 3.57", test.toString()); assertEquals(2, test.getScale()); } @Test - public void test_plus_BigMoneyProvider_negative() { + void test_plus_BigMoneyProvider_negative() { BigMoney test = GBP_2_34.plus(GBP_M1_23); assertEquals("GBP 1.11", test.toString()); assertEquals(2, test.getScale()); } @Test - public void test_plus_BigMoneyProvider_scale() { + void test_plus_BigMoneyProvider_scale() { BigMoney test = GBP_2_34.plus(BigMoney.parse("GBP 1.111")); assertEquals("GBP 3.451", test.toString()); assertEquals(3, test.getScale()); } @Test - public void test_plus_BigMoneyProvider_Money() { + void test_plus_BigMoneyProvider_Money() { BigMoney test = GBP_2_34.plus(BigMoney.ofMinor(GBP, 1)); assertEquals("GBP 2.35", test.toString()); assertEquals(2, test.getScale()); } - @Test(expected = CurrencyMismatchException.class) - public void test_plus_BigMoneyProvider_currencyMismatch() { - GBP_M5_78.plus(USD_1_23); + @Test + void test_plus_BigMoneyProvider_currencyMismatch() { + assertThrows(CurrencyMismatchException.class, () -> { + GBP_M5_78.plus(USD_1_23); + }); } - @Test(expected = NullPointerException.class) - public void test_plus_BigMoneyProvider_nullBigMoneyProvider() { - GBP_M5_78.plus((BigMoneyProvider) null); + @Test + void test_plus_BigMoneyProvider_nullBigMoneyProvider() { + assertThrows(NullPointerException.class, () -> { + GBP_M5_78.plus((BigMoneyProvider) null); + }); } - @Test(expected = NullPointerException.class) - public void test_plus_BigMoneyProvider_badProvider() { - GBP_M5_78.plus(new BigMoneyProvider() { + @Test + void test_plus_BigMoneyProvider_badProvider() { + BigMoneyProvider provider = new BigMoneyProvider() { @Override public BigMoney toBigMoney() { return null; } + }; + assertThrows(NullPointerException.class, () -> { + GBP_M5_78.plus(provider); }); } @@ -1426,62 +1572,64 @@ public BigMoney toBigMoney() { // plus(BigDecimal) //----------------------------------------------------------------------- @Test - public void test_plus_BigDecimal_zero() { + void test_plus_BigDecimal_zero() { BigMoney test = GBP_2_34.plus(BigDecimal.ZERO); assertSame(GBP_2_34, test); } @Test - public void test_plus_BigDecimal_positive() { + void test_plus_BigDecimal_positive() { BigMoney test = GBP_2_34.plus(bd("1.23")); assertEquals("GBP 3.57", test.toString()); assertEquals(2, test.getScale()); } @Test - public void test_plus_BigDecimal_negative() { + void test_plus_BigDecimal_negative() { BigMoney test = GBP_2_34.plus(bd("-1.23")); assertEquals("GBP 1.11", test.toString()); assertEquals(2, test.getScale()); } @Test - public void test_plus_BigDecimal_scale() { + void test_plus_BigDecimal_scale() { BigMoney test = GBP_2_34.plus(bd("1.235")); assertEquals("GBP 3.575", test.toString()); assertEquals(3, test.getScale()); } - @Test(expected = NullPointerException.class) - public void test_plus_BigDecimal_nullBigDecimal() { - GBP_M5_78.plus((BigDecimal) null); + @Test + void test_plus_BigDecimal_nullBigDecimal() { + assertThrows(NullPointerException.class, () -> { + GBP_M5_78.plus((BigDecimal) null); + }); } //----------------------------------------------------------------------- // plus(double) //----------------------------------------------------------------------- @Test - public void test_plus_double_zero() { + void test_plus_double_zero() { BigMoney test = GBP_2_34.plus(0d); assertSame(GBP_2_34, test); } @Test - public void test_plus_double_positive() { + void test_plus_double_positive() { BigMoney test = GBP_2_34.plus(1.23d); assertEquals("GBP 3.57", test.toString()); assertEquals(2, test.getScale()); } @Test - public void test_plus_double_negative() { + void test_plus_double_negative() { BigMoney test = GBP_2_34.plus(-1.23d); assertEquals("GBP 1.11", test.toString()); assertEquals(2, test.getScale()); } @Test - public void test_plus_double_scale() { + void test_plus_double_scale() { BigMoney test = GBP_2_34.plus(1.234d); assertEquals("GBP 3.574", test.toString()); assertEquals(3, test.getScale()); @@ -1491,20 +1639,20 @@ public void test_plus_double_scale() { // plusMajor(long) //----------------------------------------------------------------------- @Test - public void test_plusMajor_zero() { + void test_plusMajor_zero() { BigMoney test = GBP_2_34.plusMajor(0); assertSame(GBP_2_34, test); } @Test - public void test_plusMajor_positive() { + void test_plusMajor_positive() { BigMoney test = GBP_2_34.plusMajor(123); assertEquals("GBP 125.34", test.toString()); assertEquals(2, test.getScale()); } @Test - public void test_plusMajor_negative() { + void test_plusMajor_negative() { BigMoney test = GBP_2_34.plusMajor(-123); assertEquals("GBP -120.66", test.toString()); assertEquals(2, test.getScale()); @@ -1514,27 +1662,27 @@ public void test_plusMajor_negative() { // plusMinor(long) //----------------------------------------------------------------------- @Test - public void test_plusMinor_zero() { + void test_plusMinor_zero() { BigMoney test = GBP_2_34.plusMinor(0); assertSame(GBP_2_34, test); } @Test - public void test_plusMinor_positive() { + void test_plusMinor_positive() { BigMoney test = GBP_2_34.plusMinor(123); assertEquals("GBP 3.57", test.toString()); assertEquals(2, test.getScale()); } @Test - public void test_plusMinor_negative() { + void test_plusMinor_negative() { BigMoney test = GBP_2_34.plusMinor(-123); assertEquals("GBP 1.11", test.toString()); assertEquals(2, test.getScale()); } @Test - public void test_plusMinor_scale() { + void test_plusMinor_scale() { BigMoney test = BigMoney.parse("GBP 12").plusMinor(123); assertEquals("GBP 13.23", test.toString()); assertEquals(2, test.getScale()); @@ -1544,149 +1692,165 @@ public void test_plusMinor_scale() { // plusRetainScale(BigMoneyProvider,RoundingMode) //----------------------------------------------------------------------- @Test - public void test_plusRetainScale_BigMoneyProviderRoundingMode_zero() { + void test_plusRetainScale_BigMoneyProviderRoundingMode_zero() { BigMoney test = GBP_2_34.plusRetainScale(BigMoney.zero(GBP), RoundingMode.UNNECESSARY); assertSame(GBP_2_34, test); } @Test - public void test_plusRetainScale_BigMoneyProviderRoundingMode_positive() { + void test_plusRetainScale_BigMoneyProviderRoundingMode_positive() { BigMoney test = GBP_2_34.plusRetainScale(BigMoney.parse("GBP 1.23"), RoundingMode.UNNECESSARY); assertEquals("GBP 3.57", test.toString()); } @Test - public void test_plusRetainScale_BigMoneyProviderRoundingMode_negative() { + void test_plusRetainScale_BigMoneyProviderRoundingMode_negative() { BigMoney test = GBP_2_34.plusRetainScale(BigMoney.parse("GBP -1.23"), RoundingMode.UNNECESSARY); assertEquals("GBP 1.11", test.toString()); } @Test - public void test_plusRetainScale_BigMoneyProviderRoundingMode_roundDown() { + void test_plusRetainScale_BigMoneyProviderRoundingMode_roundDown() { BigMoney test = GBP_2_34.plusRetainScale(BigMoney.parse("GBP 1.235"), RoundingMode.DOWN); assertEquals("GBP 3.57", test.toString()); } - @Test(expected = ArithmeticException.class) - public void test_plusRetainScale_BigMoneyProviderRoundingMode_roundUnecessary() { - GBP_2_34.plusRetainScale(BigMoney.parse("GBP 1.235"), RoundingMode.UNNECESSARY); + @Test + void test_plusRetainScale_BigMoneyProviderRoundingMode_roundUnecessary() { + assertThrows(ArithmeticException.class, () -> { + GBP_2_34.plusRetainScale(BigMoney.parse("GBP 1.235"), RoundingMode.UNNECESSARY); + }); } - @Test(expected = NullPointerException.class) - public void test_plusRetainScale_BigMoneyProviderRoundingMode_nullBigDecimal() { - GBP_M5_78.plusRetainScale((BigDecimal) null, RoundingMode.UNNECESSARY); + @Test + void test_plusRetainScale_BigMoneyProviderRoundingMode_nullBigDecimal() { + assertThrows(NullPointerException.class, () -> { + GBP_M5_78.plusRetainScale((BigDecimal) null, RoundingMode.UNNECESSARY); + }); } - @Test(expected = NullPointerException.class) - public void test_plusRetainScale_BigMoneyProviderRoundingMode_nullRoundingMode() { - GBP_M5_78.plusRetainScale(BigMoney.parse("GBP 1.23"), (RoundingMode) null); + @Test + void test_plusRetainScale_BigMoneyProviderRoundingMode_nullRoundingMode() { + assertThrows(NullPointerException.class, () -> { + GBP_M5_78.plusRetainScale(BigMoney.parse("GBP 1.23"), (RoundingMode) null); + }); } //----------------------------------------------------------------------- // plusRetainScale(BigDecimal,RoundingMode) //----------------------------------------------------------------------- @Test - public void test_plusRetainScale_BigDecimalRoundingMode_zero() { + void test_plusRetainScale_BigDecimalRoundingMode_zero() { BigMoney test = GBP_2_34.plusRetainScale(BigDecimal.ZERO, RoundingMode.UNNECESSARY); assertSame(GBP_2_34, test); } @Test - public void test_plusRetainScale_BigDecimalRoundingMode_positive() { + void test_plusRetainScale_BigDecimalRoundingMode_positive() { BigMoney test = GBP_2_34.plusRetainScale(bd("1.23"), RoundingMode.UNNECESSARY); assertEquals("GBP 3.57", test.toString()); } @Test - public void test_plusRetainScale_BigDecimalRoundingMode_negative() { + void test_plusRetainScale_BigDecimalRoundingMode_negative() { BigMoney test = GBP_2_34.plusRetainScale(bd("-1.23"), RoundingMode.UNNECESSARY); assertEquals("GBP 1.11", test.toString()); } @Test - public void test_plusRetainScale_BigDecimalRoundingMode_roundDown() { + void test_plusRetainScale_BigDecimalRoundingMode_roundDown() { BigMoney test = GBP_2_34.plusRetainScale(bd("1.235"), RoundingMode.DOWN); assertEquals("GBP 3.57", test.toString()); } - @Test(expected = ArithmeticException.class) - public void test_plusRetainScale_BigDecimalRoundingMode_roundUnecessary() { - GBP_2_34.plusRetainScale(bd("1.235"), RoundingMode.UNNECESSARY); + @Test + void test_plusRetainScale_BigDecimalRoundingMode_roundUnecessary() { + assertThrows(ArithmeticException.class, () -> { + GBP_2_34.plusRetainScale(bd("1.235"), RoundingMode.UNNECESSARY); + }); } - @Test(expected = NullPointerException.class) - public void test_plusRetainScale_BigDecimalRoundingMode_nullBigDecimal() { - GBP_M5_78.plusRetainScale((BigDecimal) null, RoundingMode.UNNECESSARY); + @Test + void test_plusRetainScale_BigDecimalRoundingMode_nullBigDecimal() { + assertThrows(NullPointerException.class, () -> { + GBP_M5_78.plusRetainScale((BigDecimal) null, RoundingMode.UNNECESSARY); + }); } - @Test(expected = NullPointerException.class) - public void test_plusRetainScale_BigDecimalRoundingMode_nullRoundingMode() { - GBP_M5_78.plusRetainScale(BIGDEC_2_34, (RoundingMode) null); + @Test + void test_plusRetainScale_BigDecimalRoundingMode_nullRoundingMode() { + assertThrows(NullPointerException.class, () -> { + GBP_M5_78.plusRetainScale(BIGDEC_2_34, (RoundingMode) null); + }); } //----------------------------------------------------------------------- // plusRetainScale(double,RoundingMode) //----------------------------------------------------------------------- @Test - public void test_plusRetainScale_doubleRoundingMode_zero() { + void test_plusRetainScale_doubleRoundingMode_zero() { BigMoney test = GBP_2_34.plusRetainScale(0d, RoundingMode.UNNECESSARY); assertSame(GBP_2_34, test); } @Test - public void test_plusRetainScale_doubleRoundingMode_positive() { + void test_plusRetainScale_doubleRoundingMode_positive() { BigMoney test = GBP_2_34.plusRetainScale(1.23d, RoundingMode.UNNECESSARY); assertEquals("GBP 3.57", test.toString()); } @Test - public void test_plusRetainScale_doubleRoundingMode_negative() { + void test_plusRetainScale_doubleRoundingMode_negative() { BigMoney test = GBP_2_34.plusRetainScale(-1.23d, RoundingMode.UNNECESSARY); assertEquals("GBP 1.11", test.toString()); } @Test - public void test_plusRetainScale_doubleRoundingMode_roundDown() { + void test_plusRetainScale_doubleRoundingMode_roundDown() { BigMoney test = GBP_2_34.plusRetainScale(1.235d, RoundingMode.DOWN); assertEquals("GBP 3.57", test.toString()); } - @Test(expected = ArithmeticException.class) - public void test_plusRetainScale_doubleRoundingMode_roundUnecessary() { - GBP_2_34.plusRetainScale(1.235d, RoundingMode.UNNECESSARY); + @Test + void test_plusRetainScale_doubleRoundingMode_roundUnecessary() { + assertThrows(ArithmeticException.class, () -> { + GBP_2_34.plusRetainScale(1.235d, RoundingMode.UNNECESSARY); + }); } - @Test(expected = NullPointerException.class) - public void test_plusRetainScale_doubleRoundingMode_nullRoundingMode() { - GBP_M5_78.plusRetainScale(2.34d, (RoundingMode) null); + @Test + void test_plusRetainScale_doubleRoundingMode_nullRoundingMode() { + assertThrows(NullPointerException.class, () -> { + GBP_M5_78.plusRetainScale(2.34d, (RoundingMode) null); + }); } //----------------------------------------------------------------------- // minus(Iterable) //----------------------------------------------------------------------- @Test - public void test_minus_Iterable_BigMoneyProvider() { + void test_minus_Iterable_BigMoneyProvider() { Iterable iterable = Arrays.asList(GBP_2_33, GBP_1_23); BigMoney test = GBP_2_34.minus(iterable); assertEquals("GBP -1.22", test.toString()); } @Test - public void test_minus_Iterable_BigMoney() { + void test_minus_Iterable_BigMoney() { Iterable iterable = Arrays.asList(GBP_2_33, GBP_1_23); BigMoney test = GBP_2_34.minus(iterable); assertEquals("GBP -1.22", test.toString()); } @Test - public void test_minus_Iterable_Money() { + void test_minus_Iterable_Money() { Iterable iterable = Arrays.asList(GBP_2_33.toMoney(), GBP_1_23.toMoney()); BigMoney test = GBP_2_34.minus(iterable); assertEquals("GBP -1.22", test.toString()); } @Test - public void test_minus_Iterable_Mixed() { + void test_minus_Iterable_Mixed() { Iterable iterable = Arrays.asList(GBP_2_33.toMoney(), new BigMoneyProvider() { @Override public BigMoney toBigMoney() { @@ -1698,94 +1862,109 @@ public BigMoney toBigMoney() { } @Test - public void test_minus_Iterable_zero() { + void test_minus_Iterable_zero() { Iterable iterable = Arrays.asList(GBP_0_00); BigMoney test = GBP_2_34.minus(iterable); assertEquals(GBP_2_34, test); } - @Test(expected = CurrencyMismatchException.class) - public void test_minus_Iterable_currencyMismatch() { + @Test + void test_minus_Iterable_currencyMismatch() { Iterable iterable = Arrays.asList(GBP_2_33, JPY_423); - GBP_M5_78.minus(iterable); + assertThrows(CurrencyMismatchException.class, () -> { + GBP_M5_78.minus(iterable); + }); } - @Test(expected = NullPointerException.class) - public void test_minus_Iterable_nullEntry() { + @Test + void test_minus_Iterable_nullEntry() { Iterable iterable = Arrays.asList(GBP_2_33, null); - GBP_M5_78.minus(iterable); + assertThrows(NullPointerException.class, () -> { + GBP_M5_78.minus(iterable); + }); } - @Test(expected = NullPointerException.class) - public void test_minus_Iterable_nullIterable() { - GBP_M5_78.minus((Iterable) null); + @Test + void test_minus_Iterable_nullIterable() { + assertThrows(NullPointerException.class, () -> { + GBP_M5_78.minus((Iterable) null); + }); } - @Test(expected = NullPointerException.class) - public void test_minus_Iterable_badProvider() { + @Test + void test_minus_Iterable_badProvider() { Iterable iterable = Arrays.asList(new BigMoneyProvider() { @Override public BigMoney toBigMoney() { return null; } }); - GBP_M5_78.minus(iterable); + assertThrows(NullPointerException.class, () -> { + GBP_M5_78.minus(iterable); + }); } //----------------------------------------------------------------------- // minus(BigMoneyProvider) //----------------------------------------------------------------------- @Test - public void test_minus_BigMoneyProvider_zero() { + void test_minus_BigMoneyProvider_zero() { BigMoney test = GBP_2_34.minus(GBP_0_00); assertSame(GBP_2_34, test); } @Test - public void test_minus_BigMoneyProvider_positive() { + void test_minus_BigMoneyProvider_positive() { BigMoney test = GBP_2_34.minus(GBP_1_23); assertEquals("GBP 1.11", test.toString()); assertEquals(2, test.getScale()); } @Test - public void test_minus_BigMoneyProvider_negative() { + void test_minus_BigMoneyProvider_negative() { BigMoney test = GBP_2_34.minus(GBP_M1_23); assertEquals("GBP 3.57", test.toString()); assertEquals(2, test.getScale()); } @Test - public void test_minus_BigMoneyProvider_scale() { + void test_minus_BigMoneyProvider_scale() { BigMoney test = GBP_2_34.minus(BigMoney.parse("GBP 1.111")); assertEquals("GBP 1.229", test.toString()); assertEquals(3, test.getScale()); } @Test - public void test_minus_BigMoneyProvider_Money() { + void test_minus_BigMoneyProvider_Money() { BigMoney test = GBP_2_34.minus(BigMoney.ofMinor(GBP, 1)); assertEquals("GBP 2.33", test.toString()); assertEquals(2, test.getScale()); } - @Test(expected = CurrencyMismatchException.class) - public void test_minus_BigMoneyProvider_currencyMismatch() { - GBP_M5_78.minus(USD_1_23); + @Test + void test_minus_BigMoneyProvider_currencyMismatch() { + assertThrows(CurrencyMismatchException.class, () -> { + GBP_M5_78.minus(USD_1_23); + }); } - @Test(expected = NullPointerException.class) - public void test_minus_BigMoneyProvider_nullBigMoneyProvider() { - GBP_M5_78.minus((BigMoneyProvider) null); + @Test + void test_minus_BigMoneyProvider_nullBigMoneyProvider() { + assertThrows(NullPointerException.class, () -> { + GBP_M5_78.minus((BigMoneyProvider) null); + }); } - @Test(expected = NullPointerException.class) - public void test_minus_BigMoneyProvider_badProvider() { - GBP_M5_78.minus(new BigMoneyProvider() { + @Test + void test_minus_BigMoneyProvider_badProvider() { + BigMoneyProvider provider = new BigMoneyProvider() { @Override public BigMoney toBigMoney() { return null; } + }; + assertThrows(NullPointerException.class, () -> { + GBP_M5_78.minus(provider); }); } @@ -1793,62 +1972,64 @@ public BigMoney toBigMoney() { // minus(BigDecimal) //----------------------------------------------------------------------- @Test - public void test_minus_BigDecimal_zero() { + void test_minus_BigDecimal_zero() { BigMoney test = GBP_2_34.minus(BigDecimal.ZERO); assertSame(GBP_2_34, test); } @Test - public void test_minus_BigDecimal_positive() { + void test_minus_BigDecimal_positive() { BigMoney test = GBP_2_34.minus(bd("1.23")); assertEquals("GBP 1.11", test.toString()); assertEquals(2, test.getScale()); } @Test - public void test_minus_BigDecimal_negative() { + void test_minus_BigDecimal_negative() { BigMoney test = GBP_2_34.minus(bd("-1.23")); assertEquals("GBP 3.57", test.toString()); assertEquals(2, test.getScale()); } @Test - public void test_minus_BigDecimal_scale() { + void test_minus_BigDecimal_scale() { BigMoney test = GBP_2_34.minus(bd("1.235")); assertEquals("GBP 1.105", test.toString()); assertEquals(3, test.getScale()); } - @Test(expected = NullPointerException.class) - public void test_minus_BigDecimal_nullBigDecimal() { - GBP_M5_78.minus((BigDecimal) null); + @Test + void test_minus_BigDecimal_nullBigDecimal() { + assertThrows(NullPointerException.class, () -> { + GBP_M5_78.minus((BigDecimal) null); + }); } //----------------------------------------------------------------------- // minus(double) //----------------------------------------------------------------------- @Test - public void test_minus_double_zero() { + void test_minus_double_zero() { BigMoney test = GBP_2_34.minus(0d); assertSame(GBP_2_34, test); } @Test - public void test_minus_double_positive() { + void test_minus_double_positive() { BigMoney test = GBP_2_34.minus(1.23d); assertEquals("GBP 1.11", test.toString()); assertEquals(2, test.getScale()); } @Test - public void test_minus_double_negative() { + void test_minus_double_negative() { BigMoney test = GBP_2_34.minus(-1.23d); assertEquals("GBP 3.57", test.toString()); assertEquals(2, test.getScale()); } @Test - public void test_minus_double_scale() { + void test_minus_double_scale() { BigMoney test = GBP_2_34.minus(1.235d); assertEquals("GBP 1.105", test.toString()); assertEquals(3, test.getScale()); @@ -1858,20 +2039,20 @@ public void test_minus_double_scale() { // minusMajor(long) //----------------------------------------------------------------------- @Test - public void test_minusMajor_zero() { + void test_minusMajor_zero() { BigMoney test = GBP_2_34.minusMajor(0); assertSame(GBP_2_34, test); } @Test - public void test_minusMajor_positive() { + void test_minusMajor_positive() { BigMoney test = GBP_2_34.minusMajor(123); assertEquals("GBP -120.66", test.toString()); assertEquals(2, test.getScale()); } @Test - public void test_minusMajor_negative() { + void test_minusMajor_negative() { BigMoney test = GBP_2_34.minusMajor(-123); assertEquals("GBP 125.34", test.toString()); assertEquals(2, test.getScale()); @@ -1881,27 +2062,27 @@ public void test_minusMajor_negative() { // minusMinor(long) //----------------------------------------------------------------------- @Test - public void test_minusMinor_zero() { + void test_minusMinor_zero() { BigMoney test = GBP_2_34.minusMinor(0); assertSame(GBP_2_34, test); } @Test - public void test_minusMinor_positive() { + void test_minusMinor_positive() { BigMoney test = GBP_2_34.minusMinor(123); assertEquals("GBP 1.11", test.toString()); assertEquals(2, test.getScale()); } @Test - public void test_minusMinor_negative() { + void test_minusMinor_negative() { BigMoney test = GBP_2_34.minusMinor(-123); assertEquals("GBP 3.57", test.toString()); assertEquals(2, test.getScale()); } @Test - public void test_minusMinor_scale() { + void test_minusMinor_scale() { BigMoney test = BigMoney.parse("GBP 12").minusMinor(123); assertEquals("GBP 10.77", test.toString()); assertEquals(2, test.getScale()); @@ -1911,169 +2092,187 @@ public void test_minusMinor_scale() { // minusRetainScale(BigMoneyProvider,RoundingMode) //----------------------------------------------------------------------- @Test - public void test_minusRetainScale_BigMoneyProviderRoundingMode_zero() { + void test_minusRetainScale_BigMoneyProviderRoundingMode_zero() { BigMoney test = GBP_2_34.minusRetainScale(BigMoney.zero(GBP), RoundingMode.UNNECESSARY); assertSame(GBP_2_34, test); } @Test - public void test_minusRetainScale_BigMoneyProviderRoundingMode_positive() { + void test_minusRetainScale_BigMoneyProviderRoundingMode_positive() { BigMoney test = GBP_2_34.minusRetainScale(BigMoney.parse("GBP 1.23"), RoundingMode.UNNECESSARY); assertEquals("GBP 1.11", test.toString()); } @Test - public void test_minusRetainScale_BigMoneyProviderRoundingMode_negative() { + void test_minusRetainScale_BigMoneyProviderRoundingMode_negative() { BigMoney test = GBP_2_34.minusRetainScale(BigMoney.parse("GBP -1.23"), RoundingMode.UNNECESSARY); assertEquals("GBP 3.57", test.toString()); } @Test - public void test_minusRetainScale_BigMoneyProviderRoundingMode_roundDown() { + void test_minusRetainScale_BigMoneyProviderRoundingMode_roundDown() { BigMoney test = GBP_2_34.minusRetainScale(BigMoney.parse("GBP 1.235"), RoundingMode.DOWN); assertEquals("GBP 1.10", test.toString()); } - @Test(expected = ArithmeticException.class) - public void test_minusRetainScale_BigMoneyProviderRoundingMode_roundUnecessary() { - GBP_2_34.minusRetainScale(BigMoney.parse("GBP 1.235"), RoundingMode.UNNECESSARY); + @Test + void test_minusRetainScale_BigMoneyProviderRoundingMode_roundUnecessary() { + assertThrows(ArithmeticException.class, () -> { + GBP_2_34.minusRetainScale(BigMoney.parse("GBP 1.235"), RoundingMode.UNNECESSARY); + }); } - @Test(expected = NullPointerException.class) - public void test_minusRetainScale_BigMoneyProviderRoundingMode_nullBigMoneyProvider() { - GBP_M5_78.minusRetainScale((BigMoneyProvider) null, RoundingMode.UNNECESSARY); + @Test + void test_minusRetainScale_BigMoneyProviderRoundingMode_nullBigMoneyProvider() { + assertThrows(NullPointerException.class, () -> { + GBP_M5_78.minusRetainScale((BigMoneyProvider) null, RoundingMode.UNNECESSARY); + }); } - @Test(expected = NullPointerException.class) - public void test_minusRetainScale_BigMoneyProviderRoundingMode_nullRoundingMode() { - GBP_M5_78.minusRetainScale(BigMoney.parse("GBP 123"), (RoundingMode) null); + @Test + void test_minusRetainScale_BigMoneyProviderRoundingMode_nullRoundingMode() { + assertThrows(NullPointerException.class, () -> { + GBP_M5_78.minusRetainScale(BigMoney.parse("GBP 123"), (RoundingMode) null); + }); } //----------------------------------------------------------------------- // minusRetainScale(BigDecimal,RoundingMode) //----------------------------------------------------------------------- @Test - public void test_minusRetainScale_BigDecimalRoundingMode_zero() { + void test_minusRetainScale_BigDecimalRoundingMode_zero() { BigMoney test = GBP_2_34.minusRetainScale(BigDecimal.ZERO, RoundingMode.UNNECESSARY); assertSame(GBP_2_34, test); } @Test - public void test_minusRetainScale_BigDecimalRoundingMode_positive() { + void test_minusRetainScale_BigDecimalRoundingMode_positive() { BigMoney test = GBP_2_34.minusRetainScale(bd("1.23"), RoundingMode.UNNECESSARY); assertEquals("GBP 1.11", test.toString()); } @Test - public void test_minusRetainScale_BigDecimalRoundingMode_negative() { + void test_minusRetainScale_BigDecimalRoundingMode_negative() { BigMoney test = GBP_2_34.minusRetainScale(bd("-1.23"), RoundingMode.UNNECESSARY); assertEquals("GBP 3.57", test.toString()); } @Test - public void test_minusRetainScale_BigDecimalRoundingMode_roundDown() { + void test_minusRetainScale_BigDecimalRoundingMode_roundDown() { BigMoney test = GBP_2_34.minusRetainScale(bd("1.235"), RoundingMode.DOWN); assertEquals("GBP 1.10", test.toString()); } - @Test(expected = ArithmeticException.class) - public void test_minusRetainScale_BigDecimalRoundingMode_roundUnecessary() { - GBP_2_34.minusRetainScale(bd("1.235"), RoundingMode.UNNECESSARY); + @Test + void test_minusRetainScale_BigDecimalRoundingMode_roundUnecessary() { + assertThrows(ArithmeticException.class, () -> { + GBP_2_34.minusRetainScale(bd("1.235"), RoundingMode.UNNECESSARY); + }); } - @Test(expected = NullPointerException.class) - public void test_minusRetainScale_BigDecimalRoundingMode_nullBigDecimal() { - GBP_M5_78.minusRetainScale((BigDecimal) null, RoundingMode.UNNECESSARY); + @Test + void test_minusRetainScale_BigDecimalRoundingMode_nullBigDecimal() { + assertThrows(NullPointerException.class, () -> { + GBP_M5_78.minusRetainScale((BigDecimal) null, RoundingMode.UNNECESSARY); + }); } - @Test(expected = NullPointerException.class) - public void test_minusRetainScale_BigDecimalRoundingMode_nullRoundingMode() { - GBP_M5_78.minusRetainScale(BIGDEC_2_34, (RoundingMode) null); + @Test + void test_minusRetainScale_BigDecimalRoundingMode_nullRoundingMode() { + assertThrows(NullPointerException.class, () -> { + GBP_M5_78.minusRetainScale(BIGDEC_2_34, (RoundingMode) null); + }); } //----------------------------------------------------------------------- // minusRetainScale(double,RoundingMode) //----------------------------------------------------------------------- @Test - public void test_minusRetainScale_doubleRoundingMode_zero() { + void test_minusRetainScale_doubleRoundingMode_zero() { BigMoney test = GBP_2_34.minusRetainScale(0d, RoundingMode.UNNECESSARY); assertSame(GBP_2_34, test); } @Test - public void test_minusRetainScale_doubleRoundingMode_positive() { + void test_minusRetainScale_doubleRoundingMode_positive() { BigMoney test = GBP_2_34.minusRetainScale(1.23d, RoundingMode.UNNECESSARY); assertEquals("GBP 1.11", test.toString()); } @Test - public void test_minusRetainScale_doubleRoundingMode_negative() { + void test_minusRetainScale_doubleRoundingMode_negative() { BigMoney test = GBP_2_34.minusRetainScale(-1.23d, RoundingMode.UNNECESSARY); assertEquals("GBP 3.57", test.toString()); } @Test - public void test_minusRetainScale_doubleRoundingMode_roundDown() { + void test_minusRetainScale_doubleRoundingMode_roundDown() { BigMoney test = GBP_2_34.minusRetainScale(1.235d, RoundingMode.DOWN); assertEquals("GBP 1.10", test.toString()); } - @Test(expected = ArithmeticException.class) - public void test_minusRetainScale_doubleRoundingMode_roundUnecessary() { - GBP_2_34.minusRetainScale(1.235d, RoundingMode.UNNECESSARY); + @Test + void test_minusRetainScale_doubleRoundingMode_roundUnecessary() { + assertThrows(ArithmeticException.class, () -> { + GBP_2_34.minusRetainScale(1.235d, RoundingMode.UNNECESSARY); + }); } - @Test(expected = NullPointerException.class) - public void test_minusRetainScale_doubleRoundingMode_nullRoundingMode() { - GBP_M5_78.minusRetainScale(2.34d, (RoundingMode) null); + @Test + void test_minusRetainScale_doubleRoundingMode_nullRoundingMode() { + assertThrows(NullPointerException.class, () -> { + GBP_M5_78.minusRetainScale(2.34d, (RoundingMode) null); + }); } //----------------------------------------------------------------------- // multipliedBy(BigDecimal) //----------------------------------------------------------------------- @Test - public void test_multipliedBy_BigDecimal_one() { + void test_multipliedBy_BigDecimal_one() { BigMoney test = GBP_2_34.multipliedBy(BigDecimal.ONE); assertSame(GBP_2_34, test); } @Test - public void test_multipliedBy_BigDecimal_positive() { + void test_multipliedBy_BigDecimal_positive() { BigMoney test = GBP_2_33.multipliedBy(bd("2.5")); assertEquals("GBP 5.825", test.toString()); assertEquals(3, test.getScale()); } @Test - public void test_multipliedBy_BigDecimal_negative() { + void test_multipliedBy_BigDecimal_negative() { BigMoney test = GBP_2_33.multipliedBy(bd("-2.5")); assertEquals("GBP -5.825", test.toString()); assertEquals(3, test.getScale()); } - @Test(expected = NullPointerException.class) - public void test_multipliedBy_BigDecimal_nullBigDecimal() { - GBP_5_78.multipliedBy((BigDecimal) null); + @Test + void test_multipliedBy_BigDecimal_nullBigDecimal() { + assertThrows(NullPointerException.class, () -> { + GBP_5_78.multipliedBy((BigDecimal) null); + }); } //----------------------------------------------------------------------- // multipliedBy(double) //----------------------------------------------------------------------- @Test - public void test_multipliedBy_doubleRoundingMode_one() { + void test_multipliedBy_doubleRoundingMode_one() { BigMoney test = GBP_2_34.multipliedBy(1d); assertSame(GBP_2_34, test); } @Test - public void test_multipliedBy_doubleRoundingMode_positive() { + void test_multipliedBy_doubleRoundingMode_positive() { BigMoney test = GBP_2_33.multipliedBy(2.5d); assertEquals("GBP 5.825", test.toString()); assertEquals(3, test.getScale()); } @Test - public void test_multipliedBy_doubleRoundingMode_negative() { + void test_multipliedBy_doubleRoundingMode_negative() { BigMoney test = GBP_2_33.multipliedBy(-2.5d); assertEquals("GBP -5.825", test.toString()); assertEquals(3, test.getScale()); @@ -2083,20 +2282,20 @@ public void test_multipliedBy_doubleRoundingMode_negative() { // multipliedBy(long) //----------------------------------------------------------------------- @Test - public void test_multipliedBy_long_one() { + void test_multipliedBy_long_one() { BigMoney test = GBP_2_34.multipliedBy(1); assertSame(GBP_2_34, test); } @Test - public void test_multipliedBy_long_positive() { + void test_multipliedBy_long_positive() { BigMoney test = GBP_2_34.multipliedBy(3); assertEquals("GBP 7.02", test.toString()); assertEquals(2, test.getScale()); } @Test - public void test_multipliedBy_long_negative() { + void test_multipliedBy_long_negative() { BigMoney test = GBP_2_34.multipliedBy(-3); assertEquals("GBP -7.02", test.toString()); assertEquals(2, test.getScale()); @@ -2106,169 +2305,181 @@ public void test_multipliedBy_long_negative() { // multiplyRetainScale(BigDecimal,RoundingMode) //----------------------------------------------------------------------- @Test - public void test_multiplyRetainScale_BigDecimalRoundingMode_one() { + void test_multiplyRetainScale_BigDecimalRoundingMode_one() { BigMoney test = GBP_2_34.multiplyRetainScale(BigDecimal.ONE, RoundingMode.DOWN); assertSame(GBP_2_34, test); } @Test - public void test_multiplyRetainScale_BigDecimalRoundingMode_positive() { + void test_multiplyRetainScale_BigDecimalRoundingMode_positive() { BigMoney test = GBP_2_33.multiplyRetainScale(bd("2.5"), RoundingMode.DOWN); assertEquals("GBP 5.82", test.toString()); } @Test - public void test_multiplyRetainScale_BigDecimalRoundingMode_positive_halfUp() { + void test_multiplyRetainScale_BigDecimalRoundingMode_positive_halfUp() { BigMoney test = GBP_2_33.multiplyRetainScale(bd("2.5"), RoundingMode.HALF_UP); assertEquals("GBP 5.83", test.toString()); } @Test - public void test_multiplyRetainScale_BigDecimalRoundingMode_negative() { + void test_multiplyRetainScale_BigDecimalRoundingMode_negative() { BigMoney test = GBP_2_33.multiplyRetainScale(bd("-2.5"), RoundingMode.FLOOR); assertEquals("GBP -5.83", test.toString()); } - @Test(expected = NullPointerException.class) - public void test_multiplyRetainScale_BigDecimalRoundingMode_nullBigDecimal() { - GBP_5_78.multiplyRetainScale((BigDecimal) null, RoundingMode.DOWN); + @Test + void test_multiplyRetainScale_BigDecimalRoundingMode_nullBigDecimal() { + assertThrows(NullPointerException.class, () -> { + GBP_5_78.multiplyRetainScale((BigDecimal) null, RoundingMode.DOWN); + }); } - @Test(expected = NullPointerException.class) - public void test_multiplyRetainScale_BigDecimalRoundingMode_nullRoundingMode() { - GBP_5_78.multiplyRetainScale(bd("2.5"), (RoundingMode) null); + @Test + void test_multiplyRetainScale_BigDecimalRoundingMode_nullRoundingMode() { + assertThrows(NullPointerException.class, () -> { + GBP_5_78.multiplyRetainScale(bd("2.5"), (RoundingMode) null); + }); } //----------------------------------------------------------------------- // multiplyRetainScale(double,RoundingMode) //----------------------------------------------------------------------- @Test - public void test_multiplyRetainScale_doubleRoundingMode_one() { + void test_multiplyRetainScale_doubleRoundingMode_one() { BigMoney test = GBP_2_34.multiplyRetainScale(1d, RoundingMode.DOWN); assertSame(GBP_2_34, test); } @Test - public void test_multiplyRetainScale_doubleRoundingMode_positive() { + void test_multiplyRetainScale_doubleRoundingMode_positive() { BigMoney test = GBP_2_33.multiplyRetainScale(2.5d, RoundingMode.DOWN); assertEquals("GBP 5.82", test.toString()); } @Test - public void test_multiplyRetainScale_doubleRoundingMode_positive_halfUp() { + void test_multiplyRetainScale_doubleRoundingMode_positive_halfUp() { BigMoney test = GBP_2_33.multiplyRetainScale(2.5d, RoundingMode.HALF_UP); assertEquals("GBP 5.83", test.toString()); } @Test - public void test_multiplyRetainScale_doubleRoundingMode_negative() { + void test_multiplyRetainScale_doubleRoundingMode_negative() { BigMoney test = GBP_2_33.multiplyRetainScale(-2.5d, RoundingMode.FLOOR); assertEquals("GBP -5.83", test.toString()); } - @Test(expected = NullPointerException.class) - public void test_multiplyRetainScale_doubleRoundingMode_nullRoundingMode() { - GBP_5_78.multiplyRetainScale(2.5d, (RoundingMode) null); + @Test + void test_multiplyRetainScale_doubleRoundingMode_nullRoundingMode() { + assertThrows(NullPointerException.class, () -> { + GBP_5_78.multiplyRetainScale(2.5d, (RoundingMode) null); + }); } //----------------------------------------------------------------------- // dividedBy(BigDecimal,RoundingMode) //----------------------------------------------------------------------- @Test - public void test_dividedBy_BigDecimalRoundingMode_one() { + void test_dividedBy_BigDecimalRoundingMode_one() { BigMoney test = GBP_2_34.dividedBy(BigDecimal.ONE, RoundingMode.DOWN); assertSame(GBP_2_34, test); } @Test - public void test_dividedBy_BigDecimalRoundingMode_positive() { + void test_dividedBy_BigDecimalRoundingMode_positive() { BigMoney test = GBP_2_34.dividedBy(bd("2.5"), RoundingMode.DOWN); assertEquals("GBP 0.93", test.toString()); } @Test - public void test_dividedBy_BigDecimalRoundingMode_positive_halfUp() { + void test_dividedBy_BigDecimalRoundingMode_positive_halfUp() { BigMoney test = GBP_2_34.dividedBy(bd("2.5"), RoundingMode.HALF_UP); assertEquals("GBP 0.94", test.toString()); } @Test - public void test_dividedBy_BigDecimalRoundingMode_negative() { + void test_dividedBy_BigDecimalRoundingMode_negative() { BigMoney test = GBP_2_34.dividedBy(bd("-2.5"), RoundingMode.FLOOR); assertEquals("GBP -0.94", test.toString()); } - @Test(expected = NullPointerException.class) - public void test_dividedBy_BigDecimalRoundingMode_nullBigDecimal() { - GBP_5_78.dividedBy((BigDecimal) null, RoundingMode.DOWN); + @Test + void test_dividedBy_BigDecimalRoundingMode_nullBigDecimal() { + assertThrows(NullPointerException.class, () -> { + GBP_5_78.dividedBy((BigDecimal) null, RoundingMode.DOWN); + }); } - @Test(expected = NullPointerException.class) - public void test_dividedBy_BigDecimalRoundingMode_nullRoundingMode() { - GBP_5_78.dividedBy(bd("2.5"), (RoundingMode) null); + @Test + void test_dividedBy_BigDecimalRoundingMode_nullRoundingMode() { + assertThrows(NullPointerException.class, () -> { + GBP_5_78.dividedBy(bd("2.5"), (RoundingMode) null); + }); } //----------------------------------------------------------------------- // dividedBy(double,RoundingMode) //----------------------------------------------------------------------- @Test - public void test_dividedBy_doubleRoundingMode_one() { + void test_dividedBy_doubleRoundingMode_one() { BigMoney test = GBP_2_34.dividedBy(1d, RoundingMode.DOWN); assertSame(GBP_2_34, test); } @Test - public void test_dividedBy_doubleRoundingMode_positive() { + void test_dividedBy_doubleRoundingMode_positive() { BigMoney test = GBP_2_34.dividedBy(2.5d, RoundingMode.DOWN); assertEquals("GBP 0.93", test.toString()); } @Test - public void test_dividedBy_doubleRoundingMode_positive_halfUp() { + void test_dividedBy_doubleRoundingMode_positive_halfUp() { BigMoney test = GBP_2_34.dividedBy(2.5d, RoundingMode.HALF_UP); assertEquals("GBP 0.94", test.toString()); } @Test - public void test_dividedBy_doubleRoundingMode_negative() { + void test_dividedBy_doubleRoundingMode_negative() { BigMoney test = GBP_2_34.dividedBy(-2.5d, RoundingMode.FLOOR); assertEquals("GBP -0.94", test.toString()); } - @Test(expected = NullPointerException.class) - public void test_dividedBy_doubleRoundingMode_nullRoundingMode() { - GBP_5_78.dividedBy(2.5d, (RoundingMode) null); + @Test + void test_dividedBy_doubleRoundingMode_nullRoundingMode() { + assertThrows(NullPointerException.class, () -> { + GBP_5_78.dividedBy(2.5d, (RoundingMode) null); + }); } //----------------------------------------------------------------------- // dividedBy(long,RoundingMode) //----------------------------------------------------------------------- @Test - public void test_dividedBy_long_one() { + void test_dividedBy_long_one() { BigMoney test = GBP_2_34.dividedBy(1, RoundingMode.DOWN); assertSame(GBP_2_34, test); } @Test - public void test_dividedBy_long_positive() { + void test_dividedBy_long_positive() { BigMoney test = GBP_2_34.dividedBy(3, RoundingMode.DOWN); assertEquals("GBP 0.78", test.toString()); } @Test - public void test_dividedBy_long_positive_roundDown() { + void test_dividedBy_long_positive_roundDown() { BigMoney test = GBP_2_35.dividedBy(3, RoundingMode.DOWN); assertEquals("GBP 0.78", test.toString()); } @Test - public void test_dividedBy_long_positive_roundUp() { + void test_dividedBy_long_positive_roundUp() { BigMoney test = GBP_2_35.dividedBy(3, RoundingMode.UP); assertEquals("GBP 0.79", test.toString()); } @Test - public void test_dividedBy_long_negative() { + void test_dividedBy_long_negative() { BigMoney test = GBP_2_34.dividedBy(-3, RoundingMode.DOWN); assertEquals("GBP -0.78", test.toString()); } @@ -2277,19 +2488,19 @@ public void test_dividedBy_long_negative() { // negated() //----------------------------------------------------------------------- @Test - public void test_negated_zero() { + void test_negated_zero() { BigMoney test = GBP_0_00.negated(); assertSame(GBP_0_00, test); } @Test - public void test_negated_positive() { + void test_negated_positive() { BigMoney test = GBP_2_34.negated(); assertEquals("GBP -2.34", test.toString()); } @Test - public void test_negated_negative() { + void test_negated_negative() { BigMoney test = BigMoney.parse("GBP -2.34").negated(); assertEquals("GBP 2.34", test.toString()); } @@ -2298,13 +2509,13 @@ public void test_negated_negative() { // abs() //----------------------------------------------------------------------- @Test - public void test_abs_positive() { + void test_abs_positive() { BigMoney test = GBP_2_34.abs(); assertSame(GBP_2_34, test); } @Test - public void test_abs_negative() { + void test_abs_negative() { BigMoney test = BigMoney.parse("GBP -2.34").abs(); assertEquals("GBP 2.34", test.toString()); } @@ -2313,55 +2524,55 @@ public void test_abs_negative() { // rounded(int,RoundingMode) //----------------------------------------------------------------------- @Test - public void test_round_2down() { + void test_round_2down() { BigMoney test = GBP_2_34.rounded(2, RoundingMode.DOWN); assertSame(GBP_2_34, test); } @Test - public void test_round_2up() { + void test_round_2up() { BigMoney test = GBP_2_34.rounded(2, RoundingMode.DOWN); assertSame(GBP_2_34, test); } @Test - public void test_round_1down() { + void test_round_1down() { BigMoney test = GBP_2_34.rounded(1, RoundingMode.DOWN); assertEquals("GBP 2.30", test.toString()); } @Test - public void test_round_1up() { + void test_round_1up() { BigMoney test = GBP_2_34.rounded(1, RoundingMode.UP); assertEquals("GBP 2.40", test.toString()); } @Test - public void test_round_0down() { + void test_round_0down() { BigMoney test = GBP_2_34.rounded(0, RoundingMode.DOWN); assertEquals("GBP 2.00", test.toString()); } @Test - public void test_round_0up() { + void test_round_0up() { BigMoney test = GBP_2_34.rounded(0, RoundingMode.UP); assertEquals("GBP 3.00", test.toString()); } @Test - public void test_round_M1down() { + void test_round_M1down() { BigMoney test = BigMoney.parse("GBP 432.34").rounded(-1, RoundingMode.DOWN); assertEquals("GBP 430.00", test.toString()); } @Test - public void test_round_M1up() { + void test_round_M1up() { BigMoney test = BigMoney.parse("GBP 432.34").rounded(-1, RoundingMode.UP); assertEquals("GBP 440.00", test.toString()); } @Test - public void test_round_3() { + void test_round_3() { BigMoney test = GBP_2_34.rounded(3, RoundingMode.DOWN); assertSame(GBP_2_34, test); } @@ -2370,82 +2581,100 @@ public void test_round_3() { // convertedTo(CurrencyUnit,BigDecimal) //----------------------------------------------------------------------- @Test - public void test_convertedTo_CurrencyUnit_BigDecimal_positive() { + void test_convertedTo_CurrencyUnit_BigDecimal_positive() { BigMoney test = GBP_2_33.convertedTo(EUR, bd("2.5")); assertEquals("EUR 5.825", test.toString()); } @Test - public void test_convertedTo_CurrencyUnit_BigDecimal_sameCurrencyCorrectFactor() { + void test_convertedTo_CurrencyUnit_BigDecimal_sameCurrencyCorrectFactor() { BigMoney test = GBP_2_33.convertedTo(GBP, bd("1.00000")); assertEquals(GBP_2_33, test); } - @Test(expected = IllegalArgumentException.class) - public void test_convertedTo_CurrencyUnit_BigDecimal_negative() { - GBP_2_33.convertedTo(EUR, bd("-2.5")); + @Test + void test_convertedTo_CurrencyUnit_BigDecimal_negative() { + assertThrows(IllegalArgumentException.class, () -> { + GBP_2_33.convertedTo(EUR, bd("-2.5")); + }); } - @Test(expected = IllegalArgumentException.class) - public void test_convertedTo_CurrencyUnit_BigDecimal_sameCurrencyWrongFactor() { - GBP_2_33.convertedTo(GBP, bd("2.5")); + @Test + void test_convertedTo_CurrencyUnit_BigDecimal_sameCurrencyWrongFactor() { + assertThrows(IllegalArgumentException.class, () -> { + GBP_2_33.convertedTo(GBP, bd("2.5")); + }); } - @Test(expected = NullPointerException.class) - public void test_convertedTo_CurrencyUnit_BigDecimal_nullCurrency() { - GBP_5_78.convertedTo((CurrencyUnit) null, bd("2")); + @Test + void test_convertedTo_CurrencyUnit_BigDecimal_nullCurrency() { + assertThrows(NullPointerException.class, () -> { + GBP_5_78.convertedTo((CurrencyUnit) null, bd("2")); + }); } - @Test(expected = NullPointerException.class) - public void test_convertedTo_CurrencyUnit_BigDecimal_nullBigDecimal() { - GBP_5_78.convertedTo(EUR, (BigDecimal) null); + @Test + void test_convertedTo_CurrencyUnit_BigDecimal_nullBigDecimal() { + assertThrows(NullPointerException.class, () -> { + GBP_5_78.convertedTo(EUR, (BigDecimal) null); + }); } //----------------------------------------------------------------------- // convertRetainScale(CurrencyUnit,BigDecimal,RoundingMode) //----------------------------------------------------------------------- @Test - public void test_convertRetainScale_CurrencyUnit_BigDecimal_RoundingMode_positive() { + void test_convertRetainScale_CurrencyUnit_BigDecimal_RoundingMode_positive() { BigMoney test = BigMoney.parse("GBP 2.2").convertRetainScale(EUR, bd("2.5"), RoundingMode.DOWN); assertEquals("EUR 5.5", test.toString()); } @Test - public void test_convertRetainScale_CurrencyUnit_BigDecimal_RoundingMode_roundHalfUp() { + void test_convertRetainScale_CurrencyUnit_BigDecimal_RoundingMode_roundHalfUp() { BigMoney test = BigMoney.parse("GBP 2.21").convertRetainScale(EUR, bd("2.5"), RoundingMode.HALF_UP); assertEquals("EUR 5.53", test.toString()); } - @Test(expected = IllegalArgumentException.class) - public void test_convertRetainScale_CurrencyUnit_BigDecimal_RoundingMode_negative() { - GBP_2_33.convertRetainScale(EUR, bd("-2.5"), RoundingMode.DOWN); + @Test + void test_convertRetainScale_CurrencyUnit_BigDecimal_RoundingMode_negative() { + assertThrows(IllegalArgumentException.class, () -> { + GBP_2_33.convertRetainScale(EUR, bd("-2.5"), RoundingMode.DOWN); + }); } - @Test(expected = IllegalArgumentException.class) - public void test_convertRetainScale_CurrencyUnit_BigDecimal_RoundingMode_sameCurrency() { - GBP_2_33.convertRetainScale(GBP, bd("2.5"), RoundingMode.DOWN); + @Test + void test_convertRetainScale_CurrencyUnit_BigDecimal_RoundingMode_sameCurrency() { + assertThrows(IllegalArgumentException.class, () -> { + GBP_2_33.convertRetainScale(GBP, bd("2.5"), RoundingMode.DOWN); + }); } - @Test(expected = NullPointerException.class) - public void test_convertRetainScale_CurrencyUnit_BigDecimal_RoundingMode_nullCurrency() { - GBP_5_78.convertRetainScale((CurrencyUnit) null, bd("2"), RoundingMode.DOWN); + @Test + void test_convertRetainScale_CurrencyUnit_BigDecimal_RoundingMode_nullCurrency() { + assertThrows(NullPointerException.class, () -> { + GBP_5_78.convertRetainScale((CurrencyUnit) null, bd("2"), RoundingMode.DOWN); + }); } - @Test(expected = NullPointerException.class) - public void test_convertRetainScale_CurrencyUnit_BigDecimal_RoundingMode_nullBigDecimal() { - GBP_5_78.convertRetainScale(EUR, (BigDecimal) null, RoundingMode.DOWN); + @Test + void test_convertRetainScale_CurrencyUnit_BigDecimal_RoundingMode_nullBigDecimal() { + assertThrows(NullPointerException.class, () -> { + GBP_5_78.convertRetainScale(EUR, (BigDecimal) null, RoundingMode.DOWN); + }); } - @Test(expected = NullPointerException.class) - public void test_convertRetainScale_CurrencyUnit_BigDecimal_RoundingMode_nullRoundingMode() { - GBP_5_78.convertRetainScale(EUR, bd("2"), (RoundingMode) null); + @Test + void test_convertRetainScale_CurrencyUnit_BigDecimal_RoundingMode_nullRoundingMode() { + assertThrows(NullPointerException.class, () -> { + GBP_5_78.convertRetainScale(EUR, bd("2"), (RoundingMode) null); + }); } //----------------------------------------------------------------------- // toMoney() //----------------------------------------------------------------------- @Test - public void test_toBigMoney() { + void test_toBigMoney() { assertSame(GBP_2_34, GBP_2_34.toBigMoney()); } @@ -2453,7 +2682,7 @@ public void test_toBigMoney() { // toMoney() //----------------------------------------------------------------------- @Test - public void test_toMoney() { + void test_toMoney() { assertEquals(Money.of(GBP, BIGDEC_2_34), GBP_2_34.toMoney()); } @@ -2461,12 +2690,12 @@ public void test_toMoney() { // toMoney() //----------------------------------------------------------------------- @Test - public void test_toMoney_RoundingMode() { + void test_toMoney_RoundingMode() { assertEquals(Money.parse("GBP 2.34"), GBP_2_34.toMoney(RoundingMode.HALF_EVEN)); } @Test - public void test_toMoney_RoundingMode_round() { + void test_toMoney_RoundingMode_round() { BigMoney money = BigMoney.parse("GBP 2.355"); assertEquals(Money.parse("GBP 2.36"), money.toMoney(RoundingMode.HALF_EVEN)); } @@ -2475,35 +2704,37 @@ public void test_toMoney_RoundingMode_round() { // isSameCurrency(Money) //----------------------------------------------------------------------- @Test - public void test_isSameCurrency_BigMoney_same() { - assertEquals(true, GBP_2_34.isSameCurrency(GBP_2_35)); + void test_isSameCurrency_BigMoney_same() { + assertTrue(GBP_2_34.isSameCurrency(GBP_2_35)); } @Test - public void test_isSameCurrency_BigMoney_different() { - assertEquals(false, GBP_2_34.isSameCurrency(USD_2_34)); + void test_isSameCurrency_BigMoney_different() { + assertFalse(GBP_2_34.isSameCurrency(USD_2_34)); } @Test - public void test_isSameCurrency_Money_same() { - assertEquals(true, GBP_2_34.isSameCurrency(Money.parse("GBP 2"))); + void test_isSameCurrency_Money_same() { + assertTrue(GBP_2_34.isSameCurrency(Money.parse("GBP 2"))); } @Test - public void test_isSameCurrency_Money_different() { - assertEquals(false, GBP_2_34.isSameCurrency(Money.parse("USD 2"))); + void test_isSameCurrency_Money_different() { + assertFalse(GBP_2_34.isSameCurrency(Money.parse("USD 2"))); } - @Test(expected = NullPointerException.class) - public void test_isSameCurrency_Money_nullMoney() { - GBP_2_34.isSameCurrency((BigMoney) null); + @Test + void test_isSameCurrency_Money_nullMoney() { + assertThrows(NullPointerException.class, () -> { + GBP_2_34.isSameCurrency((BigMoney) null); + }); } //----------------------------------------------------------------------- // compareTo() //----------------------------------------------------------------------- @Test - public void test_compareTo_BigMoney() { + void test_compareTo_BigMoney() { BigMoney a = GBP_2_34; BigMoney b = GBP_2_35; BigMoney c = GBP_2_36; @@ -2522,7 +2753,7 @@ public void test_compareTo_BigMoney() { } @Test - public void test_compareTo_Money() { + void test_compareTo_Money() { BigMoney t = GBP_2_35; Money a = Money.ofMinor(GBP, 234); Money b = Money.ofMinor(GBP, 235); @@ -2532,206 +2763,220 @@ public void test_compareTo_Money() { assertEquals(-1, t.compareTo(c)); } - @Test(expected = CurrencyMismatchException.class) - public void test_compareTo_currenciesDiffer() { + @Test + void test_compareTo_currenciesDiffer() { BigMoney a = GBP_2_34; BigMoney b = USD_2_35; - a.compareTo(b); + assertThrows(CurrencyMismatchException.class, () -> { + a.compareTo(b); + }); } - @Test(expected = ClassCastException.class) + @Test @SuppressWarnings({"unchecked", "rawtypes"}) - public void test_compareTo_wrongType() { + void test_compareTo_wrongType() { Comparable a = GBP_2_34; - a.compareTo("NotRightType"); + assertThrows(ClassCastException.class, () -> { + a.compareTo("NotRightType"); + }); } //----------------------------------------------------------------------- // isEqual() //----------------------------------------------------------------------- @Test - public void test_isEqual() { + void test_isEqual() { BigMoney a = GBP_2_34; BigMoney b = GBP_2_35; BigMoney c = GBP_2_36; - assertEquals(true, a.isEqual(a)); - assertEquals(true, b.isEqual(b)); - assertEquals(true, c.isEqual(c)); + assertTrue(a.isEqual(a)); + assertTrue(b.isEqual(b)); + assertTrue(c.isEqual(c)); - assertEquals(false, a.isEqual(b)); - assertEquals(false, b.isEqual(a)); + assertFalse(a.isEqual(b)); + assertFalse(b.isEqual(a)); - assertEquals(false, a.isEqual(c)); - assertEquals(false, c.isEqual(a)); + assertFalse(a.isEqual(c)); + assertFalse(c.isEqual(a)); - assertEquals(false, b.isEqual(c)); - assertEquals(false, c.isEqual(b)); + assertFalse(b.isEqual(c)); + assertFalse(c.isEqual(b)); } @Test - public void test_isEqual_Money() { + void test_isEqual_Money() { BigMoney a = GBP_2_34; Money b = Money.ofMinor(GBP, 234); - assertEquals(true, a.isEqual(b)); + assertTrue(a.isEqual(b)); } - @Test(expected = CurrencyMismatchException.class) - public void test_isEqual_currenciesDiffer() { + @Test + void test_isEqual_currenciesDiffer() { BigMoney a = GBP_2_34; BigMoney b = USD_2_35; - a.isEqual(b); + assertThrows(CurrencyMismatchException.class, () -> { + a.isEqual(b); + }); } //----------------------------------------------------------------------- // isGreaterThan() //----------------------------------------------------------------------- @Test - public void test_isGreaterThan() { + void test_isGreaterThan() { BigMoney a = GBP_2_34; BigMoney b = GBP_2_35; BigMoney c = GBP_2_36; - assertEquals(false, a.isGreaterThan(a)); - assertEquals(false, a.isGreaterThan(b)); - assertEquals(false, a.isGreaterThan(c)); + assertFalse(a.isGreaterThan(a)); + assertFalse(a.isGreaterThan(b)); + assertFalse(a.isGreaterThan(c)); - assertEquals(true, b.isGreaterThan(a)); - assertEquals(false, b.isGreaterThan(b)); - assertEquals(false, b.isGreaterThan(c)); + assertTrue(b.isGreaterThan(a)); + assertFalse(b.isGreaterThan(b)); + assertFalse(b.isGreaterThan(c)); - assertEquals(true, c.isGreaterThan(a)); - assertEquals(true, c.isGreaterThan(b)); - assertEquals(false, c.isGreaterThan(c)); + assertTrue(c.isGreaterThan(a)); + assertTrue(c.isGreaterThan(b)); + assertFalse(c.isGreaterThan(c)); } - @Test(expected = CurrencyMismatchException.class) - public void test_isGreaterThan_currenciesDiffer() { + @Test + void test_isGreaterThan_currenciesDiffer() { BigMoney a = GBP_2_34; BigMoney b = USD_2_35; - a.isGreaterThan(b); + assertThrows(CurrencyMismatchException.class, () -> { + a.isGreaterThan(b); + }); } //----------------------------------------------------------------------- // isGreaterThanOrEqual() //----------------------------------------------------------------------- @Test - public void test_isGreaterThanOrEqual() { + void test_isGreaterThanOrEqual() { BigMoney a = GBP_2_34; BigMoney b = GBP_2_35; BigMoney c = GBP_2_36; - assertEquals(true, a.isGreaterThanOrEqual(a)); - assertEquals(false, a.isGreaterThanOrEqual(b)); - assertEquals(false, a.isGreaterThanOrEqual(c)); + assertTrue(a.isGreaterThanOrEqual(a)); + assertFalse(a.isGreaterThanOrEqual(b)); + assertFalse(a.isGreaterThanOrEqual(c)); - assertEquals(true, b.isGreaterThanOrEqual(a)); - assertEquals(true, b.isGreaterThanOrEqual(b)); - assertEquals(false, b.isGreaterThanOrEqual(c)); + assertTrue(b.isGreaterThanOrEqual(a)); + assertTrue(b.isGreaterThanOrEqual(b)); + assertFalse(b.isGreaterThanOrEqual(c)); - assertEquals(true, c.isGreaterThanOrEqual(a)); - assertEquals(true, c.isGreaterThanOrEqual(b)); - assertEquals(true, c.isGreaterThanOrEqual(c)); + assertTrue(c.isGreaterThanOrEqual(a)); + assertTrue(c.isGreaterThanOrEqual(b)); + assertTrue(c.isGreaterThanOrEqual(c)); } - @Test(expected = CurrencyMismatchException.class) - public void test_isGreaterThanOrEqual_currenciesDiffer() { + @Test + void test_isGreaterThanOrEqual_currenciesDiffer() { BigMoney a = GBP_2_34; BigMoney b = USD_2_35; - a.isGreaterThanOrEqual(b); + assertThrows(CurrencyMismatchException.class, () -> { + a.isGreaterThanOrEqual(b); + }); } //----------------------------------------------------------------------- // isLessThan() //----------------------------------------------------------------------- @Test - public void test_isLessThan() { + void test_isLessThan() { BigMoney a = GBP_2_34; BigMoney b = GBP_2_35; BigMoney c = GBP_2_36; - assertEquals(false, a.isLessThan(a)); - assertEquals(true, a.isLessThan(b)); - assertEquals(true, a.isLessThan(c)); + assertFalse(a.isLessThan(a)); + assertTrue(a.isLessThan(b)); + assertTrue(a.isLessThan(c)); - assertEquals(false, b.isLessThan(a)); - assertEquals(false, b.isLessThan(b)); - assertEquals(true, b.isLessThan(c)); + assertFalse(b.isLessThan(a)); + assertFalse(b.isLessThan(b)); + assertTrue(b.isLessThan(c)); - assertEquals(false, c.isLessThan(a)); - assertEquals(false, c.isLessThan(b)); - assertEquals(false, c.isLessThan(c)); + assertFalse(c.isLessThan(a)); + assertFalse(c.isLessThan(b)); + assertFalse(c.isLessThan(c)); } - @Test(expected = CurrencyMismatchException.class) - public void test_isLessThan_currenciesDiffer() { + @Test + void test_isLessThan_currenciesDiffer() { BigMoney a = GBP_2_34; BigMoney b = USD_2_35; - a.isLessThan(b); + assertThrows(CurrencyMismatchException.class, () -> { + a.isLessThan(b); + }); } //----------------------------------------------------------------------- // isLessThanOrEqual() //----------------------------------------------------------------------- @Test - public void test_isLessThanOrEqual() { + void test_isLessThanOrEqual() { BigMoney a = GBP_2_34; BigMoney b = GBP_2_35; BigMoney c = GBP_2_36; - assertEquals(true, a.isLessThanOrEqual(a)); - assertEquals(true, a.isLessThanOrEqual(b)); - assertEquals(true, a.isLessThanOrEqual(c)); + assertTrue(a.isLessThanOrEqual(a)); + assertTrue(a.isLessThanOrEqual(b)); + assertTrue(a.isLessThanOrEqual(c)); - assertEquals(false, b.isLessThanOrEqual(a)); - assertEquals(true, b.isLessThanOrEqual(b)); - assertEquals(true, b.isLessThanOrEqual(c)); + assertFalse(b.isLessThanOrEqual(a)); + assertTrue(b.isLessThanOrEqual(b)); + assertTrue(b.isLessThanOrEqual(c)); - assertEquals(false, c.isLessThanOrEqual(a)); - assertEquals(false, c.isLessThanOrEqual(b)); - assertEquals(true, c.isLessThanOrEqual(c)); + assertFalse(c.isLessThanOrEqual(a)); + assertFalse(c.isLessThanOrEqual(b)); + assertTrue(c.isLessThanOrEqual(c)); } - @Test(expected = CurrencyMismatchException.class) - public void test_isLessThanOrEqual_currenciesDiffer() { + @Test + void test_isLessThanOrEqual_currenciesDiffer() { BigMoney a = GBP_2_34; BigMoney b = USD_2_35; - a.isLessThanOrEqual(b); + assertThrows(CurrencyMismatchException.class, () -> { + a.isLessThanOrEqual(b); + }); } //----------------------------------------------------------------------- // equals() hashCode() //----------------------------------------------------------------------- @Test - public void test_equals_hashCode_positive() { + void test_equals_hashCode_positive() { BigMoney a = GBP_2_34; BigMoney b = GBP_2_34; BigMoney c = GBP_2_35; - assertEquals(true, a.equals(a)); - assertEquals(true, b.equals(b)); - assertEquals(true, c.equals(c)); + assertTrue(a.equals(a)); + assertTrue(b.equals(b)); + assertTrue(c.equals(c)); - assertEquals(true, a.equals(b)); - assertEquals(true, b.equals(a)); - assertEquals(true, a.hashCode() == b.hashCode()); + assertTrue(a.equals(b)); + assertTrue(b.equals(a)); + assertTrue(a.hashCode() == b.hashCode()); - assertEquals(false, a.equals(c)); - assertEquals(false, b.equals(c)); + assertFalse(a.equals(c)); + assertFalse(b.equals(c)); } @Test - public void test_equals_false() { + void test_equals_false() { BigMoney a = GBP_2_34; - assertEquals(false, a.equals(null)); - assertEquals(false, a.equals(new Object())); + assertFalse(a.equals(null)); + assertFalse(a.equals(new Object())); } //----------------------------------------------------------------------- // toString() //----------------------------------------------------------------------- @Test - public void test_toString_positive() { + void test_toString_positive() { BigMoney test = BigMoney.of(GBP, BIGDEC_2_34); assertEquals("GBP 2.34", test.toString()); } @Test - public void test_toString_negative() { + void test_toString_negative() { BigMoney test = BigMoney.of(EUR, BIGDEC_M5_78); assertEquals("EUR -5.78", test.toString()); } diff --git a/src/test/java/org/joda/money/TestCurrencyMismatchException.java b/src/test/java/org/joda/money/TestCurrencyMismatchException.java index 9c6a128..42c9852 100644 --- a/src/test/java/org/joda/money/TestCurrencyMismatchException.java +++ b/src/test/java/org/joda/money/TestCurrencyMismatchException.java @@ -15,14 +15,15 @@ */ package org.joda.money; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Test CurrencyMismatchException. */ -public class TestCurrencyMismatchException { +class TestCurrencyMismatchException { private static final CurrencyUnit GBP = CurrencyUnit.of("GBP"); private static final CurrencyUnit EUR = CurrencyUnit.of("EUR"); @@ -31,39 +32,39 @@ public class TestCurrencyMismatchException { // new (CurrencyUnit,CurrencyUnit) //----------------------------------------------------------------------- @Test - public void test_new_GBPEUR() { + void test_new_GBPEUR() { CurrencyMismatchException test = new CurrencyMismatchException(GBP, EUR); assertEquals("Currencies differ: GBP/EUR", test.getMessage()); - assertEquals(null, test.getCause()); + assertNull(test.getCause()); assertEquals(GBP, test.getFirstCurrency()); assertEquals(EUR, test.getSecondCurrency()); } @Test - public void test_new_nullEUR() { + void test_new_nullEUR() { CurrencyMismatchException test = new CurrencyMismatchException(null, EUR); assertEquals("Currencies differ: null/EUR", test.getMessage()); - assertEquals(null, test.getCause()); - assertEquals(null, test.getFirstCurrency()); + assertNull(test.getCause()); + assertNull(test.getFirstCurrency()); assertEquals(EUR, test.getSecondCurrency()); } @Test - public void test_new_GBPnull() { + void test_new_GBPnull() { CurrencyMismatchException test = new CurrencyMismatchException(GBP, null); assertEquals("Currencies differ: GBP/null", test.getMessage()); - assertEquals(null, test.getCause()); + assertNull(test.getCause()); assertEquals(GBP, test.getFirstCurrency()); - assertEquals(null, test.getSecondCurrency()); + assertNull(test.getSecondCurrency()); } @Test - public void test_new_nullnull() { + void test_new_nullnull() { CurrencyMismatchException test = new CurrencyMismatchException(null, null); assertEquals("Currencies differ: null/null", test.getMessage()); - assertEquals(null, test.getCause()); - assertEquals(null, test.getFirstCurrency()); - assertEquals(null, test.getSecondCurrency()); + assertNull(test.getCause()); + assertNull(test.getFirstCurrency()); + assertNull(test.getSecondCurrency()); } } diff --git a/src/test/java/org/joda/money/TestCurrencyUnit.java b/src/test/java/org/joda/money/TestCurrencyUnit.java index 382274d..bad8075 100644 --- a/src/test/java/org/joda/money/TestCurrencyUnit.java +++ b/src/test/java/org/joda/money/TestCurrencyUnit.java @@ -15,12 +15,14 @@ */ package org.joda.money; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; +import java.io.IOException; import java.io.InvalidObjectException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; @@ -32,12 +34,12 @@ import java.util.Locale; import java.util.Set; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Test CurrencyUnit. */ -public class TestCurrencyUnit { +class TestCurrencyUnit { private static final Currency JDK_GBP = Currency.getInstance("GBP"); @@ -45,7 +47,7 @@ public class TestCurrencyUnit { // registeredCurrencies() //----------------------------------------------------------------------- @Test - public void test_registeredCurrencies() { + void test_registeredCurrencies() { List curList = CurrencyUnit.registeredCurrencies(); boolean found = false; for (CurrencyUnit currencyUnit : curList) { @@ -58,7 +60,7 @@ public void test_registeredCurrencies() { } @Test - public void test_registeredCurrencies_sorted() { + void test_registeredCurrencies_sorted() { List curList1 = CurrencyUnit.registeredCurrencies(); List curList2 = CurrencyUnit.registeredCurrencies(); Collections.sort(curList2); @@ -68,102 +70,134 @@ public void test_registeredCurrencies_sorted() { assertEquals(curList2, curList1); } - @Test(expected = NullPointerException.class) - public void test_registeredCurrency_nullCode() { - CurrencyUnit.registerCurrency(null, 991, 2, Arrays.asList("TS")); + @Test + void test_registeredCurrency_nullCode() { + assertThrows(NullPointerException.class, () -> { + CurrencyUnit.registerCurrency(null, 991, 2, Arrays.asList("TS")); + }); } - @Test(expected = IllegalArgumentException.class) - public void test_registeredCurrency_invalidStringCode_empty() { - CurrencyUnit.registerCurrency("", 991, 2, Arrays.asList("TS")); + @Test + void test_registeredCurrency_invalidStringCode_empty() { + assertThrows(IllegalArgumentException.class, () -> { + CurrencyUnit.registerCurrency("", 991, 2, Arrays.asList("TS")); + }); } - @Test(expected = IllegalArgumentException.class) - public void test_registeredCurrency_invalidStringCode_1letter() { - CurrencyUnit.registerCurrency("A", 991, 2, Arrays.asList("TS")); + @Test + void test_registeredCurrency_invalidStringCode_1letter() { + assertThrows(IllegalArgumentException.class, () -> { + CurrencyUnit.registerCurrency("A", 991, 2, Arrays.asList("TS")); + }); } - @Test(expected = IllegalArgumentException.class) - public void test_registeredCurrency_invalidStringCode_2letters() { - CurrencyUnit.registerCurrency("AB", 991, 2, Arrays.asList("TS")); + @Test + void test_registeredCurrency_invalidStringCode_2letters() { + assertThrows(IllegalArgumentException.class, () -> { + CurrencyUnit.registerCurrency("AB", 991, 2, Arrays.asList("TS")); + }); } - @Test(expected = IllegalArgumentException.class) - public void test_registeredCurrency_invalidStringCode_4letters() { - CurrencyUnit.registerCurrency("ABCD", 991, 2, Arrays.asList("TS")); + @Test + void test_registeredCurrency_invalidStringCode_4letters() { + assertThrows(IllegalArgumentException.class, () -> { + CurrencyUnit.registerCurrency("ABCD", 991, 2, Arrays.asList("TS")); + }); } - @Test(expected = IllegalArgumentException.class) - public void test_registeredCurrency_invalidStringCode_lowerCase() { - CurrencyUnit.registerCurrency("xxA", 991, 2, Arrays.asList("xx")); + @Test + void test_registeredCurrency_invalidStringCode_lowerCase() { + assertThrows(IllegalArgumentException.class, () -> { + CurrencyUnit.registerCurrency("xxA", 991, 2, Arrays.asList("xx")); + }); } - @Test(expected = IllegalArgumentException.class) - public void test_registeredCurrency_invalidStringCode_number() { - CurrencyUnit.registerCurrency("123", 991, 2, Arrays.asList("TS")); + @Test + void test_registeredCurrency_invalidStringCode_number() { + assertThrows(IllegalArgumentException.class, () -> { + CurrencyUnit.registerCurrency("123", 991, 2, Arrays.asList("TS")); + }); } - @Test(expected = IllegalArgumentException.class) - public void test_registeredCurrency_invalidStringCode_dash() { - CurrencyUnit.registerCurrency("A-", 991, 2, Arrays.asList("TS")); + @Test + void test_registeredCurrency_invalidStringCode_dash() { + assertThrows(IllegalArgumentException.class, () -> { + CurrencyUnit.registerCurrency("A-", 991, 2, Arrays.asList("TS")); + }); } - @Test(expected = IllegalArgumentException.class) - public void test_registeredCurrency_invalidNumericCode_small() { - CurrencyUnit.registerCurrency("TST", -2, 2, Arrays.asList("TS")); + @Test + void test_registeredCurrency_invalidNumericCode_small() { + assertThrows(IllegalArgumentException.class, () -> { + CurrencyUnit.registerCurrency("TST", -2, 2, Arrays.asList("TS")); + }); } - @Test(expected = IllegalArgumentException.class) - public void test_registeredCurrency_invalidNumericCode_big() { - CurrencyUnit.registerCurrency("TST", 1000, 2, Arrays.asList("TS")); + @Test + void test_registeredCurrency_invalidNumericCode_big() { + assertThrows(IllegalArgumentException.class, () -> { + CurrencyUnit.registerCurrency("TST", 1000, 2, Arrays.asList("TS")); + }); } - @Test(expected = IllegalArgumentException.class) - public void test_registeredCurrency_invalidDP_small() { - CurrencyUnit.registerCurrency("TST", 991, -2, Arrays.asList("TS")); + @Test + void test_registeredCurrency_invalidDP_small() { + assertThrows(IllegalArgumentException.class, () -> { + CurrencyUnit.registerCurrency("TST", 991, -2, Arrays.asList("TS")); + }); } - @Test(expected = IllegalArgumentException.class) - public void test_registeredCurrency_invalidDP_big() { - CurrencyUnit.registerCurrency("TST", 991, 31, Arrays.asList("TS")); + @Test + void test_registeredCurrency_invalidDP_big() { + assertThrows(IllegalArgumentException.class, () -> { + CurrencyUnit.registerCurrency("TST", 991, 31, Arrays.asList("TS")); + }); } @Test - public void test_registeredCurrency_validDP_big() { + void test_registeredCurrency_validDP_big() { CurrencyUnit.registerCurrency("XLG", -1, 30, new ArrayList()); CurrencyUnit currency = CurrencyUnit.of("XLG"); assertEquals(30, currency.getDecimalPlaces()); } - @Test(expected = NullPointerException.class) - public void test_registeredCurrency_nullCountry() { - CurrencyUnit.registerCurrency("TST", 991, 2, Arrays.asList((String) null)); + @Test + void test_registeredCurrency_nullCountry() { + assertThrows(NullPointerException.class, () -> { + CurrencyUnit.registerCurrency("TST", 991, 2, Arrays.asList((String) null)); + }); } - @Test(expected = IllegalArgumentException.class) - public void test_registeredCurrency_alreadyRegisteredCode() { - CurrencyUnit.registerCurrency("GBP", 991, 2, Arrays.asList("GB")); + @Test + void test_registeredCurrency_alreadyRegisteredCode() { + assertThrows(IllegalArgumentException.class, () -> { + CurrencyUnit.registerCurrency("GBP", 991, 2, Arrays.asList("GB")); + }); } - @Test(expected = IllegalArgumentException.class) - public void test_registeredCurrency_alreadyRegisteredNumericCode() { - CurrencyUnit.registerCurrency("TST", 826, 2, Arrays.asList("TS")); + @Test + void test_registeredCurrency_alreadyRegisteredNumericCode() { + assertThrows(IllegalArgumentException.class, () -> { + CurrencyUnit.registerCurrency("TST", 826, 2, Arrays.asList("TS")); + }); } - @Test(expected = IllegalArgumentException.class) - public void test_registeredCurrency_alreadyRegisteredCountry() { - CurrencyUnit.registerCurrency("GBX", 991, 2, Arrays.asList("GB")); + @Test + void test_registeredCurrency_alreadyRegisteredCountry() { + assertThrows(IllegalArgumentException.class, () -> { + CurrencyUnit.registerCurrency("GBX", 991, 2, Arrays.asList("GB")); + }); } @Test - public void test_registeredCurrencies_crossCheck() { + void test_registeredCurrencies_crossCheck() { List curList = CurrencyUnit.registeredCurrencies(); for (CurrencyUnit currencyUnit : curList) { try { Currency curr = Currency.getInstance(currencyUnit.getCode()); int dp = curr.getDefaultFractionDigits() < 0 ? 0 : curr.getDefaultFractionDigits(); - assertEquals(curr.getCurrencyCode(), dp, currencyUnit.getDecimalPlaces()); + assertEquals(dp, currencyUnit.getDecimalPlaces(), curr.getCurrencyCode()); } catch (IllegalArgumentException ignored) { } } @@ -173,7 +207,7 @@ public void test_registeredCurrencies_crossCheck() { // registeredCountries() //----------------------------------------------------------------------- @Test - public void test_registeredCountries() { + void test_registeredCountries() { List countryList = CurrencyUnit.registeredCountries(); assertTrue(countryList.contains("GB")); assertTrue(countryList.contains("EU")); @@ -181,7 +215,7 @@ public void test_registeredCountries() { } @Test - public void test_registeredCountries_sorted() { + void test_registeredCountries_sorted() { List curList1 = CurrencyUnit.registeredCountries(); List curList2 = CurrencyUnit.registeredCountries(); Collections.sort(curList2); @@ -195,260 +229,298 @@ public void test_registeredCountries_sorted() { // constants //----------------------------------------------------------------------- @Test - public void test_constants() { - assertEquals(CurrencyUnit.of("USD"), CurrencyUnit.USD); - assertEquals(CurrencyUnit.of("EUR"), CurrencyUnit.EUR); - assertEquals(CurrencyUnit.of("JPY"), CurrencyUnit.JPY); - assertEquals(CurrencyUnit.of("GBP"), CurrencyUnit.GBP); - assertEquals(CurrencyUnit.of("CHF"), CurrencyUnit.CHF); - assertEquals(CurrencyUnit.of("AUD"), CurrencyUnit.AUD); - assertEquals(CurrencyUnit.of("CAD"), CurrencyUnit.CAD); + void test_constants() { + assertEquals(CurrencyUnit.USD, CurrencyUnit.of("USD")); + assertEquals(CurrencyUnit.EUR, CurrencyUnit.of("EUR")); + assertEquals(CurrencyUnit.JPY, CurrencyUnit.of("JPY")); + assertEquals(CurrencyUnit.GBP, CurrencyUnit.of("GBP")); + assertEquals(CurrencyUnit.CHF, CurrencyUnit.of("CHF")); + assertEquals(CurrencyUnit.AUD, CurrencyUnit.of("AUD")); + assertEquals(CurrencyUnit.CAD, CurrencyUnit.of("CAD")); } //----------------------------------------------------------------------- // constructor assert //----------------------------------------------------------------------- - @Test(expected = AssertionError.class) - public void test_constructor_nullCode() { - new CurrencyUnit(null, (short) 1, (short) 2); + @Test + void test_constructor_nullCode() { + assertThrows(AssertionError.class, () -> { + new CurrencyUnit(null, (short) 1, (short) 2); + }); } //----------------------------------------------------------------------- // of(Currency) //----------------------------------------------------------------------- @Test - public void test_factory_of_Currency() { + void test_factory_of_Currency() { CurrencyUnit test = CurrencyUnit.of(JDK_GBP); assertEquals("GBP", test.getCode()); } - @Test(expected = NullPointerException.class) - public void test_factory_of_Currency_nullCurrency() { - CurrencyUnit.of((Currency) null); + @Test + void test_factory_of_Currency_nullCurrency() { + assertThrows(NullPointerException.class, () -> { + CurrencyUnit.of((Currency) null); + }); } //----------------------------------------------------------------------- // of(String) //----------------------------------------------------------------------- @Test - public void test_factory_of_String() { + void test_factory_of_String() { CurrencyUnit test = CurrencyUnit.of("GBP"); assertEquals("GBP", test.getCode()); } - @Test(expected = NullPointerException.class) - public void test_factory_of_String_nullString() { - CurrencyUnit.of((String) null); + @Test + void test_factory_of_String_nullString() { + assertThrows(NullPointerException.class, () -> { + CurrencyUnit.of((String) null); + }); } - @Test(expected = IllegalCurrencyException.class) - public void test_factory_of_String_unknownCurrency() { - try { - CurrencyUnit.of("ABC"); - } catch (IllegalCurrencyException ex) { - assertEquals("Unknown currency 'ABC'", ex.getMessage()); - throw ex; - } + @Test + void test_factory_of_String_unknownCurrency() { + assertThrows(IllegalCurrencyException.class, () -> { + try { + CurrencyUnit.of("ABC"); + } catch (IllegalCurrencyException ex) { + assertEquals("Unknown currency 'ABC'", ex.getMessage()); + throw ex; + } + }); } - @Test(expected = IllegalCurrencyException.class) - public void test_factory_of_String_empty() { - CurrencyUnit.of(""); + @Test + void test_factory_of_String_empty() { + assertThrows(IllegalCurrencyException.class, () -> { + CurrencyUnit.of(""); + }); } - @Test(expected = IllegalCurrencyException.class) - public void test_factory_of_String_tooShort_unknown() { - CurrencyUnit.of("AB"); + @Test + void test_factory_of_String_tooShort_unknown() { + assertThrows(IllegalCurrencyException.class, () -> { + CurrencyUnit.of("AB"); + }); } - @Test(expected = IllegalCurrencyException.class) - public void test_factory_of_String_tooLong_unknown() { - CurrencyUnit.of("ABCD"); + @Test + void test_factory_of_String_tooLong_unknown() { + assertThrows(IllegalCurrencyException.class, () -> { + CurrencyUnit.of("ABCD"); + }); } //----------------------------------------------------------------------- // ofNumericCode(String) //----------------------------------------------------------------------- @Test - public void test_factory_ofNumericCode_String() { + void test_factory_ofNumericCode_String() { CurrencyUnit test = CurrencyUnit.ofNumericCode("826"); assertEquals("GBP", test.getCode()); } @Test - public void test_factory_ofNumericCode_String_2char() { + void test_factory_ofNumericCode_String_2char() { CurrencyUnit test = CurrencyUnit.ofNumericCode("051"); assertEquals("AMD", test.getCode()); } @Test - public void test_factory_ofNumericCode_String_2charNoPad() { + void test_factory_ofNumericCode_String_2charNoPad() { CurrencyUnit test = CurrencyUnit.ofNumericCode("51"); assertEquals("AMD", test.getCode()); } @Test - public void test_factory_ofNumericCode_String_1char() { + void test_factory_ofNumericCode_String_1char() { CurrencyUnit test = CurrencyUnit.ofNumericCode("008"); assertEquals("ALL", test.getCode()); } @Test - public void test_factory_ofNumericCode_String_1charNoPad() { + void test_factory_ofNumericCode_String_1charNoPad() { CurrencyUnit test = CurrencyUnit.ofNumericCode("8"); assertEquals("ALL", test.getCode()); } - @Test(expected = NullPointerException.class) - public void test_factory_ofNumericCode_String_nullString() { - CurrencyUnit.ofNumericCode((String) null); + @Test + void test_factory_ofNumericCode_String_nullString() { + assertThrows(NullPointerException.class, () -> { + CurrencyUnit.ofNumericCode((String) null); + }); } - @Test(expected = IllegalCurrencyException.class) - public void test_factory_ofNumericCode_String_unknownCurrency() { - try { - CurrencyUnit.ofNumericCode("111"); - } catch (IllegalCurrencyException ex) { - assertEquals("Unknown currency '111'", ex.getMessage()); - throw ex; - } + @Test + void test_factory_ofNumericCode_String_unknownCurrency() { + assertThrows(IllegalCurrencyException.class, () -> { + try { + CurrencyUnit.ofNumericCode("111"); + } catch (IllegalCurrencyException ex) { + assertEquals("Unknown currency '111'", ex.getMessage()); + throw ex; + } + }); } - @Test(expected = IllegalCurrencyException.class) - public void test_factory_ofNumericCode_String_negative() { - CurrencyUnit.ofNumericCode("-1"); + @Test + void test_factory_ofNumericCode_String_negative() { + assertThrows(IllegalCurrencyException.class, () -> { + CurrencyUnit.ofNumericCode("-1"); + }); } - @Test(expected = IllegalCurrencyException.class) - public void test_factory_ofNumericCode_String_empty() { - try { - CurrencyUnit.ofNumericCode(""); - } catch (IllegalCurrencyException ex) { - assertEquals("Unknown currency ''", ex.getMessage()); - throw ex; - } + @Test + void test_factory_ofNumericCode_String_empty() { + assertThrows(IllegalCurrencyException.class, () -> { + try { + CurrencyUnit.ofNumericCode(""); + } catch (IllegalCurrencyException ex) { + assertEquals("Unknown currency ''", ex.getMessage()); + throw ex; + } + }); } - @Test(expected = IllegalCurrencyException.class) - public void test_factory_ofNumericCode_String_tooLong() { - try { - CurrencyUnit.ofNumericCode("1234"); - } catch (IllegalCurrencyException ex) { - assertEquals("Unknown currency '1234'", ex.getMessage()); - throw ex; - } + @Test + void test_factory_ofNumericCode_String_tooLong() { + assertThrows(IllegalCurrencyException.class, () -> { + try { + CurrencyUnit.ofNumericCode("1234"); + } catch (IllegalCurrencyException ex) { + assertEquals("Unknown currency '1234'", ex.getMessage()); + throw ex; + } + }); } //----------------------------------------------------------------------- // ofNumericCode(int) //----------------------------------------------------------------------- @Test - public void test_factory_ofNumericCode_int() { + void test_factory_ofNumericCode_int() { CurrencyUnit test = CurrencyUnit.ofNumericCode(826); assertEquals("GBP", test.getCode()); } @Test - public void test_factory_ofNumericCode_int_2char() { + void test_factory_ofNumericCode_int_2char() { CurrencyUnit test = CurrencyUnit.ofNumericCode(51); assertEquals("AMD", test.getCode()); } @Test - public void test_factory_ofNumericCode_int_1char() { + void test_factory_ofNumericCode_int_1char() { CurrencyUnit test = CurrencyUnit.ofNumericCode(8); assertEquals("ALL", test.getCode()); } - @Test(expected = IllegalCurrencyException.class) - public void test_factory_ofNumericCode_int_unknownCurrency() { - try { - CurrencyUnit.ofNumericCode(111); - } catch (IllegalCurrencyException ex) { - assertEquals("Unknown currency '111'", ex.getMessage()); - throw ex; - } + @Test + void test_factory_ofNumericCode_int_unknownCurrency() { + assertThrows(IllegalCurrencyException.class, () -> { + try { + CurrencyUnit.ofNumericCode(111); + } catch (IllegalCurrencyException ex) { + assertEquals("Unknown currency '111'", ex.getMessage()); + throw ex; + } + }); } - @Test(expected = IllegalCurrencyException.class) - public void test_factory_ofNumericCode_int_negative() { - try { - CurrencyUnit.ofNumericCode(-1); - } catch (IllegalCurrencyException ex) { - assertEquals("Unknown currency '-1'", ex.getMessage()); - throw ex; - } + @Test + void test_factory_ofNumericCode_int_negative() { + assertThrows(IllegalCurrencyException.class, () -> { + try { + CurrencyUnit.ofNumericCode(-1); + } catch (IllegalCurrencyException ex) { + assertEquals("Unknown currency '-1'", ex.getMessage()); + throw ex; + } + }); } - @Test(expected = IllegalCurrencyException.class) - public void test_factory_ofNumericCode_int_tooLong() { - try { - CurrencyUnit.ofNumericCode(1234); - } catch (IllegalCurrencyException ex) { - assertEquals("Unknown currency '1234'", ex.getMessage()); - throw ex; - } + @Test + void test_factory_ofNumericCode_int_tooLong() { + assertThrows(IllegalCurrencyException.class, () -> { + try { + CurrencyUnit.ofNumericCode(1234); + } catch (IllegalCurrencyException ex) { + assertEquals("Unknown currency '1234'", ex.getMessage()); + throw ex; + } + }); } //----------------------------------------------------------------------- // of(Locale) //----------------------------------------------------------------------- @Test - public void test_factory_of_LocaleUK() { + void test_factory_of_LocaleUK() { CurrencyUnit test = CurrencyUnit.of(Locale.UK); assertEquals("GBP", test.getCode()); } @Test - public void test_factory_of_LocaleUS() { + void test_factory_of_LocaleUS() { CurrencyUnit test = CurrencyUnit.of(Locale.US); assertEquals("USD", test.getCode()); } - @Test(expected = NullPointerException.class) - public void test_factory_of_Locale_nullLocale() { - CurrencyUnit.of((Locale) null); + @Test + void test_factory_of_Locale_nullLocale() { + assertThrows(NullPointerException.class, () -> { + CurrencyUnit.of((Locale) null); + }); } - @Test(expected = IllegalCurrencyException.class) - public void test_factory_of_Locale_unknownCurrency() { - try { - CurrencyUnit.of(new Locale("en", "XY")); - } catch (IllegalCurrencyException ex) { - assertEquals("No currency found for locale 'en_XY'", ex.getMessage()); - throw ex; - } + @Test + void test_factory_of_Locale_unknownCurrency() { + assertThrows(IllegalCurrencyException.class, () -> { + try { + CurrencyUnit.of(new Locale("en", "XY")); + } catch (IllegalCurrencyException ex) { + assertEquals("No currency found for locale 'en_XY'", ex.getMessage()); + throw ex; + } + }); } //----------------------------------------------------------------------- // ofCountry(String) //----------------------------------------------------------------------- @Test - public void test_factory_ofCountry_String() { + void test_factory_ofCountry_String() { CurrencyUnit test = CurrencyUnit.ofCountry("GB"); assertEquals("GBP", test.getCode()); } - @Test(expected = NullPointerException.class) - public void test_factory_ofCountry_String_nullString() { - CurrencyUnit.ofCountry((String) null); + @Test + void test_factory_ofCountry_String_nullString() { + assertThrows(NullPointerException.class, () -> { + CurrencyUnit.ofCountry((String) null); + }); } - @Test(expected = IllegalCurrencyException.class) - public void test_factory_ofCountry_String_unknownCurrency() { - try { - CurrencyUnit.ofCountry("gb"); - } catch (IllegalCurrencyException ex) { - assertEquals("No currency found for country 'gb'", ex.getMessage()); - throw ex; - } + @Test + void test_factory_ofCountry_String_unknownCurrency() { + assertThrows(IllegalCurrencyException.class, () -> { + try { + CurrencyUnit.ofCountry("gb"); + } catch (IllegalCurrencyException ex) { + assertEquals("No currency found for country 'gb'", ex.getMessage()); + throw ex; + } + }); } //----------------------------------------------------------------------- // Serialisation //----------------------------------------------------------------------- @Test - public void test_serialization() throws Exception { + void test_serialization() throws Exception { CurrencyUnit cu = CurrencyUnit.of("GBP"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (ObjectOutputStream oos = new ObjectOutputStream(baos)) { @@ -460,41 +532,45 @@ public void test_serialization() throws Exception { } } - @Test(expected = InvalidObjectException.class) - public void test_serialization_invalidNumericCode() throws Exception { + @Test + void test_serialization_invalidNumericCode() throws IOException { CurrencyUnit cu = new CurrencyUnit("GBP", (short) 234, (short) 2); ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (ObjectOutputStream oos = new ObjectOutputStream(baos)) { oos.writeObject(cu); oos.close(); ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); - try { - ois.readObject(); - } catch (InvalidObjectException ex) { - // expected - assertTrue(ex.getMessage().contains("numeric code")); - assertTrue(ex.getMessage().contains("currency GBP")); - throw ex; - } + assertThrows(InvalidObjectException.class, () -> { + try { + ois.readObject(); + } catch (InvalidObjectException ex) { + // expected + assertTrue(ex.getMessage().contains("numeric code")); + assertTrue(ex.getMessage().contains("currency GBP")); + throw ex; + } + }); } } - @Test(expected = InvalidObjectException.class) - public void test_serialization_invalidDecimalPlaces() throws Exception { + @Test + void test_serialization_invalidDecimalPlaces() throws IOException { CurrencyUnit cu = new CurrencyUnit("GBP", (short) 826, (short) 1); ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (ObjectOutputStream oos = new ObjectOutputStream(baos)) { oos.writeObject(cu); oos.close(); ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); - try { - ois.readObject(); - } catch (InvalidObjectException ex) { - // expected - assertTrue(ex.getMessage().contains("decimal places")); - assertTrue(ex.getMessage().contains("currency GBP")); - throw ex; - } + assertThrows(InvalidObjectException.class, () -> { + try { + ois.readObject(); + } catch (InvalidObjectException ex) { + // expected + assertTrue(ex.getMessage().contains("decimal places")); + assertTrue(ex.getMessage().contains("currency GBP")); + throw ex; + } + }); } } @@ -502,25 +578,25 @@ public void test_serialization_invalidDecimalPlaces() throws Exception { // getNumeric3Code() //----------------------------------------------------------------------- @Test - public void test_getNumeric3Code_GBP() { + void test_getNumeric3Code_GBP() { CurrencyUnit test = CurrencyUnit.of("GBP"); assertEquals("826", test.getNumeric3Code()); } @Test - public void test_getNumeric3Code_ALL() { + void test_getNumeric3Code_ALL() { CurrencyUnit test = CurrencyUnit.of("ALL"); assertEquals("008", test.getNumeric3Code()); } @Test - public void test_getNumeric3Code_AMD() { + void test_getNumeric3Code_AMD() { CurrencyUnit test = CurrencyUnit.of("AMD"); assertEquals("051", test.getNumeric3Code()); } @Test - public void test_getNumeric3Code_XFU() { + void test_getNumeric3Code_XFU() { CurrencyUnit test = CurrencyUnit.of("XFU"); assertEquals("", test.getNumeric3Code()); } @@ -529,7 +605,7 @@ public void test_getNumeric3Code_XFU() { // getNumericCode() //----------------------------------------------------------------------- @Test - public void test_getNumericCode_GBP() { + void test_getNumericCode_GBP() { CurrencyUnit test = CurrencyUnit.of("GBP"); assertEquals(826, test.getNumericCode()); } @@ -538,7 +614,7 @@ public void test_getNumericCode_GBP() { // getCurrencyCodes() //----------------------------------------------------------------------- @Test - public void test_getCurrencyCodes_GBP() { + void test_getCurrencyCodes_GBP() { Set test = CurrencyUnit.of("GBP").getCountryCodes(); assertTrue(test.contains("GB")); assertTrue(test.contains("IM")); @@ -550,19 +626,19 @@ public void test_getCurrencyCodes_GBP() { // getDecimalPlaces() //----------------------------------------------------------------------- @Test - public void test_getDecimalPlaces_GBP() { + void test_getDecimalPlaces_GBP() { CurrencyUnit test = CurrencyUnit.of("GBP"); assertEquals(2, test.getDecimalPlaces()); } @Test - public void test_getDecimalPlaces_JPY() { + void test_getDecimalPlaces_JPY() { CurrencyUnit test = CurrencyUnit.of("JPY"); assertEquals(0, test.getDecimalPlaces()); } @Test - public void test_getDecimalPlaces_XXX() { + void test_getDecimalPlaces_XXX() { CurrencyUnit test = CurrencyUnit.of("XXX"); assertEquals(0, test.getDecimalPlaces()); } @@ -571,19 +647,19 @@ public void test_getDecimalPlaces_XXX() { // isPseudoCurrency() //----------------------------------------------------------------------- @Test - public void test_isPseudoCurrency_GBP() { + void test_isPseudoCurrency_GBP() { CurrencyUnit test = CurrencyUnit.of("GBP"); assertFalse(test.isPseudoCurrency()); } @Test - public void test_isPseudoCurrency_JPY() { + void test_isPseudoCurrency_JPY() { CurrencyUnit test = CurrencyUnit.of("JPY"); assertFalse(test.isPseudoCurrency()); } @Test - public void test_isPseudoCurrency_XXX() { + void test_isPseudoCurrency_XXX() { CurrencyUnit test = CurrencyUnit.of("XXX"); assertTrue(test.isPseudoCurrency()); } @@ -592,7 +668,7 @@ public void test_isPseudoCurrency_XXX() { // getSymbol() //----------------------------------------------------------------------- @Test - public void test_getSymbol_GBP() { + void test_getSymbol_GBP() { Locale loc = Locale.getDefault(); try { Locale.setDefault(Locale.UK); @@ -604,7 +680,7 @@ public void test_getSymbol_GBP() { } @Test - public void test_getSymbol_JPY() { + void test_getSymbol_JPY() { Locale loc = Locale.getDefault(); try { Locale.setDefault(Locale.UK); @@ -616,7 +692,7 @@ public void test_getSymbol_JPY() { } @Test - public void test_getSymbol_TMT() { + void test_getSymbol_TMT() { Locale loc = Locale.getDefault(); try { Locale.setDefault(Locale.UK); @@ -628,7 +704,7 @@ public void test_getSymbol_TMT() { } @Test - public void test_getSymbol_XXX() { + void test_getSymbol_XXX() { Locale loc = Locale.getDefault(); try { Locale.setDefault(Locale.UK); @@ -643,7 +719,7 @@ public void test_getSymbol_XXX() { // getSymbol() //----------------------------------------------------------------------- @Test - public void test_getSymbol_Locale_GBP_UK() { + void test_getSymbol_Locale_GBP_UK() { Locale loc = Locale.getDefault(); try { Locale.setDefault(Locale.UK); @@ -655,7 +731,7 @@ public void test_getSymbol_Locale_GBP_UK() { } @Test - public void test_getSymbol_Locale_GBP_France() { + void test_getSymbol_Locale_GBP_France() { Locale loc = Locale.getDefault(); try { Locale.setDefault(Locale.UK); @@ -667,7 +743,7 @@ public void test_getSymbol_Locale_GBP_France() { } @Test - public void test_getSymbol_Locale_USD_UK() { + void test_getSymbol_Locale_USD_UK() { Locale loc = Locale.getDefault(); try { Locale.setDefault(Locale.UK); @@ -679,7 +755,7 @@ public void test_getSymbol_Locale_USD_UK() { } @Test - public void test_getSymbol_Locale_USD_France() { + void test_getSymbol_Locale_USD_France() { Locale loc = Locale.getDefault(); try { Locale.setDefault(Locale.UK); @@ -691,7 +767,7 @@ public void test_getSymbol_Locale_USD_France() { } @Test - public void test_getSymbol_Locale_JPY_Japan() { + void test_getSymbol_Locale_JPY_Japan() { Locale loc = Locale.getDefault(); try { Locale.setDefault(Locale.UK); @@ -703,7 +779,7 @@ public void test_getSymbol_Locale_JPY_Japan() { } @Test - public void test_getSymbol_TMT_UK() { + void test_getSymbol_TMT_UK() { Locale loc = Locale.getDefault(); try { Locale.setDefault(Locale.UK); @@ -715,7 +791,7 @@ public void test_getSymbol_TMT_UK() { } @Test - public void test_getSymbol_Locale_XXX() { + void test_getSymbol_Locale_XXX() { Locale loc = Locale.getDefault(); try { Locale.setDefault(Locale.UK); @@ -730,7 +806,7 @@ public void test_getSymbol_Locale_XXX() { // toCurrency() //----------------------------------------------------------------------- @Test - public void test_toCurrency() { + void test_toCurrency() { CurrencyUnit test = CurrencyUnit.of("GBP"); assertEquals(JDK_GBP, test.toCurrency()); } @@ -739,7 +815,7 @@ public void test_toCurrency() { // compareTo() //----------------------------------------------------------------------- @Test - public void test_compareTo() { + void test_compareTo() { CurrencyUnit a = CurrencyUnit.of("EUR"); CurrencyUnit b = CurrencyUnit.of("GBP"); CurrencyUnit c = CurrencyUnit.of("JPY"); @@ -757,16 +833,18 @@ public void test_compareTo() { assertTrue(c.compareTo(b) > 0); } - @Test(expected = NullPointerException.class) - public void test_compareTo_null() { - CurrencyUnit.of("EUR").compareTo(null); + @Test + void test_compareTo_null() { + assertThrows(NullPointerException.class, () -> { + CurrencyUnit.of("EUR").compareTo(null); + }); } //----------------------------------------------------------------------- // equals() hashCode() //----------------------------------------------------------------------- @Test - public void test_equals_hashCode() { + void test_equals_hashCode() { CurrencyUnit a = CurrencyUnit.of("GBP"); CurrencyUnit b = CurrencyUnit.of("GBP"); CurrencyUnit c = CurrencyUnit.of("EUR"); @@ -783,7 +861,7 @@ public void test_equals_hashCode() { } @Test - public void test_equals_false() { + void test_equals_false() { CurrencyUnit a = CurrencyUnit.of("GBP"); assertFalse(a.equals(null)); Object obj = "String"; // avoid warning in Eclipse @@ -795,7 +873,7 @@ public void test_equals_false() { // toString() //----------------------------------------------------------------------- @Test - public void test_toString() { + void test_toString() { CurrencyUnit test = CurrencyUnit.of("GBP"); assertEquals("GBP", test.toString()); } diff --git a/src/test/java/org/joda/money/TestCurrencyUnitExtension.java b/src/test/java/org/joda/money/TestCurrencyUnitExtension.java index 407c996..5109545 100644 --- a/src/test/java/org/joda/money/TestCurrencyUnitExtension.java +++ b/src/test/java/org/joda/money/TestCurrencyUnitExtension.java @@ -15,20 +15,21 @@ */ package org.joda.money; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Test CurrencyUnit. */ -public class TestCurrencyUnitExtension { +class TestCurrencyUnitExtension { @Test - public void test_CurrencyFromMoneyData() { + void test_CurrencyFromMoneyData() { List curList = CurrencyUnit.registeredCurrencies(); boolean found = false; for (CurrencyUnit currencyUnit : curList) { @@ -37,11 +38,11 @@ public void test_CurrencyFromMoneyData() { break; } } - assertEquals(true, found); + assertTrue(found); } @Test - public void test_CurrencyFromMoneyDataExtension() { + void test_CurrencyFromMoneyDataExtension() { List curList = CurrencyUnit.registeredCurrencies(); boolean found = false; for (CurrencyUnit currencyUnit : curList) { @@ -50,11 +51,11 @@ public void test_CurrencyFromMoneyDataExtension() { break; } } - assertEquals(true, found); + assertTrue(found); } @Test - public void test_LargerDecimalPrecisionCurrencyFromMoneyDataExtension() { + void test_LargerDecimalPrecisionCurrencyFromMoneyDataExtension() { List curList = CurrencyUnit.registeredCurrencies(); boolean found = false; for (CurrencyUnit currencyUnit : curList) { @@ -64,11 +65,11 @@ public void test_LargerDecimalPrecisionCurrencyFromMoneyDataExtension() { break; } } - assertEquals(true, found); + assertTrue(found); } @Test - public void test_InvalidLargerDecimalPrecisionCurrencyFromMoneyDataExtension() { + void test_InvalidLargerDecimalPrecisionCurrencyFromMoneyDataExtension() { for (CurrencyUnit currencyUnit : CurrencyUnit.registeredCurrencies()) { if (currencyUnit.getCode().equals("XXL")) { fail("Currency XXL should not exist"); @@ -77,7 +78,7 @@ public void test_InvalidLargerDecimalPrecisionCurrencyFromMoneyDataExtension() { } @Test - public void test_CurrencyMissing() { + void test_CurrencyMissing() { for (CurrencyUnit currencyUnit : CurrencyUnit.registeredCurrencies()) { if (currencyUnit.getCode().equals("NMC")) { fail("Currency NMC should not exist"); @@ -86,11 +87,11 @@ public void test_CurrencyMissing() { } @Test - public void test_CurrencyEURChanged() { + void test_CurrencyEURChanged() { CurrencyUnit currency = CurrencyUnit.ofCountry("HU"); assertEquals(CurrencyUnit.EUR, currency); - assertEquals(true, CurrencyUnit.EUR.getCountryCodes().contains("HU")); - assertEquals(true, CurrencyUnit.of("HUF").getCountryCodes().isEmpty()); + assertTrue(CurrencyUnit.EUR.getCountryCodes().contains("HU")); + assertTrue(CurrencyUnit.of("HUF").getCountryCodes().isEmpty()); } } diff --git a/src/test/java/org/joda/money/TestIllegalCurrencyException.java b/src/test/java/org/joda/money/TestIllegalCurrencyException.java index fc67856..3771528 100644 --- a/src/test/java/org/joda/money/TestIllegalCurrencyException.java +++ b/src/test/java/org/joda/money/TestIllegalCurrencyException.java @@ -15,30 +15,31 @@ */ package org.joda.money; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Test IllegalCurrencyException. */ -public class TestIllegalCurrencyException { +class TestIllegalCurrencyException { //----------------------------------------------------------------------- // new (String) //----------------------------------------------------------------------- @Test - public void test_String() { + void test_String() { IllegalCurrencyException test = new IllegalCurrencyException("PROBLEM"); assertEquals("PROBLEM", test.getMessage()); - assertEquals(null, test.getCause()); + assertNull(test.getCause()); } @Test - public void test_String_nullString() { + void test_String_nullString() { IllegalCurrencyException test = new IllegalCurrencyException(null); - assertEquals(null, test.getMessage()); - assertEquals(null, test.getCause()); + assertNull(test.getMessage()); + assertNull(test.getCause()); } } diff --git a/src/test/java/org/joda/money/TestMoney.java b/src/test/java/org/joda/money/TestMoney.java index d6bd40a..38ea19f 100644 --- a/src/test/java/org/joda/money/TestMoney.java +++ b/src/test/java/org/joda/money/TestMoney.java @@ -15,12 +15,16 @@ */ package org.joda.money; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; +import java.io.IOException; import java.io.InvalidObjectException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; @@ -32,18 +36,14 @@ import java.util.Arrays; import java.util.Collections; -import org.junit.Test; -import org.junit.runner.RunWith; - -import com.tngtech.java.junit.dataprovider.DataProvider; -import com.tngtech.java.junit.dataprovider.DataProviderRunner; -import com.tngtech.java.junit.dataprovider.UseDataProvider; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; /** * Test Money. */ -@RunWith(DataProviderRunner.class) -public class TestMoney { +class TestMoney { private static final CurrencyUnit GBP = CurrencyUnit.of("GBP"); private static final CurrencyUnit EUR = CurrencyUnit.of("EUR"); @@ -85,7 +85,7 @@ public class TestMoney { // of(Currency,BigDecimal) //----------------------------------------------------------------------- @Test - public void test_factory_of_Currency_BigDecimal() { + void test_factory_of_Currency_BigDecimal() { Money test = Money.of(GBP, BIGDEC_2_34); assertEquals(GBP, test.getCurrencyUnit()); assertEquals(234, test.getAmountMinorInt()); @@ -93,38 +93,46 @@ public void test_factory_of_Currency_BigDecimal() { } @Test - public void test_factory_of_Currency_BigDecimal_correctScale() { + void test_factory_of_Currency_BigDecimal_correctScale() { Money test = Money.of(GBP, BIGDEC_2_3); assertEquals(GBP, test.getCurrencyUnit()); assertEquals(230, test.getAmountMinorInt()); assertEquals(2, test.getAmount().scale()); } - @Test(expected = ArithmeticException.class) - public void test_factory_of_Currency_BigDecimal_invalidScaleGBP() { - Money.of(GBP, BIGDEC_2_345); + @Test + void test_factory_of_Currency_BigDecimal_invalidScaleGBP() { + assertThrows(ArithmeticException.class, () -> { + Money.of(GBP, BIGDEC_2_345); + }); } - @Test(expected = ArithmeticException.class) - public void test_factory_of_Currency_BigDecimal_invalidScaleJPY() { - Money.of(JPY, BIGDEC_2_3); + @Test + void test_factory_of_Currency_BigDecimal_invalidScaleJPY() { + assertThrows(ArithmeticException.class, () -> { + Money.of(JPY, BIGDEC_2_3); + }); } - @Test(expected = NullPointerException.class) - public void test_factory_of_Currency_BigDecimal_nullCurrency() { - Money.of((CurrencyUnit) null, BIGDEC_2_34); + @Test + void test_factory_of_Currency_BigDecimal_nullCurrency() { + assertThrows(NullPointerException.class, () -> { + Money.of((CurrencyUnit) null, BIGDEC_2_34); + }); } - @Test(expected = NullPointerException.class) - public void test_factory_of_Currency_BigDecimal_nullBigDecimal() { - Money.of(GBP, (BigDecimal) null); + @Test + void test_factory_of_Currency_BigDecimal_nullBigDecimal() { + assertThrows(NullPointerException.class, () -> { + Money.of(GBP, (BigDecimal) null); + }); } //----------------------------------------------------------------------- // of(Currency,BigDecimal,RoundingMode) //----------------------------------------------------------------------- @Test - public void test_factory_of_Currency_BigDecimal_GBP_RoundingMode_DOWN() { + void test_factory_of_Currency_BigDecimal_GBP_RoundingMode_DOWN() { Money test = Money.of(GBP, BIGDEC_2_34, RoundingMode.DOWN); assertEquals(GBP, test.getCurrencyUnit()); assertEquals(234, test.getAmountMinorInt()); @@ -132,7 +140,7 @@ public void test_factory_of_Currency_BigDecimal_GBP_RoundingMode_DOWN() { } @Test - public void test_factory_of_Currency_BigDecimal_JPY_RoundingMode_DOWN() { + void test_factory_of_Currency_BigDecimal_JPY_RoundingMode_DOWN() { Money test = Money.of(JPY, BIGDEC_2_34, RoundingMode.DOWN); assertEquals(JPY, test.getCurrencyUnit()); assertEquals(2, test.getAmountMinorInt()); @@ -140,38 +148,46 @@ public void test_factory_of_Currency_BigDecimal_JPY_RoundingMode_DOWN() { } @Test - public void test_factory_of_Currency_BigDecimal_JPY_RoundingMode_UP() { + void test_factory_of_Currency_BigDecimal_JPY_RoundingMode_UP() { Money test = Money.of(JPY, BIGDEC_2_34, RoundingMode.UP); assertEquals(JPY, test.getCurrencyUnit()); assertEquals(3, test.getAmountMinorInt()); assertEquals(0, test.getAmount().scale()); } - @Test(expected = ArithmeticException.class) - public void test_factory_of_Currency_BigDecimal_RoundingMode_UNNECESSARY() { - Money.of(JPY, BIGDEC_2_34, RoundingMode.UNNECESSARY); + @Test + void test_factory_of_Currency_BigDecimal_RoundingMode_UNNECESSARY() { + assertThrows(ArithmeticException.class, () -> { + Money.of(JPY, BIGDEC_2_34, RoundingMode.UNNECESSARY); + }); } - @Test(expected = NullPointerException.class) - public void test_factory_of_Currency_BigDecimal_RoundingMode_nullCurrency() { - Money.of((CurrencyUnit) null, BIGDEC_2_34, RoundingMode.DOWN); + @Test + void test_factory_of_Currency_BigDecimal_RoundingMode_nullCurrency() { + assertThrows(NullPointerException.class, () -> { + Money.of((CurrencyUnit) null, BIGDEC_2_34, RoundingMode.DOWN); + }); } - @Test(expected = NullPointerException.class) - public void test_factory_of_Currency_BigDecimal_RoundingMode_nullBigDecimal() { - Money.of(GBP, (BigDecimal) null, RoundingMode.DOWN); + @Test + void test_factory_of_Currency_BigDecimal_RoundingMode_nullBigDecimal() { + assertThrows(NullPointerException.class, () -> { + Money.of(GBP, (BigDecimal) null, RoundingMode.DOWN); + }); } - @Test(expected = NullPointerException.class) - public void test_factory_of_Currency_BigDecimal_RoundingMode_nullRoundingMode() { - Money.of(GBP, BIGDEC_2_34, (RoundingMode) null); + @Test + void test_factory_of_Currency_BigDecimal_RoundingMode_nullRoundingMode() { + assertThrows(NullPointerException.class, () -> { + Money.of(GBP, BIGDEC_2_34, (RoundingMode) null); + }); } //----------------------------------------------------------------------- // of(Currency,double) //----------------------------------------------------------------------- @Test - public void test_factory_of_Currency_double() { + void test_factory_of_Currency_double() { Money test = Money.of(GBP, 2.34d); assertEquals(GBP, test.getCurrencyUnit()); assertEquals(234, test.getAmountMinorInt()); @@ -179,7 +195,7 @@ public void test_factory_of_Currency_double() { } @Test - public void test_factory_of_Currency_double_correctScale() { + void test_factory_of_Currency_double_correctScale() { Money test = Money.of(GBP, 2.3d); assertEquals(GBP, test.getCurrencyUnit()); assertEquals(230, test.getAmountMinorInt()); @@ -187,7 +203,7 @@ public void test_factory_of_Currency_double_correctScale() { } @Test - public void test_factory_of_Currency_double_trailingZero1() { + void test_factory_of_Currency_double_trailingZero1() { Money test = Money.of(GBP, 1.230d); assertEquals(GBP, test.getCurrencyUnit()); assertEquals(BigDecimal.valueOf(123L, 2), test.getAmount()); @@ -195,7 +211,7 @@ public void test_factory_of_Currency_double_trailingZero1() { } @Test - public void test_factory_of_Currency_double_trailingZero2() { + void test_factory_of_Currency_double_trailingZero2() { Money test = Money.of(GBP, 1.20d); assertEquals(GBP, test.getCurrencyUnit()); assertEquals(BigDecimal.valueOf(120L, 2), test.getAmount()); @@ -203,7 +219,7 @@ public void test_factory_of_Currency_double_trailingZero2() { } @Test - public void test_factory_of_Currency_double_medium() { + void test_factory_of_Currency_double_medium() { Money test = Money.of(GBP, 2000d); assertEquals(GBP, test.getCurrencyUnit()); assertEquals(BigDecimal.valueOf(200000L, 2), test.getAmount()); @@ -211,33 +227,39 @@ public void test_factory_of_Currency_double_medium() { } @Test - public void test_factory_of_Currency_double_big() { + void test_factory_of_Currency_double_big() { Money test = Money.of(GBP, 200000000d); assertEquals(GBP, test.getCurrencyUnit()); assertEquals(BigDecimal.valueOf(20000000000L, 2), test.getAmount()); assertEquals(2, test.getScale()); } - @Test(expected = ArithmeticException.class) - public void test_factory_of_Currency_double_invalidScaleGBP() { - Money.of(GBP, 2.345d); + @Test + void test_factory_of_Currency_double_invalidScaleGBP() { + assertThrows(ArithmeticException.class, () -> { + Money.of(GBP, 2.345d); + }); } - @Test(expected = ArithmeticException.class) - public void test_factory_of_Currency_double_invalidScaleJPY() { - Money.of(JPY, 2.3d); + @Test + void test_factory_of_Currency_double_invalidScaleJPY() { + assertThrows(ArithmeticException.class, () -> { + Money.of(JPY, 2.3d); + }); } - @Test(expected = NullPointerException.class) - public void test_factory_of_Currency_double_nullCurrency() { - Money.of((CurrencyUnit) null, BIGDEC_2_34); + @Test + void test_factory_of_Currency_double_nullCurrency() { + assertThrows(NullPointerException.class, () -> { + Money.of((CurrencyUnit) null, BIGDEC_2_34); + }); } //----------------------------------------------------------------------- // of(Currency,double,RoundingMode) //----------------------------------------------------------------------- @Test - public void test_factory_of_Currency_double_GBP_RoundingMode_DOWN() { + void test_factory_of_Currency_double_GBP_RoundingMode_DOWN() { Money test = Money.of(GBP, 2.34d, RoundingMode.DOWN); assertEquals(GBP, test.getCurrencyUnit()); assertEquals(234, test.getAmountMinorInt()); @@ -245,7 +267,7 @@ public void test_factory_of_Currency_double_GBP_RoundingMode_DOWN() { } @Test - public void test_factory_of_Currency_double_JPY_RoundingMode_DOWN() { + void test_factory_of_Currency_double_JPY_RoundingMode_DOWN() { Money test = Money.of(JPY, 2.34d, RoundingMode.DOWN); assertEquals(JPY, test.getCurrencyUnit()); assertEquals(2, test.getAmountMinorInt()); @@ -253,81 +275,93 @@ public void test_factory_of_Currency_double_JPY_RoundingMode_DOWN() { } @Test - public void test_factory_of_Currency_double_JPY_RoundingMode_UP() { + void test_factory_of_Currency_double_JPY_RoundingMode_UP() { Money test = Money.of(JPY, 2.34d, RoundingMode.UP); assertEquals(JPY, test.getCurrencyUnit()); assertEquals(3, test.getAmountMinorInt()); assertEquals(0, test.getAmount().scale()); } - @Test(expected = ArithmeticException.class) - public void test_factory_of_Currency_double_RoundingMode_UNNECESSARY() { - Money.of(JPY, 2.34d, RoundingMode.UNNECESSARY); + @Test + void test_factory_of_Currency_double_RoundingMode_UNNECESSARY() { + assertThrows(ArithmeticException.class, () -> { + Money.of(JPY, 2.34d, RoundingMode.UNNECESSARY); + }); } - @Test(expected = NullPointerException.class) - public void test_factory_of_Currency_double_RoundingMode_nullCurrency() { - Money.of((CurrencyUnit) null, 2.34d, RoundingMode.DOWN); + @Test + void test_factory_of_Currency_double_RoundingMode_nullCurrency() { + assertThrows(NullPointerException.class, () -> { + Money.of((CurrencyUnit) null, 2.34d, RoundingMode.DOWN); + }); } - @Test(expected = NullPointerException.class) - public void test_factory_of_Currency_double_RoundingMode_nullRoundingMode() { - Money.of(GBP, 2.34d, (RoundingMode) null); + @Test + void test_factory_of_Currency_double_RoundingMode_nullRoundingMode() { + assertThrows(NullPointerException.class, () -> { + Money.of(GBP, 2.34d, (RoundingMode) null); + }); } //----------------------------------------------------------------------- // ofMajor(Currency,long) //----------------------------------------------------------------------- @Test - public void test_factory_ofMajor_Currency_long() { + void test_factory_ofMajor_Currency_long() { Money test = Money.ofMajor(GBP, 234); assertEquals(GBP, test.getCurrencyUnit()); assertEquals(23400, test.getAmountMinorInt()); assertEquals(2, test.getAmount().scale()); } - @Test(expected = NullPointerException.class) - public void test_factory_ofMajor_Currency_long_nullCurrency() { - Money.ofMajor((CurrencyUnit) null, 234); + @Test + void test_factory_ofMajor_Currency_long_nullCurrency() { + assertThrows(NullPointerException.class, () -> { + Money.ofMajor((CurrencyUnit) null, 234); + }); } //----------------------------------------------------------------------- // ofMinor(Currency,long) //----------------------------------------------------------------------- @Test - public void test_factory_ofMinor_Currency_long() { + void test_factory_ofMinor_Currency_long() { Money test = Money.ofMinor(GBP, 234); assertEquals(GBP, test.getCurrencyUnit()); assertEquals(234, test.getAmountMinorInt()); assertEquals(2, test.getAmount().scale()); } - @Test(expected = NullPointerException.class) - public void test_factory_ofMinor_Currency_long_nullCurrency() { - Money.ofMinor((CurrencyUnit) null, 234); + @Test + void test_factory_ofMinor_Currency_long_nullCurrency() { + assertThrows(NullPointerException.class, () -> { + Money.ofMinor((CurrencyUnit) null, 234); + }); } //----------------------------------------------------------------------- // zero(Currency) //----------------------------------------------------------------------- @Test - public void test_factory_zero_Currency() { + void test_factory_zero_Currency() { Money test = Money.zero(GBP); assertEquals(GBP, test.getCurrencyUnit()); assertEquals(0, test.getAmountMinorInt()); assertEquals(2, test.getAmount().scale()); } - @Test(expected = NullPointerException.class) - public void test_factory_zero_Currency_nullCurrency() { - Money.zero((CurrencyUnit) null); + @Test + void test_factory_zero_Currency_nullCurrency() { + assertThrows(NullPointerException.class, () -> { + Money.zero((CurrencyUnit) null); + }); } //----------------------------------------------------------------------- // from(BigMoneyProvider) //----------------------------------------------------------------------- @Test - public void test_factory_from_BigMoneyProvider() { + void test_factory_from_BigMoneyProvider() { Money test = Money.of(BigMoney.parse("GBP 104.23")); assertEquals(GBP, test.getCurrencyUnit()); assertEquals(10423, test.getAmountMinorInt()); @@ -335,56 +369,64 @@ public void test_factory_from_BigMoneyProvider() { } @Test - public void test_factory_from_BigMoneyProvider_fixScale() { + void test_factory_from_BigMoneyProvider_fixScale() { Money test = Money.of(BigMoney.parse("GBP 104.2")); assertEquals(GBP, test.getCurrencyUnit()); assertEquals(10420, test.getAmountMinorInt()); assertEquals(2, test.getAmount().scale()); } - @Test(expected = ArithmeticException.class) - public void test_factory_from_BigMoneyProvider_invalidCurrencyScale() { - Money.of(BigMoney.parse("GBP 104.235")); + @Test + void test_factory_from_BigMoneyProvider_invalidCurrencyScale() { + assertThrows(ArithmeticException.class, () -> { + Money.of(BigMoney.parse("GBP 104.235")); + }); } - @Test(expected = NullPointerException.class) - public void test_factory_from_BigMoneyProvider_nullBigMoneyProvider() { - Money.of((BigMoneyProvider) null); + @Test + void test_factory_from_BigMoneyProvider_nullBigMoneyProvider() { + assertThrows(NullPointerException.class, () -> { + Money.of((BigMoneyProvider) null); + }); } //----------------------------------------------------------------------- // from(BigMoneyProvider,RoundingMode) //----------------------------------------------------------------------- @Test - public void test_factory_from_BigMoneyProvider_RoundingMode() { + void test_factory_from_BigMoneyProvider_RoundingMode() { Money test = Money.of(BigMoney.parse("GBP 104.235"), RoundingMode.HALF_EVEN); assertEquals(GBP, test.getCurrencyUnit()); assertEquals(10424, test.getAmountMinorInt()); assertEquals(2, test.getAmount().scale()); } - @Test(expected = NullPointerException.class) - public void test_factory_from_BigMoneyProvider_RoundingMode_nullBigMoneyProvider() { - Money.of((BigMoneyProvider) null, RoundingMode.DOWN); + @Test + void test_factory_from_BigMoneyProvider_RoundingMode_nullBigMoneyProvider() { + assertThrows(NullPointerException.class, () -> { + Money.of((BigMoneyProvider) null, RoundingMode.DOWN); + }); } - @Test(expected = NullPointerException.class) - public void test_factory_from_BigMoneyProvider_RoundingMode_nullRoundingMode() { - Money.of(BigMoney.parse("GBP 104.235"), (RoundingMode) null); + @Test + void test_factory_from_BigMoneyProvider_RoundingMode_nullRoundingMode() { + assertThrows(NullPointerException.class, () -> { + Money.of(BigMoney.parse("GBP 104.235"), (RoundingMode) null); + }); } //----------------------------------------------------------------------- // total(Money...) //----------------------------------------------------------------------- @Test - public void test_factory_total_varargs_1() { + void test_factory_total_varargs_1() { Money test = Money.total(GBP_1_23); assertEquals(GBP, test.getCurrencyUnit()); assertEquals(123, test.getAmountMinorInt()); } @Test - public void test_factory_total_array_1() { + void test_factory_total_array_1() { Money[] array = new Money[] {GBP_1_23}; Money test = Money.total(array); assertEquals(GBP, test.getCurrencyUnit()); @@ -392,129 +434,153 @@ public void test_factory_total_array_1() { } @Test - public void test_factory_total_varargs_3() { + void test_factory_total_varargs_3() { Money test = Money.total(GBP_1_23, GBP_2_33, GBP_2_36); assertEquals(GBP, test.getCurrencyUnit()); assertEquals(592, test.getAmountMinorInt()); } @Test - public void test_factory_total_array_3() { + void test_factory_total_array_3() { Money[] array = new Money[] {GBP_1_23, GBP_2_33, GBP_2_36}; Money test = Money.total(array); assertEquals(GBP, test.getCurrencyUnit()); assertEquals(592, test.getAmountMinorInt()); } - @Test(expected = IllegalArgumentException.class) - public void test_factory_total_varargs_empty() { - Money.total(); + @Test + void test_factory_total_varargs_empty() { + assertThrows(IllegalArgumentException.class, () -> { + Money.total(); + }); } - @Test(expected = IllegalArgumentException.class) - public void test_factory_total_array_empty() { - Money[] array = new Money[0]; - Money.total(array); + @Test + void test_factory_total_array_empty() { + assertThrows(IllegalArgumentException.class, () -> { + Money[] array = new Money[0]; + Money.total(array); + }); } - @Test(expected = CurrencyMismatchException.class) - public void test_factory_total_varargs_currenciesDiffer() { - try { - Money.total(GBP_2_33, JPY_423); - } catch (CurrencyMismatchException ex) { - assertEquals(GBP, ex.getFirstCurrency()); - assertEquals(JPY, ex.getSecondCurrency()); - throw ex; - } + @Test + void test_factory_total_varargs_currenciesDiffer() { + assertThrows(CurrencyMismatchException.class, () -> { + try { + Money.total(GBP_2_33, JPY_423); + } catch (CurrencyMismatchException ex) { + assertEquals(GBP, ex.getFirstCurrency()); + assertEquals(JPY, ex.getSecondCurrency()); + throw ex; + } + }); } - @Test(expected = CurrencyMismatchException.class) - public void test_factory_total_array_currenciesDiffer() { - try { - Money[] array = new Money[] {GBP_2_33, JPY_423}; - Money.total(array); - } catch (CurrencyMismatchException ex) { - assertEquals(GBP, ex.getFirstCurrency()); - assertEquals(JPY, ex.getSecondCurrency()); - throw ex; - } + @Test + void test_factory_total_array_currenciesDiffer() { + assertThrows(CurrencyMismatchException.class, () -> { + try { + Money[] array = new Money[]{GBP_2_33, JPY_423}; + Money.total(array); + } catch (CurrencyMismatchException ex) { + assertEquals(GBP, ex.getFirstCurrency()); + assertEquals(JPY, ex.getSecondCurrency()); + throw ex; + } + }); } - @Test(expected = NullPointerException.class) - public void test_factory_total_varargs_nullFirst() { - Money.total((Money) null, GBP_2_33, GBP_2_36); + @Test + void test_factory_total_varargs_nullFirst() { + assertThrows(NullPointerException.class, () -> { + Money.total((Money) null, GBP_2_33, GBP_2_36); + }); } - @Test(expected = NullPointerException.class) - public void test_factory_total_array_nullFirst() { + @Test + void test_factory_total_array_nullFirst() { Money[] array = new Money[] {null, GBP_2_33, GBP_2_36}; - Money.total(array); + assertThrows(NullPointerException.class, () -> { + Money.total(array); + }); } - @Test(expected = NullPointerException.class) - public void test_factory_total_varargs_nullNotFirst() { - Money.total(GBP_2_33, null, GBP_2_36); + @Test + void test_factory_total_varargs_nullNotFirst() { + assertThrows(NullPointerException.class, () -> { + Money.total(GBP_2_33, null, GBP_2_36); + }); } - @Test(expected = NullPointerException.class) - public void test_factory_total_array_nullNotFirst() { + @Test + void test_factory_total_array_nullNotFirst() { Money[] array = new Money[] {GBP_2_33, null, GBP_2_36}; - Money.total(array); + assertThrows(NullPointerException.class, () -> { + Money.total(array); + }); } //----------------------------------------------------------------------- // total(Iterable) //----------------------------------------------------------------------- @Test - public void test_factory_total_Iterable() { + void test_factory_total_Iterable() { Iterable iterable = Arrays.asList(GBP_1_23, GBP_2_33, GBP_2_36); Money test = Money.total(iterable); assertEquals(GBP, test.getCurrencyUnit()); assertEquals(592, test.getAmountMinorInt()); } - @Test(expected = IllegalArgumentException.class) - public void test_factory_total_Iterable_empty() { + @Test + void test_factory_total_Iterable_empty() { Iterable iterable = Collections.emptyList(); - Money.total(iterable); + assertThrows(IllegalArgumentException.class, () -> { + Money.total(iterable); + }); } - @Test(expected = CurrencyMismatchException.class) - public void test_factory_total_Iterable_currenciesDiffer() { - try { - Iterable iterable = Arrays.asList(GBP_2_33, JPY_423); - Money.total(iterable); - } catch (CurrencyMismatchException ex) { - assertEquals(GBP, ex.getFirstCurrency()); - assertEquals(JPY, ex.getSecondCurrency()); - throw ex; - } + @Test + void test_factory_total_Iterable_currenciesDiffer() { + assertThrows(CurrencyMismatchException.class, () -> { + try { + Iterable iterable = Arrays.asList(GBP_2_33, JPY_423); + Money.total(iterable); + } catch (CurrencyMismatchException ex) { + assertEquals(GBP, ex.getFirstCurrency()); + assertEquals(JPY, ex.getSecondCurrency()); + throw ex; + } + }); } - @Test(expected = NullPointerException.class) - public void test_factory_total_Iterable_nullFirst() { + @Test + void test_factory_total_Iterable_nullFirst() { Iterable iterable = Arrays.asList(null, GBP_2_33, GBP_2_36); - Money.total(iterable); + assertThrows(NullPointerException.class, () -> { + Money.total(iterable); + }); } - @Test(expected = NullPointerException.class) - public void test_factory_total_Iterable_nullNotFirst() { + @Test + void test_factory_total_Iterable_nullNotFirst() { Iterable iterable = Arrays.asList(GBP_2_33, null, GBP_2_36); - Money.total(iterable); + assertThrows(NullPointerException.class, () -> { + Money.total(iterable); + }); } //----------------------------------------------------------------------- // total(CurrencyUnit,Money...) //----------------------------------------------------------------------- @Test - public void test_factory_total_CurrencyUnitVarargs_1() { + void test_factory_total_CurrencyUnitVarargs_1() { Money test = Money.total(GBP, GBP_1_23); assertEquals(GBP, test.getCurrencyUnit()); assertEquals(123, test.getAmountMinorInt()); } @Test - public void test_factory_total_CurrencyUnitArray_1() { + void test_factory_total_CurrencyUnitArray_1() { Money[] array = new Money[] {GBP_1_23}; Money test = Money.total(GBP, array); assertEquals(GBP, test.getCurrencyUnit()); @@ -522,14 +588,14 @@ public void test_factory_total_CurrencyUnitArray_1() { } @Test - public void test_factory_total_CurrencyUnitVarargs_3() { + void test_factory_total_CurrencyUnitVarargs_3() { Money test = Money.total(GBP, GBP_1_23, GBP_2_33, GBP_2_36); assertEquals(GBP, test.getCurrencyUnit()); assertEquals(592, test.getAmountMinorInt()); } @Test - public void test_factory_total_CurrencyUnitArray_3() { + void test_factory_total_CurrencyUnitArray_3() { Money[] array = new Money[] {GBP_1_23, GBP_2_33, GBP_2_36}; Money test = Money.total(GBP, array); assertEquals(GBP, test.getCurrencyUnit()); @@ -537,93 +603,109 @@ public void test_factory_total_CurrencyUnitArray_3() { } @Test - public void test_factory_total_CurrencyUnitVarargs_empty() { + void test_factory_total_CurrencyUnitVarargs_empty() { Money test = Money.total(GBP); assertEquals(GBP, test.getCurrencyUnit()); assertEquals(0, test.getAmountMinorInt()); } @Test - public void test_factory_total_CurrencyUnitArray_empty() { + void test_factory_total_CurrencyUnitArray_empty() { Money[] array = new Money[0]; Money test = Money.total(GBP, array); assertEquals(GBP, test.getCurrencyUnit()); assertEquals(0, test.getAmountMinorInt()); } - @Test(expected = CurrencyMismatchException.class) - public void test_factory_total_CurrencyUnitVarargs_currenciesDiffer() { - try { - Money.total(GBP, JPY_423); - } catch (CurrencyMismatchException ex) { - assertEquals(GBP, ex.getFirstCurrency()); - assertEquals(JPY, ex.getSecondCurrency()); - throw ex; - } + @Test + void test_factory_total_CurrencyUnitVarargs_currenciesDiffer() { + assertThrows(CurrencyMismatchException.class, () -> { + try { + Money.total(GBP, JPY_423); + } catch (CurrencyMismatchException ex) { + assertEquals(GBP, ex.getFirstCurrency()); + assertEquals(JPY, ex.getSecondCurrency()); + throw ex; + } + }); } - @Test(expected = CurrencyMismatchException.class) - public void test_factory_total_CurrencyUnitArray_currenciesDiffer() { - try { - Money[] array = new Money[] {JPY_423}; - Money.total(GBP, array); - } catch (CurrencyMismatchException ex) { - assertEquals(GBP, ex.getFirstCurrency()); - assertEquals(JPY, ex.getSecondCurrency()); - throw ex; - } + @Test + void test_factory_total_CurrencyUnitArray_currenciesDiffer() { + assertThrows(CurrencyMismatchException.class, () -> { + try { + Money[] array = new Money[]{JPY_423}; + Money.total(GBP, array); + } catch (CurrencyMismatchException ex) { + assertEquals(GBP, ex.getFirstCurrency()); + assertEquals(JPY, ex.getSecondCurrency()); + throw ex; + } + }); } - @Test(expected = CurrencyMismatchException.class) - public void test_factory_total_CurrencyUnitVarargs_currenciesDifferInArray() { - try { - Money.total(GBP, GBP_2_33, JPY_423); - } catch (CurrencyMismatchException ex) { - assertEquals(GBP, ex.getFirstCurrency()); - assertEquals(JPY, ex.getSecondCurrency()); - throw ex; - } + @Test + void test_factory_total_CurrencyUnitVarargs_currenciesDifferInArray() { + assertThrows(CurrencyMismatchException.class, () -> { + try { + Money.total(GBP, GBP_2_33, JPY_423); + } catch (CurrencyMismatchException ex) { + assertEquals(GBP, ex.getFirstCurrency()); + assertEquals(JPY, ex.getSecondCurrency()); + throw ex; + } + }); } - @Test(expected = CurrencyMismatchException.class) - public void test_factory_total_CurrencyUnitArray_currenciesDifferInArray() { - try { - Money[] array = new Money[] {GBP_2_33, JPY_423}; - Money.total(GBP, array); - } catch (CurrencyMismatchException ex) { - assertEquals(GBP, ex.getFirstCurrency()); - assertEquals(JPY, ex.getSecondCurrency()); - throw ex; - } + @Test + void test_factory_total_CurrencyUnitArray_currenciesDifferInArray() { + assertThrows(CurrencyMismatchException.class, () -> { + try { + Money[] array = new Money[]{GBP_2_33, JPY_423}; + Money.total(GBP, array); + } catch (CurrencyMismatchException ex) { + assertEquals(GBP, ex.getFirstCurrency()); + assertEquals(JPY, ex.getSecondCurrency()); + throw ex; + } + }); } - @Test(expected = NullPointerException.class) - public void test_factory_total_CurrencyUnitVarargs_nullFirst() { - Money.total(GBP, null, GBP_2_33, GBP_2_36); + @Test + void test_factory_total_CurrencyUnitVarargs_nullFirst() { + assertThrows(NullPointerException.class, () -> { + Money.total(GBP, null, GBP_2_33, GBP_2_36); + }); } - @Test(expected = NullPointerException.class) - public void test_factory_total_CurrencyUnitArray_nullFirst() { + @Test + void test_factory_total_CurrencyUnitArray_nullFirst() { Money[] array = new Money[] {null, GBP_2_33, GBP_2_36}; - Money.total(GBP, array); + assertThrows(NullPointerException.class, () -> { + Money.total(GBP, array); + }); } - @Test(expected = NullPointerException.class) - public void test_factory_total_CurrencyUnitVarargs_nullNotFirst() { - Money.total(GBP, GBP_2_33, null, GBP_2_36); + @Test + void test_factory_total_CurrencyUnitVarargs_nullNotFirst() { + assertThrows(NullPointerException.class, () -> { + Money.total(GBP, GBP_2_33, null, GBP_2_36); + }); } - @Test(expected = NullPointerException.class) - public void test_factory_total_CurrencyUnitArray_nullNotFirst() { + @Test + void test_factory_total_CurrencyUnitArray_nullNotFirst() { Money[] array = new Money[] {GBP_2_33, null, GBP_2_36}; - Money.total(GBP, array); + assertThrows(NullPointerException.class, () -> { + Money.total(GBP, array); + }); } //----------------------------------------------------------------------- // total(CurrencyUnit,Iterable) //----------------------------------------------------------------------- @Test - public void test_factory_total_CurrencyUnitIterable() { + void test_factory_total_CurrencyUnitIterable() { Iterable iterable = Arrays.asList(GBP_1_23, GBP_2_33, GBP_2_36); Money test = Money.total(GBP, iterable); assertEquals(GBP, test.getCurrencyUnit()); @@ -631,53 +713,60 @@ public void test_factory_total_CurrencyUnitIterable() { } @Test - public void test_factory_total_CurrencyUnitIterable_empty() { + void test_factory_total_CurrencyUnitIterable_empty() { Iterable iterable = Collections.emptyList(); Money test = Money.total(GBP, iterable); assertEquals(GBP, test.getCurrencyUnit()); assertEquals(0, test.getAmountMinorInt()); } - @Test(expected = CurrencyMismatchException.class) - public void test_factory_total_CurrencyUnitIterable_currenciesDiffer() { - try { - Iterable iterable = Arrays.asList(JPY_423); - Money.total(GBP, iterable); - } catch (CurrencyMismatchException ex) { - assertEquals(GBP, ex.getFirstCurrency()); - assertEquals(JPY, ex.getSecondCurrency()); - throw ex; - } + @Test + void test_factory_total_CurrencyUnitIterable_currenciesDiffer() { + assertThrows(CurrencyMismatchException.class, () -> { + try { + Iterable iterable = Arrays.asList(JPY_423); + Money.total(GBP, iterable); + } catch (CurrencyMismatchException ex) { + assertEquals(GBP, ex.getFirstCurrency()); + assertEquals(JPY, ex.getSecondCurrency()); + throw ex; + } + }); } - @Test(expected = CurrencyMismatchException.class) - public void test_factory_total_CurrencyUnitIterable_currenciesDifferInIterable() { - try { - Iterable iterable = Arrays.asList(GBP_2_33, JPY_423); - Money.total(GBP, iterable); - } catch (CurrencyMismatchException ex) { - assertEquals(GBP, ex.getFirstCurrency()); - assertEquals(JPY, ex.getSecondCurrency()); - throw ex; - } + @Test + void test_factory_total_CurrencyUnitIterable_currenciesDifferInIterable() { + assertThrows(CurrencyMismatchException.class, () -> { + try { + Iterable iterable = Arrays.asList(GBP_2_33, JPY_423); + Money.total(GBP, iterable); + } catch (CurrencyMismatchException ex) { + assertEquals(GBP, ex.getFirstCurrency()); + assertEquals(JPY, ex.getSecondCurrency()); + throw ex; + } + }); } - @Test(expected = NullPointerException.class) - public void test_factory_total_CurrencyUnitIterable_nullFirst() { + @Test + void test_factory_total_CurrencyUnitIterable_nullFirst() { Iterable iterable = Arrays.asList(null, GBP_2_33, GBP_2_36); - Money.total(GBP, iterable); + assertThrows(NullPointerException.class, () -> { + Money.total(GBP, iterable); + }); } - @Test(expected = NullPointerException.class) - public void test_factory_total_CurrencyUnitIterable_nullNotFirst() { + @Test + void test_factory_total_CurrencyUnitIterable_nullNotFirst() { Iterable iterable = Arrays.asList(GBP_2_33, null, GBP_2_36); - Money.total(GBP, iterable); + assertThrows(NullPointerException.class, () -> { + Money.total(GBP, iterable); + }); } //----------------------------------------------------------------------- // parse(String) //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_parse() { return new Object[][] { {"GBP 2.43", GBP, 243}, @@ -700,37 +789,43 @@ public static Object[][] data_parse() { }; } - @Test - @UseDataProvider("data_parse") - public void test_factory_parse(String str, CurrencyUnit currency, int amount) { + @ParameterizedTest + @MethodSource("data_parse") + void test_factory_parse(String str, CurrencyUnit currency, int amount) { Money test = Money.parse(str); assertEquals(currency, test.getCurrencyUnit()); assertEquals(amount, test.getAmountMinorInt()); } - @Test(expected = IllegalArgumentException.class) - public void test_factory_parse_String_tooShort() { - Money.parse("GBP "); + @Test + void test_factory_parse_String_tooShort() { + assertThrows(IllegalArgumentException.class, () -> { + Money.parse("GBP "); + }); } - @Test(expected = IllegalArgumentException.class) - public void test_factory_parse_String_badCurrency() { - Money.parse("GBX 2.34"); + @Test + void test_factory_parse_String_badCurrency() { + assertThrows(IllegalArgumentException.class, () -> { + Money.parse("GBX 2.34"); + }); } - @Test(expected = NullPointerException.class) - public void test_factory_parse_String_nullString() { - Money.parse((String) null); + @Test + void test_factory_parse_String_nullString() { + assertThrows(NullPointerException.class, () -> { + Money.parse((String) null); + }); } //----------------------------------------------------------------------- // constructor //----------------------------------------------------------------------- @Test - public void test_constructor_null1() throws Exception { + void test_constructor_null1() throws Exception { Constructor con = Money.class.getDeclaredConstructor(BigMoney.class); - assertEquals(false, Modifier.isPublic(con.getModifiers())); - assertEquals(false, Modifier.isProtected(con.getModifiers())); + assertFalse(Modifier.isPublic(con.getModifiers())); + assertFalse(Modifier.isProtected(con.getModifiers())); try { con.setAccessible(true); con.newInstance(new Object[] {null}); @@ -741,7 +836,7 @@ public void test_constructor_null1() throws Exception { } @Test - public void test_constructor_scale() throws Exception { + void test_constructor_scale() throws Exception { Constructor con = Money.class.getDeclaredConstructor(BigMoney.class); try { con.setAccessible(true); @@ -756,7 +851,7 @@ public void test_constructor_scale() throws Exception { // serialization //----------------------------------------------------------------------- @Test - public void test_serialization() throws Exception { + void test_serialization() throws Exception { Money a = GBP_2_34; ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (ObjectOutputStream oos = new ObjectOutputStream(baos)) { @@ -768,8 +863,8 @@ public void test_serialization() throws Exception { } } - @Test(expected = InvalidObjectException.class) - public void test_serialization_invalidNumericCode() throws Exception { + @Test + void test_serialization_invalidNumericCode() throws IOException { CurrencyUnit cu = new CurrencyUnit("GBP", (short) 234, (short) 2); Money m = Money.of(cu, 123.43d); ByteArrayOutputStream baos = new ByteArrayOutputStream(); @@ -777,12 +872,14 @@ public void test_serialization_invalidNumericCode() throws Exception { oos.writeObject(m); oos.close(); ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); - ois.readObject(); + assertThrows(InvalidObjectException.class, () -> { + ois.readObject(); + }); } } - @Test(expected = InvalidObjectException.class) - public void test_serialization_invalidDecimalPlaces() throws Exception { + @Test + void test_serialization_invalidDecimalPlaces() throws IOException { CurrencyUnit cu = new CurrencyUnit("GBP", (short) 826, (short) 3); Money m = Money.of(cu, 123.43d); ByteArrayOutputStream baos = new ByteArrayOutputStream(); @@ -790,7 +887,9 @@ public void test_serialization_invalidDecimalPlaces() throws Exception { oos.writeObject(m); oos.close(); ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); - ois.readObject(); + assertThrows(InvalidObjectException.class, () -> { + ois.readObject(); + }); } } @@ -798,12 +897,12 @@ public void test_serialization_invalidDecimalPlaces() throws Exception { // getCurrencyUnit() //----------------------------------------------------------------------- @Test - public void test_getCurrencyUnit_GBP() { + void test_getCurrencyUnit_GBP() { assertEquals(GBP, GBP_2_34.getCurrencyUnit()); } @Test - public void test_getCurrencyUnit_EUR() { + void test_getCurrencyUnit_EUR() { assertEquals(EUR, Money.parse("EUR -5.78").getCurrencyUnit()); } @@ -811,68 +910,76 @@ public void test_getCurrencyUnit_EUR() { // withCurrencyUnit(Currency) //----------------------------------------------------------------------- @Test - public void test_withCurrencyUnit_Currency() { + void test_withCurrencyUnit_Currency() { Money test = GBP_2_34.withCurrencyUnit(USD); assertEquals("USD 2.34", test.toString()); } @Test - public void test_withCurrencyUnit_Currency_same() { + void test_withCurrencyUnit_Currency_same() { Money test = GBP_2_34.withCurrencyUnit(GBP); assertSame(GBP_2_34, test); } - @Test(expected = ArithmeticException.class) - public void test_withCurrencyUnit_Currency_scaleProblem() { - GBP_2_34.withCurrencyUnit(JPY); + @Test + void test_withCurrencyUnit_Currency_scaleProblem() { + assertThrows(ArithmeticException.class, () -> { + GBP_2_34.withCurrencyUnit(JPY); + }); } - @Test(expected = NullPointerException.class) - public void test_withCurrencyUnit_Currency_nullCurrency() { - GBP_2_34.withCurrencyUnit((CurrencyUnit) null); + @Test + void test_withCurrencyUnit_Currency_nullCurrency() { + assertThrows(NullPointerException.class, () -> { + GBP_2_34.withCurrencyUnit((CurrencyUnit) null); + }); } //----------------------------------------------------------------------- // withCurrencyUnit(Currency,RoundingMode) //----------------------------------------------------------------------- @Test - public void test_withCurrencyUnit_CurrencyRoundingMode_DOWN() { + void test_withCurrencyUnit_CurrencyRoundingMode_DOWN() { Money test = GBP_2_34.withCurrencyUnit(JPY, RoundingMode.DOWN); assertEquals("JPY 2", test.toString()); } @Test - public void test_withCurrencyUnit_CurrencyRoundingMode_UP() { + void test_withCurrencyUnit_CurrencyRoundingMode_UP() { Money test = GBP_2_34.withCurrencyUnit(JPY, RoundingMode.UP); assertEquals("JPY 3", test.toString()); } @Test - public void test_withCurrencyUnit_CurrencyRoundingMode_same() { + void test_withCurrencyUnit_CurrencyRoundingMode_same() { Money test = GBP_2_34.withCurrencyUnit(GBP, RoundingMode.DOWN); assertSame(GBP_2_34, test); } - @Test(expected = ArithmeticException.class) - public void test_withCurrencyUnit_CurrencyRoundingMode_UNECESSARY() { - GBP_2_34.withCurrencyUnit(JPY, RoundingMode.UNNECESSARY); + @Test + void test_withCurrencyUnit_CurrencyRoundingMode_UNECESSARY() { + assertThrows(ArithmeticException.class, () -> { + GBP_2_34.withCurrencyUnit(JPY, RoundingMode.UNNECESSARY); + }); } - @Test(expected = NullPointerException.class) - public void test_withCurrencyUnit_CurrencyRoundingMode_nullCurrency() { - GBP_2_34.withCurrencyUnit((CurrencyUnit) null, RoundingMode.UNNECESSARY); + @Test + void test_withCurrencyUnit_CurrencyRoundingMode_nullCurrency() { + assertThrows(NullPointerException.class, () -> { + GBP_2_34.withCurrencyUnit((CurrencyUnit) null, RoundingMode.UNNECESSARY); + }); } //----------------------------------------------------------------------- // getScale() //----------------------------------------------------------------------- @Test - public void test_getScale_GBP() { + void test_getScale_GBP() { assertEquals(2, GBP_2_34.getScale()); } @Test - public void test_getScale_JPY() { + void test_getScale_JPY() { assertEquals(0, JPY_423.getScale()); } @@ -880,12 +987,12 @@ public void test_getScale_JPY() { // getAmount() //----------------------------------------------------------------------- @Test - public void test_getAmount_positive() { + void test_getAmount_positive() { assertEquals(BIGDEC_2_34, GBP_2_34.getAmount()); } @Test - public void test_getAmount_negative() { + void test_getAmount_negative() { assertEquals(BIGDEC_M5_78, GBP_M5_78.getAmount()); } @@ -893,12 +1000,12 @@ public void test_getAmount_negative() { // getAmountMajor() //----------------------------------------------------------------------- @Test - public void test_getAmountMajor_positive() { + void test_getAmountMajor_positive() { assertEquals(BigDecimal.valueOf(2), GBP_2_34.getAmountMajor()); } @Test - public void test_getAmountMajor_negative() { + void test_getAmountMajor_negative() { assertEquals(BigDecimal.valueOf(-5), GBP_M5_78.getAmountMajor()); } @@ -906,58 +1013,66 @@ public void test_getAmountMajor_negative() { // getAmountMajorLong() //----------------------------------------------------------------------- @Test - public void test_getAmountMajorLong_positive() { + void test_getAmountMajorLong_positive() { assertEquals(2L, GBP_2_34.getAmountMajorLong()); } @Test - public void test_getAmountMajorLong_negative() { + void test_getAmountMajorLong_negative() { assertEquals(-5L, GBP_M5_78.getAmountMajorLong()); } - @Test(expected = ArithmeticException.class) - public void test_getAmountMajorLong_tooBigPositive() { - GBP_LONG_MAX_MAJOR_PLUS1.getAmountMajorLong(); + @Test + void test_getAmountMajorLong_tooBigPositive() { + assertThrows(ArithmeticException.class, () -> { + GBP_LONG_MAX_MAJOR_PLUS1.getAmountMajorLong(); + }); } - @Test(expected = ArithmeticException.class) - public void test_getAmountMajorLong_tooBigNegative() { - GBP_LONG_MIN_MAJOR_MINUS1.getAmountMajorLong(); + @Test + void test_getAmountMajorLong_tooBigNegative() { + assertThrows(ArithmeticException.class, () -> { + GBP_LONG_MIN_MAJOR_MINUS1.getAmountMajorLong(); + }); } //----------------------------------------------------------------------- // getAmountMajorInt() //----------------------------------------------------------------------- @Test - public void test_getAmountMajorInt_positive() { + void test_getAmountMajorInt_positive() { assertEquals(2, GBP_2_34.getAmountMajorInt()); } @Test - public void test_getAmountMajorInt_negative() { + void test_getAmountMajorInt_negative() { assertEquals(-5, GBP_M5_78.getAmountMajorInt()); } - @Test(expected = ArithmeticException.class) - public void test_getAmountMajorInt_tooBigPositive() { - GBP_INT_MAX_MAJOR_PLUS1.getAmountMajorInt(); + @Test + void test_getAmountMajorInt_tooBigPositive() { + assertThrows(ArithmeticException.class, () -> { + GBP_INT_MAX_MAJOR_PLUS1.getAmountMajorInt(); + }); } - @Test(expected = ArithmeticException.class) - public void test_getAmountMajorInt_tooBigNegative() { - GBP_INT_MIN_MAJOR_MINUS1.getAmountMajorInt(); + @Test + void test_getAmountMajorInt_tooBigNegative() { + assertThrows(ArithmeticException.class, () -> { + GBP_INT_MIN_MAJOR_MINUS1.getAmountMajorInt(); + }); } //----------------------------------------------------------------------- // getAmountMinor() //----------------------------------------------------------------------- @Test - public void test_getAmountMinor_positive() { + void test_getAmountMinor_positive() { assertEquals(BigDecimal.valueOf(234), GBP_2_34.getAmountMinor()); } @Test - public void test_getAmountMinor_negative() { + void test_getAmountMinor_negative() { assertEquals(BigDecimal.valueOf(-578), GBP_M5_78.getAmountMinor()); } @@ -965,58 +1080,66 @@ public void test_getAmountMinor_negative() { // getAmountMinorLong() //----------------------------------------------------------------------- @Test - public void test_getAmountMinorLong_positive() { + void test_getAmountMinorLong_positive() { assertEquals(234L, GBP_2_34.getAmountMinorLong()); } @Test - public void test_getAmountMinorLong_negative() { + void test_getAmountMinorLong_negative() { assertEquals(-578L, GBP_M5_78.getAmountMinorLong()); } - @Test(expected = ArithmeticException.class) - public void test_getAmountMinorLong_tooBigPositive() { - GBP_LONG_MAX_PLUS1.getAmountMinorLong(); + @Test + void test_getAmountMinorLong_tooBigPositive() { + assertThrows(ArithmeticException.class, () -> { + GBP_LONG_MAX_PLUS1.getAmountMinorLong(); + }); } - @Test(expected = ArithmeticException.class) - public void test_getAmountMinorLong_tooBigNegative() { - GBP_LONG_MIN_MINUS1.getAmountMinorLong(); + @Test + void test_getAmountMinorLong_tooBigNegative() { + assertThrows(ArithmeticException.class, () -> { + GBP_LONG_MIN_MINUS1.getAmountMinorLong(); + }); } //----------------------------------------------------------------------- // getAmountMinorInt() //----------------------------------------------------------------------- @Test - public void test_getAmountMinorInt_positive() { + void test_getAmountMinorInt_positive() { assertEquals(234, GBP_2_34.getAmountMinorInt()); } @Test - public void test_getAmountMinorInt_negative() { + void test_getAmountMinorInt_negative() { assertEquals(-578, GBP_M5_78.getAmountMinorInt()); } - @Test(expected = ArithmeticException.class) - public void test_getAmountMinorInt_tooBigPositive() { - GBP_INT_MAX_PLUS1.getAmountMinorInt(); + @Test + void test_getAmountMinorInt_tooBigPositive() { + assertThrows(ArithmeticException.class, () -> { + GBP_INT_MAX_PLUS1.getAmountMinorInt(); + }); } - @Test(expected = ArithmeticException.class) - public void test_getAmountMinorInt_tooBigNegative() { - GBP_INT_MIN_MINUS1.getAmountMinorInt(); + @Test + void test_getAmountMinorInt_tooBigNegative() { + assertThrows(ArithmeticException.class, () -> { + GBP_INT_MIN_MINUS1.getAmountMinorInt(); + }); } //----------------------------------------------------------------------- // getMinorPart() //----------------------------------------------------------------------- @Test - public void test_getMinorPart_positive() { + void test_getMinorPart_positive() { assertEquals(34, GBP_2_34.getMinorPart()); } @Test - public void test_getMinorPart_negative() { + void test_getMinorPart_negative() { assertEquals(-78, GBP_M5_78.getMinorPart()); } @@ -1024,394 +1147,436 @@ public void test_getMinorPart_negative() { // isZero() //----------------------------------------------------------------------- @Test - public void test_isZero() { - assertEquals(true, GBP_0_00.isZero()); - assertEquals(false, GBP_2_34.isZero()); - assertEquals(false, GBP_M5_78.isZero()); + void test_isZero() { + assertTrue(GBP_0_00.isZero()); + assertFalse(GBP_2_34.isZero()); + assertFalse(GBP_M5_78.isZero()); } //----------------------------------------------------------------------- // isPositive() //----------------------------------------------------------------------- @Test - public void test_isPositive() { - assertEquals(false, GBP_0_00.isPositive()); - assertEquals(true, GBP_2_34.isPositive()); - assertEquals(false, GBP_M5_78.isPositive()); + void test_isPositive() { + assertFalse(GBP_0_00.isPositive()); + assertTrue(GBP_2_34.isPositive()); + assertFalse(GBP_M5_78.isPositive()); } //----------------------------------------------------------------------- // isPositiveOrZero() //----------------------------------------------------------------------- @Test - public void test_isPositiveOrZero() { - assertEquals(true, GBP_0_00.isPositiveOrZero()); - assertEquals(true, GBP_2_34.isPositiveOrZero()); - assertEquals(false, GBP_M5_78.isPositiveOrZero()); + void test_isPositiveOrZero() { + assertTrue(GBP_0_00.isPositiveOrZero()); + assertTrue(GBP_2_34.isPositiveOrZero()); + assertFalse(GBP_M5_78.isPositiveOrZero()); } //----------------------------------------------------------------------- // isNegative() //----------------------------------------------------------------------- @Test - public void test_isNegative() { - assertEquals(false, GBP_0_00.isNegative()); - assertEquals(false, GBP_2_34.isNegative()); - assertEquals(true, GBP_M5_78.isNegative()); + void test_isNegative() { + assertFalse(GBP_0_00.isNegative()); + assertFalse(GBP_2_34.isNegative()); + assertTrue(GBP_M5_78.isNegative()); } //----------------------------------------------------------------------- // isNegativeOrZero() //----------------------------------------------------------------------- @Test - public void test_isNegativeOrZero() { - assertEquals(true, GBP_0_00.isNegativeOrZero()); - assertEquals(false, GBP_2_34.isNegativeOrZero()); - assertEquals(true, GBP_M5_78.isNegativeOrZero()); + void test_isNegativeOrZero() { + assertTrue(GBP_0_00.isNegativeOrZero()); + assertFalse(GBP_2_34.isNegativeOrZero()); + assertTrue(GBP_M5_78.isNegativeOrZero()); } //----------------------------------------------------------------------- // withAmount(BigDecimal) //----------------------------------------------------------------------- @Test - public void test_withAmount_BigDecimal() { + void test_withAmount_BigDecimal() { Money test = GBP_2_34.withAmount(BIGDEC_M5_78); assertEquals("GBP -5.78", test.toString()); } @Test - public void test_withAmount_BigDecimal_same() { + void test_withAmount_BigDecimal_same() { Money test = GBP_2_34.withAmount(BIGDEC_2_34); assertSame(GBP_2_34, test); } - @Test(expected = ArithmeticException.class) - public void test_withAmount_BigDecimal_invalidScale() { - GBP_2_34.withAmount(new BigDecimal("2.345")); + @Test + void test_withAmount_BigDecimal_invalidScale() { + assertThrows(ArithmeticException.class, () -> { + GBP_2_34.withAmount(new BigDecimal("2.345")); + }); } - @Test(expected = NullPointerException.class) - public void test_withAmount_BigDecimal_nullBigDecimal() { - GBP_2_34.withAmount((BigDecimal) null); + @Test + void test_withAmount_BigDecimal_nullBigDecimal() { + assertThrows(NullPointerException.class, () -> { + GBP_2_34.withAmount((BigDecimal) null); + }); } //----------------------------------------------------------------------- // withAmount(BigDecimal,RoundingMode) //----------------------------------------------------------------------- @Test - public void test_withAmount_BigDecimalRoundingMode() { + void test_withAmount_BigDecimalRoundingMode() { Money test = GBP_2_34.withAmount(BIGDEC_M5_78, RoundingMode.UNNECESSARY); assertEquals("GBP -5.78", test.toString()); } @Test - public void test_withAmount_BigDecimalRoundingMode_same() { + void test_withAmount_BigDecimalRoundingMode_same() { Money test = GBP_2_34.withAmount(BIGDEC_2_34, RoundingMode.UNNECESSARY); assertSame(GBP_2_34, test); } @Test - public void test_withAmount_BigDecimalRoundingMode_roundDown() { + void test_withAmount_BigDecimalRoundingMode_roundDown() { Money test = GBP_2_34.withAmount(new BigDecimal("2.355"), RoundingMode.DOWN); assertEquals(GBP_2_35, test); } - @Test(expected = ArithmeticException.class) - public void test_withAmount_BigDecimalRoundingMode_roundUnecessary() { - GBP_2_34.withAmount(new BigDecimal("2.345"), RoundingMode.UNNECESSARY); + @Test + void test_withAmount_BigDecimalRoundingMode_roundUnecessary() { + assertThrows(ArithmeticException.class, () -> { + GBP_2_34.withAmount(new BigDecimal("2.345"), RoundingMode.UNNECESSARY); + }); } - @Test(expected = NullPointerException.class) - public void test_withAmount_BigDecimalRoundingMode_nullBigDecimal() { - GBP_2_34.withAmount((BigDecimal) null, RoundingMode.UNNECESSARY); + @Test + void test_withAmount_BigDecimalRoundingMode_nullBigDecimal() { + assertThrows(NullPointerException.class, () -> { + GBP_2_34.withAmount((BigDecimal) null, RoundingMode.UNNECESSARY); + }); } - @Test(expected = NullPointerException.class) - public void test_withAmount_BigDecimalRoundingMode_nullRoundingMode() { - GBP_2_34.withAmount(BIGDEC_2_34, (RoundingMode) null); + @Test + void test_withAmount_BigDecimalRoundingMode_nullRoundingMode() { + assertThrows(NullPointerException.class, () -> { + GBP_2_34.withAmount(BIGDEC_2_34, (RoundingMode) null); + }); } //----------------------------------------------------------------------- // withAmount(double) //----------------------------------------------------------------------- @Test - public void test_withAmount_double() { + void test_withAmount_double() { Money test = GBP_2_34.withAmount(-5.78d); assertEquals("GBP -5.78", test.toString()); } @Test - public void test_withAmount_double_same() { + void test_withAmount_double_same() { Money test = GBP_2_34.withAmount(2.34d); assertSame(GBP_2_34, test); } - @Test(expected = ArithmeticException.class) - public void test_withAmount_double_invalidScale() { - GBP_2_34.withAmount(2.345d); + @Test + void test_withAmount_double_invalidScale() { + assertThrows(ArithmeticException.class, () -> { + GBP_2_34.withAmount(2.345d); + }); } //----------------------------------------------------------------------- // withAmount(double,RoundingMode) //----------------------------------------------------------------------- @Test - public void test_withAmount_doubleRoundingMode() { + void test_withAmount_doubleRoundingMode() { Money test = GBP_2_34.withAmount(-5.78d, RoundingMode.UNNECESSARY); assertEquals("GBP -5.78", test.toString()); } @Test - public void test_withAmount_doubleRoundingMode_same() { + void test_withAmount_doubleRoundingMode_same() { Money test = GBP_2_34.withAmount(2.34d, RoundingMode.UNNECESSARY); assertSame(GBP_2_34, test); } @Test - public void test_withAmount_doubleRoundingMode_roundDown() { + void test_withAmount_doubleRoundingMode_roundDown() { Money test = GBP_2_34.withAmount(2.355d, RoundingMode.DOWN); assertEquals(GBP_2_35, test); } - @Test(expected = ArithmeticException.class) - public void test_withAmount_doubleRoundingMode_roundUnecessary() { - GBP_2_34.withAmount(2.345d, RoundingMode.UNNECESSARY); + @Test + void test_withAmount_doubleRoundingMode_roundUnecessary() { + assertThrows(ArithmeticException.class, () -> { + GBP_2_34.withAmount(2.345d, RoundingMode.UNNECESSARY); + }); } - @Test(expected = NullPointerException.class) - public void test_withAmount_doubleRoundingMode_nullRoundingMode() { - GBP_2_34.withAmount(BIGDEC_2_34, (RoundingMode) null); + @Test + void test_withAmount_doubleRoundingMode_nullRoundingMode() { + assertThrows(NullPointerException.class, () -> { + GBP_2_34.withAmount(BIGDEC_2_34, (RoundingMode) null); + }); } //----------------------------------------------------------------------- // plus(Iterable) //----------------------------------------------------------------------- @Test - public void test_plus_Iterable() { + void test_plus_Iterable() { Iterable iterable = Arrays.asList(GBP_2_33, GBP_1_23); Money test = GBP_2_34.plus(iterable); assertEquals("GBP 5.90", test.toString()); } @Test - public void test_plus_Iterable_zero() { + void test_plus_Iterable_zero() { Iterable iterable = Arrays.asList(GBP_0_00); Money test = GBP_2_34.plus(iterable); assertSame(GBP_2_34, test); } - @Test(expected = CurrencyMismatchException.class) - public void test_plus_Iterable_currencyMismatch() { - try { - Iterable iterable = Arrays.asList(GBP_2_33, JPY_423); - GBP_M5_78.plus(iterable); - } catch (CurrencyMismatchException ex) { - assertEquals(GBP, ex.getFirstCurrency()); - assertEquals(JPY, ex.getSecondCurrency()); - throw ex; - } + @Test + void test_plus_Iterable_currencyMismatch() { + assertThrows(CurrencyMismatchException.class, () -> { + try { + Iterable iterable = Arrays.asList(GBP_2_33, JPY_423); + GBP_M5_78.plus(iterable); + } catch (CurrencyMismatchException ex) { + assertEquals(GBP, ex.getFirstCurrency()); + assertEquals(JPY, ex.getSecondCurrency()); + throw ex; + } + }); } - @Test(expected = NullPointerException.class) - public void test_plus_Iterable_nullEntry() { + @Test + void test_plus_Iterable_nullEntry() { Iterable iterable = Arrays.asList(GBP_2_33, null); - GBP_M5_78.plus(iterable); + assertThrows(NullPointerException.class, () -> { + GBP_M5_78.plus(iterable); + }); } - @Test(expected = NullPointerException.class) - public void test_plus_Iterable_nullIterable() { - GBP_M5_78.plus((Iterable) null); + @Test + void test_plus_Iterable_nullIterable() { + assertThrows(NullPointerException.class, () -> { + GBP_M5_78.plus((Iterable) null); + }); } //----------------------------------------------------------------------- // plus(Money) //----------------------------------------------------------------------- @Test - public void test_plus_Money_zero() { + void test_plus_Money_zero() { Money test = GBP_2_34.plus(GBP_0_00); assertSame(GBP_2_34, test); } @Test - public void test_plus_Money_positive() { + void test_plus_Money_positive() { Money test = GBP_2_34.plus(GBP_1_23); assertEquals("GBP 3.57", test.toString()); } @Test - public void test_plus_Money_negative() { + void test_plus_Money_negative() { Money test = GBP_2_34.plus(GBP_M1_23); assertEquals("GBP 1.11", test.toString()); } - @Test(expected = CurrencyMismatchException.class) - public void test_plus_Money_currencyMismatch() { - try { - GBP_M5_78.plus(USD_1_23); - } catch (CurrencyMismatchException ex) { - assertEquals(GBP, ex.getFirstCurrency()); - assertEquals(USD, ex.getSecondCurrency()); - throw ex; - } + @Test + void test_plus_Money_currencyMismatch() { + assertThrows(CurrencyMismatchException.class, () -> { + try { + GBP_M5_78.plus(USD_1_23); + } catch (CurrencyMismatchException ex) { + assertEquals(GBP, ex.getFirstCurrency()); + assertEquals(USD, ex.getSecondCurrency()); + throw ex; + } + }); } - @Test(expected = NullPointerException.class) - public void test_plus_Money_nullMoney() { - GBP_M5_78.plus((Money) null); + @Test + void test_plus_Money_nullMoney() { + assertThrows(NullPointerException.class, () -> { + GBP_M5_78.plus((Money) null); + }); } //----------------------------------------------------------------------- // plus(BigDecimal) //----------------------------------------------------------------------- @Test - public void test_plus_BigDecimal_zero() { + void test_plus_BigDecimal_zero() { Money test = GBP_2_34.plus(BigDecimal.ZERO); assertSame(GBP_2_34, test); } @Test - public void test_plus_BigDecimal_positive() { + void test_plus_BigDecimal_positive() { Money test = GBP_2_34.plus(new BigDecimal("1.23")); assertEquals("GBP 3.57", test.toString()); } @Test - public void test_plus_BigDecimal_negative() { + void test_plus_BigDecimal_negative() { Money test = GBP_2_34.plus(new BigDecimal("-1.23")); assertEquals("GBP 1.11", test.toString()); } - @Test(expected = ArithmeticException.class) - public void test_plus_BigDecimal_invalidScale() { - GBP_2_34.plus(new BigDecimal("1.235")); + @Test + void test_plus_BigDecimal_invalidScale() { + assertThrows(ArithmeticException.class, () -> { + GBP_2_34.plus(new BigDecimal("1.235")); + }); } - @Test(expected = NullPointerException.class) - public void test_plus_BigDecimal_nullBigDecimal() { - GBP_M5_78.plus((BigDecimal) null); + @Test + void test_plus_BigDecimal_nullBigDecimal() { + assertThrows(NullPointerException.class, () -> { + GBP_M5_78.plus((BigDecimal) null); + }); } //----------------------------------------------------------------------- // plus(BigDecimal,RoundingMode) //----------------------------------------------------------------------- @Test - public void test_plus_BigDecimalRoundingMode_zero() { + void test_plus_BigDecimalRoundingMode_zero() { Money test = GBP_2_34.plus(BigDecimal.ZERO, RoundingMode.UNNECESSARY); assertSame(GBP_2_34, test); } @Test - public void test_plus_BigDecimalRoundingMode_positive() { + void test_plus_BigDecimalRoundingMode_positive() { Money test = GBP_2_34.plus(new BigDecimal("1.23"), RoundingMode.UNNECESSARY); assertEquals("GBP 3.57", test.toString()); } @Test - public void test_plus_BigDecimalRoundingMode_negative() { + void test_plus_BigDecimalRoundingMode_negative() { Money test = GBP_2_34.plus(new BigDecimal("-1.23"), RoundingMode.UNNECESSARY); assertEquals("GBP 1.11", test.toString()); } @Test - public void test_plus_BigDecimalRoundingMode_roundDown() { + void test_plus_BigDecimalRoundingMode_roundDown() { Money test = GBP_2_34.plus(new BigDecimal("1.235"), RoundingMode.DOWN); assertEquals("GBP 3.57", test.toString()); } - @Test(expected = ArithmeticException.class) - public void test_plus_BigDecimalRoundingMode_roundUnecessary() { - GBP_2_34.plus(new BigDecimal("1.235"), RoundingMode.UNNECESSARY); + @Test + void test_plus_BigDecimalRoundingMode_roundUnecessary() { + assertThrows(ArithmeticException.class, () -> { + GBP_2_34.plus(new BigDecimal("1.235"), RoundingMode.UNNECESSARY); + }); } - @Test(expected = NullPointerException.class) - public void test_plus_BigDecimalRoundingMode_nullBigDecimal() { - GBP_M5_78.plus((BigDecimal) null, RoundingMode.UNNECESSARY); + @Test + void test_plus_BigDecimalRoundingMode_nullBigDecimal() { + assertThrows(NullPointerException.class, () -> { + GBP_M5_78.plus((BigDecimal) null, RoundingMode.UNNECESSARY); + }); } - @Test(expected = NullPointerException.class) - public void test_plus_BigDecimalRoundingMode_nullRoundingMode() { - GBP_M5_78.plus(BIGDEC_2_34, (RoundingMode) null); + @Test + void test_plus_BigDecimalRoundingMode_nullRoundingMode() { + assertThrows(NullPointerException.class, () -> { + GBP_M5_78.plus(BIGDEC_2_34, (RoundingMode) null); + }); } //----------------------------------------------------------------------- // plus(double) //----------------------------------------------------------------------- @Test - public void test_plus_double_zero() { + void test_plus_double_zero() { Money test = GBP_2_34.plus(0d); assertSame(GBP_2_34, test); } @Test - public void test_plus_double_positive() { + void test_plus_double_positive() { Money test = GBP_2_34.plus(1.23d); assertEquals("GBP 3.57", test.toString()); } @Test - public void test_plus_double_negative() { + void test_plus_double_negative() { Money test = GBP_2_34.plus(-1.23d); assertEquals("GBP 1.11", test.toString()); } - @Test(expected = ArithmeticException.class) - public void test_plus_double_invalidScale() { - GBP_2_34.plus(1.235d); + @Test + void test_plus_double_invalidScale() { + assertThrows(ArithmeticException.class, () -> { + GBP_2_34.plus(1.235d); + }); } //----------------------------------------------------------------------- // plus(double,RoundingMode) //----------------------------------------------------------------------- @Test - public void test_plus_doubleRoundingMode_zero() { + void test_plus_doubleRoundingMode_zero() { Money test = GBP_2_34.plus(0d, RoundingMode.UNNECESSARY); assertSame(GBP_2_34, test); } @Test - public void test_plus_doubleRoundingMode_positive() { + void test_plus_doubleRoundingMode_positive() { Money test = GBP_2_34.plus(1.23d, RoundingMode.UNNECESSARY); assertEquals("GBP 3.57", test.toString()); } @Test - public void test_plus_doubleRoundingMode_negative() { + void test_plus_doubleRoundingMode_negative() { Money test = GBP_2_34.plus(-1.23d, RoundingMode.UNNECESSARY); assertEquals("GBP 1.11", test.toString()); } @Test - public void test_plus_doubleRoundingMode_roundDown() { + void test_plus_doubleRoundingMode_roundDown() { Money test = GBP_2_34.plus(1.235d, RoundingMode.DOWN); assertEquals("GBP 3.57", test.toString()); } - @Test(expected = ArithmeticException.class) - public void test_plus_doubleRoundingMode_roundUnecessary() { - GBP_2_34.plus(1.235d, RoundingMode.UNNECESSARY); + @Test + void test_plus_doubleRoundingMode_roundUnecessary() { + assertThrows(ArithmeticException.class, () -> { + GBP_2_34.plus(1.235d, RoundingMode.UNNECESSARY); + }); } - @Test(expected = NullPointerException.class) - public void test_plus_doubleRoundingMode_nullRoundingMode() { - GBP_M5_78.plus(2.34d, (RoundingMode) null); + @Test + void test_plus_doubleRoundingMode_nullRoundingMode() { + assertThrows(NullPointerException.class, () -> { + GBP_M5_78.plus(2.34d, (RoundingMode) null); + }); } //----------------------------------------------------------------------- // plusMajor(long) //----------------------------------------------------------------------- @Test - public void test_plusMajor_zero() { + void test_plusMajor_zero() { Money test = GBP_2_34.plusMajor(0); assertSame(GBP_2_34, test); } @Test - public void test_plusMajor_positive() { + void test_plusMajor_positive() { Money test = GBP_2_34.plusMajor(123); assertEquals("GBP 125.34", test.toString()); } @Test - public void test_plusMajor_negative() { + void test_plusMajor_negative() { Money test = GBP_2_34.plusMajor(-123); assertEquals("GBP -120.66", test.toString()); } @@ -1420,19 +1585,19 @@ public void test_plusMajor_negative() { // plusMinor(long) //----------------------------------------------------------------------- @Test - public void test_plusMinor_zero() { + void test_plusMinor_zero() { Money test = GBP_2_34.plusMinor(0); assertSame(GBP_2_34, test); } @Test - public void test_plusMinor_positive() { + void test_plusMinor_positive() { Money test = GBP_2_34.plusMinor(123); assertEquals("GBP 3.57", test.toString()); } @Test - public void test_plusMinor_negative() { + void test_plusMinor_negative() { Money test = GBP_2_34.plusMinor(-123); assertEquals("GBP 1.11", test.toString()); } @@ -1441,232 +1606,258 @@ public void test_plusMinor_negative() { // minus(Iterable) //----------------------------------------------------------------------- @Test - public void test_minus_Iterable() { + void test_minus_Iterable() { Iterable iterable = Arrays.asList(GBP_2_33, GBP_1_23); Money test = GBP_2_34.minus(iterable); assertEquals("GBP -1.22", test.toString()); } @Test - public void test_minus_Iterable_zero() { + void test_minus_Iterable_zero() { Iterable iterable = Arrays.asList(GBP_0_00); Money test = GBP_2_34.minus(iterable); assertSame(GBP_2_34, test); } - @Test(expected = CurrencyMismatchException.class) - public void test_minus_Iterable_currencyMismatch() { - try { - Iterable iterable = Arrays.asList(GBP_2_33, JPY_423); - GBP_M5_78.minus(iterable); - } catch (CurrencyMismatchException ex) { - assertEquals(GBP, ex.getFirstCurrency()); - assertEquals(JPY, ex.getSecondCurrency()); - throw ex; - } + @Test + void test_minus_Iterable_currencyMismatch() { + assertThrows(CurrencyMismatchException.class, () -> { + try { + Iterable iterable = Arrays.asList(GBP_2_33, JPY_423); + GBP_M5_78.minus(iterable); + } catch (CurrencyMismatchException ex) { + assertEquals(GBP, ex.getFirstCurrency()); + assertEquals(JPY, ex.getSecondCurrency()); + throw ex; + } + }); } - @Test(expected = NullPointerException.class) - public void test_minus_Iterable_nullEntry() { + @Test + void test_minus_Iterable_nullEntry() { Iterable iterable = Arrays.asList(GBP_2_33, null); - GBP_M5_78.minus(iterable); + assertThrows(NullPointerException.class, () -> { + GBP_M5_78.minus(iterable); + }); } - @Test(expected = NullPointerException.class) - public void test_minus_Iterable_nullIterable() { - GBP_M5_78.minus((Iterable) null); + @Test + void test_minus_Iterable_nullIterable() { + assertThrows(NullPointerException.class, () -> { + GBP_M5_78.minus((Iterable) null); + }); } //----------------------------------------------------------------------- // minus(Money) //----------------------------------------------------------------------- @Test - public void test_minus_Money_zero() { + void test_minus_Money_zero() { Money test = GBP_2_34.minus(GBP_0_00); assertSame(GBP_2_34, test); } @Test - public void test_minus_Money_positive() { + void test_minus_Money_positive() { Money test = GBP_2_34.minus(GBP_1_23); assertEquals("GBP 1.11", test.toString()); } @Test - public void test_minus_Money_negative() { + void test_minus_Money_negative() { Money test = GBP_2_34.minus(GBP_M1_23); assertEquals("GBP 3.57", test.toString()); } - @Test(expected = CurrencyMismatchException.class) - public void test_minus_Money_currencyMismatch() { - try { - GBP_M5_78.minus(USD_1_23); - } catch (CurrencyMismatchException ex) { - assertEquals(GBP, ex.getFirstCurrency()); - assertEquals(USD, ex.getSecondCurrency()); - throw ex; - } + @Test + void test_minus_Money_currencyMismatch() { + assertThrows(CurrencyMismatchException.class, () -> { + try { + GBP_M5_78.minus(USD_1_23); + } catch (CurrencyMismatchException ex) { + assertEquals(GBP, ex.getFirstCurrency()); + assertEquals(USD, ex.getSecondCurrency()); + throw ex; + } + }); } - @Test(expected = NullPointerException.class) - public void test_minus_Money_nullMoney() { - GBP_M5_78.minus((Money) null); + @Test + void test_minus_Money_nullMoney() { + assertThrows(NullPointerException.class, () -> { + GBP_M5_78.minus((Money) null); + }); } //----------------------------------------------------------------------- // minus(BigDecimal) //----------------------------------------------------------------------- @Test - public void test_minus_BigDecimal_zero() { + void test_minus_BigDecimal_zero() { Money test = GBP_2_34.minus(BigDecimal.ZERO); assertSame(GBP_2_34, test); } @Test - public void test_minus_BigDecimal_positive() { + void test_minus_BigDecimal_positive() { Money test = GBP_2_34.minus(new BigDecimal("1.23")); assertEquals("GBP 1.11", test.toString()); } @Test - public void test_minus_BigDecimal_negative() { + void test_minus_BigDecimal_negative() { Money test = GBP_2_34.minus(new BigDecimal("-1.23")); assertEquals("GBP 3.57", test.toString()); } - @Test(expected = ArithmeticException.class) - public void test_minus_BigDecimal_invalidScale() { - GBP_2_34.minus(new BigDecimal("1.235")); + @Test + void test_minus_BigDecimal_invalidScale() { + assertThrows(ArithmeticException.class, () -> { + GBP_2_34.minus(new BigDecimal("1.235")); + }); } - @Test(expected = NullPointerException.class) - public void test_minus_BigDecimal_nullBigDecimal() { - GBP_M5_78.minus((BigDecimal) null); + @Test + void test_minus_BigDecimal_nullBigDecimal() { + assertThrows(NullPointerException.class, () -> { + GBP_M5_78.minus((BigDecimal) null); + }); } //----------------------------------------------------------------------- // minus(BigDecimal,RoundingMode) //----------------------------------------------------------------------- @Test - public void test_minus_BigDecimalRoundingMode_zero() { + void test_minus_BigDecimalRoundingMode_zero() { Money test = GBP_2_34.minus(BigDecimal.ZERO, RoundingMode.UNNECESSARY); assertSame(GBP_2_34, test); } @Test - public void test_minus_BigDecimalRoundingMode_positive() { + void test_minus_BigDecimalRoundingMode_positive() { Money test = GBP_2_34.minus(new BigDecimal("1.23"), RoundingMode.UNNECESSARY); assertEquals("GBP 1.11", test.toString()); } @Test - public void test_minus_BigDecimalRoundingMode_negative() { + void test_minus_BigDecimalRoundingMode_negative() { Money test = GBP_2_34.minus(new BigDecimal("-1.23"), RoundingMode.UNNECESSARY); assertEquals("GBP 3.57", test.toString()); } @Test - public void test_minus_BigDecimalRoundingMode_roundDown() { + void test_minus_BigDecimalRoundingMode_roundDown() { Money test = GBP_2_34.minus(new BigDecimal("1.235"), RoundingMode.DOWN); assertEquals("GBP 1.10", test.toString()); } - @Test(expected = ArithmeticException.class) - public void test_minus_BigDecimalRoundingMode_roundUnecessary() { - GBP_2_34.minus(new BigDecimal("1.235"), RoundingMode.UNNECESSARY); + @Test + void test_minus_BigDecimalRoundingMode_roundUnecessary() { + assertThrows(ArithmeticException.class, () -> { + GBP_2_34.minus(new BigDecimal("1.235"), RoundingMode.UNNECESSARY); + }); } - @Test(expected = NullPointerException.class) - public void test_minus_BigDecimalRoundingMode_nullBigDecimal() { - GBP_M5_78.minus((BigDecimal) null, RoundingMode.UNNECESSARY); + @Test + void test_minus_BigDecimalRoundingMode_nullBigDecimal() { + assertThrows(NullPointerException.class, () -> { + GBP_M5_78.minus((BigDecimal) null, RoundingMode.UNNECESSARY); + }); } - @Test(expected = NullPointerException.class) - public void test_minus_BigDecimalRoundingMode_nullRoundingMode() { - GBP_M5_78.minus(BIGDEC_2_34, (RoundingMode) null); + @Test + void test_minus_BigDecimalRoundingMode_nullRoundingMode() { + assertThrows(NullPointerException.class, () -> { + GBP_M5_78.minus(BIGDEC_2_34, (RoundingMode) null); + }); } //----------------------------------------------------------------------- // minus(double) //----------------------------------------------------------------------- @Test - public void test_minus_double_zero() { + void test_minus_double_zero() { Money test = GBP_2_34.minus(0d); assertSame(GBP_2_34, test); } @Test - public void test_minus_double_positive() { + void test_minus_double_positive() { Money test = GBP_2_34.minus(1.23d); assertEquals("GBP 1.11", test.toString()); } @Test - public void test_minus_double_negative() { + void test_minus_double_negative() { Money test = GBP_2_34.minus(-1.23d); assertEquals("GBP 3.57", test.toString()); } - @Test(expected = ArithmeticException.class) - public void test_minus_double_invalidScale() { - GBP_2_34.minus(1.235d); + @Test + void test_minus_double_invalidScale() { + assertThrows(ArithmeticException.class, () -> { + GBP_2_34.minus(1.235d); + }); } //----------------------------------------------------------------------- // minus(double,RoundingMode) //----------------------------------------------------------------------- @Test - public void test_minus_doubleRoundingMode_zero() { + void test_minus_doubleRoundingMode_zero() { Money test = GBP_2_34.minus(0d, RoundingMode.UNNECESSARY); assertSame(GBP_2_34, test); } @Test - public void test_minus_doubleRoundingMode_positive() { + void test_minus_doubleRoundingMode_positive() { Money test = GBP_2_34.minus(1.23d, RoundingMode.UNNECESSARY); assertEquals("GBP 1.11", test.toString()); } @Test - public void test_minus_doubleRoundingMode_negative() { + void test_minus_doubleRoundingMode_negative() { Money test = GBP_2_34.minus(-1.23d, RoundingMode.UNNECESSARY); assertEquals("GBP 3.57", test.toString()); } @Test - public void test_minus_doubleRoundingMode_roundDown() { + void test_minus_doubleRoundingMode_roundDown() { Money test = GBP_2_34.minus(1.235d, RoundingMode.DOWN); assertEquals("GBP 1.10", test.toString()); } - @Test(expected = ArithmeticException.class) - public void test_minus_doubleRoundingMode_roundUnecessary() { - GBP_2_34.minus(1.235d, RoundingMode.UNNECESSARY); + @Test + void test_minus_doubleRoundingMode_roundUnecessary() { + assertThrows(ArithmeticException.class, () -> { + GBP_2_34.minus(1.235d, RoundingMode.UNNECESSARY); + }); } - @Test(expected = NullPointerException.class) - public void test_minus_doubleRoundingMode_nullRoundingMode() { - GBP_M5_78.minus(2.34d, (RoundingMode) null); + @Test + void test_minus_doubleRoundingMode_nullRoundingMode() { + assertThrows(NullPointerException.class, () -> { + GBP_M5_78.minus(2.34d, (RoundingMode) null); + }); } //----------------------------------------------------------------------- // minusMajor(long) //----------------------------------------------------------------------- @Test - public void test_minusMajor_zero() { + void test_minusMajor_zero() { Money test = GBP_2_34.minusMajor(0); assertSame(GBP_2_34, test); } @Test - public void test_minusMajor_positive() { + void test_minusMajor_positive() { Money test = GBP_2_34.minusMajor(123); assertEquals("GBP -120.66", test.toString()); } @Test - public void test_minusMajor_negative() { + void test_minusMajor_negative() { Money test = GBP_2_34.minusMajor(-123); assertEquals("GBP 125.34", test.toString()); } @@ -1675,19 +1866,19 @@ public void test_minusMajor_negative() { // minusMinor(long) //----------------------------------------------------------------------- @Test - public void test_minusMinor_zero() { + void test_minusMinor_zero() { Money test = GBP_2_34.minusMinor(0); assertSame(GBP_2_34, test); } @Test - public void test_minusMinor_positive() { + void test_minusMinor_positive() { Money test = GBP_2_34.minusMinor(123); assertEquals("GBP 1.11", test.toString()); } @Test - public void test_minusMinor_negative() { + void test_minusMinor_negative() { Money test = GBP_2_34.minusMinor(-123); assertEquals("GBP 3.57", test.toString()); } @@ -1696,88 +1887,94 @@ public void test_minusMinor_negative() { // multipliedBy(BigDecimal,RoundingMode) //----------------------------------------------------------------------- @Test - public void test_multipliedBy_BigDecimalRoundingMode_one() { + void test_multipliedBy_BigDecimalRoundingMode_one() { Money test = GBP_2_34.multipliedBy(BigDecimal.ONE, RoundingMode.DOWN); assertSame(GBP_2_34, test); } @Test - public void test_multipliedBy_BigDecimalRoundingMode_positive() { + void test_multipliedBy_BigDecimalRoundingMode_positive() { Money test = GBP_2_33.multipliedBy(new BigDecimal("2.5"), RoundingMode.DOWN); assertEquals("GBP 5.82", test.toString()); } @Test - public void test_multipliedBy_BigDecimalRoundingMode_positive_halfUp() { + void test_multipliedBy_BigDecimalRoundingMode_positive_halfUp() { Money test = GBP_2_33.multipliedBy(new BigDecimal("2.5"), RoundingMode.HALF_UP); assertEquals("GBP 5.83", test.toString()); } @Test - public void test_multipliedBy_BigDecimalRoundingMode_negative() { + void test_multipliedBy_BigDecimalRoundingMode_negative() { Money test = GBP_2_33.multipliedBy(new BigDecimal("-2.5"), RoundingMode.FLOOR); assertEquals("GBP -5.83", test.toString()); } - @Test(expected = NullPointerException.class) - public void test_multipliedBy_BigDecimalRoundingMode_nullBigDecimal() { - GBP_5_78.multipliedBy((BigDecimal) null, RoundingMode.DOWN); + @Test + void test_multipliedBy_BigDecimalRoundingMode_nullBigDecimal() { + assertThrows(NullPointerException.class, () -> { + GBP_5_78.multipliedBy((BigDecimal) null, RoundingMode.DOWN); + }); } - @Test(expected = NullPointerException.class) - public void test_multipliedBy_BigDecimalRoundingMode_nullRoundingMode() { - GBP_5_78.multipliedBy(new BigDecimal("2.5"), (RoundingMode) null); + @Test + void test_multipliedBy_BigDecimalRoundingMode_nullRoundingMode() { + assertThrows(NullPointerException.class, () -> { + GBP_5_78.multipliedBy(new BigDecimal("2.5"), (RoundingMode) null); + }); } //----------------------------------------------------------------------- // multipliedBy(double,RoundingMode) //----------------------------------------------------------------------- @Test - public void test_multipliedBy_doubleRoundingMode_one() { + void test_multipliedBy_doubleRoundingMode_one() { Money test = GBP_2_34.multipliedBy(1d, RoundingMode.DOWN); assertSame(GBP_2_34, test); } @Test - public void test_multipliedBy_doubleRoundingMode_positive() { + void test_multipliedBy_doubleRoundingMode_positive() { Money test = GBP_2_33.multipliedBy(2.5d, RoundingMode.DOWN); assertEquals("GBP 5.82", test.toString()); } @Test - public void test_multipliedBy_doubleRoundingMode_positive_halfUp() { + void test_multipliedBy_doubleRoundingMode_positive_halfUp() { Money test = GBP_2_33.multipliedBy(2.5d, RoundingMode.HALF_UP); assertEquals("GBP 5.83", test.toString()); } @Test - public void test_multipliedBy_doubleRoundingMode_negative() { + void test_multipliedBy_doubleRoundingMode_negative() { Money test = GBP_2_33.multipliedBy(-2.5d, RoundingMode.FLOOR); assertEquals("GBP -5.83", test.toString()); } - @Test(expected = NullPointerException.class) - public void test_multipliedBy_doubleRoundingMode_nullRoundingMode() { - GBP_5_78.multipliedBy(2.5d, (RoundingMode) null); + @Test + void test_multipliedBy_doubleRoundingMode_nullRoundingMode() { + assertThrows(NullPointerException.class, () -> { + GBP_5_78.multipliedBy(2.5d, (RoundingMode) null); + }); } //----------------------------------------------------------------------- // multipliedBy(long) //----------------------------------------------------------------------- @Test - public void test_multipliedBy_long_one() { + void test_multipliedBy_long_one() { Money test = GBP_2_34.multipliedBy(1); assertSame(GBP_2_34, test); } @Test - public void test_multipliedBy_long_positive() { + void test_multipliedBy_long_positive() { Money test = GBP_2_34.multipliedBy(3); assertEquals("GBP 7.02", test.toString()); } @Test - public void test_multipliedBy_long_negative() { + void test_multipliedBy_long_negative() { Money test = GBP_2_34.multipliedBy(-3); assertEquals("GBP -7.02", test.toString()); } @@ -1786,100 +1983,106 @@ public void test_multipliedBy_long_negative() { // dividedBy(BigDecimal,RoundingMode) //----------------------------------------------------------------------- @Test - public void test_dividedBy_BigDecimalRoundingMode_one() { + void test_dividedBy_BigDecimalRoundingMode_one() { Money test = GBP_2_34.dividedBy(BigDecimal.ONE, RoundingMode.DOWN); assertSame(GBP_2_34, test); } @Test - public void test_dividedBy_BigDecimalRoundingMode_positive() { + void test_dividedBy_BigDecimalRoundingMode_positive() { Money test = GBP_2_34.dividedBy(new BigDecimal("2.5"), RoundingMode.DOWN); assertEquals("GBP 0.93", test.toString()); } @Test - public void test_dividedBy_BigDecimalRoundingMode_positive_halfUp() { + void test_dividedBy_BigDecimalRoundingMode_positive_halfUp() { Money test = GBP_2_34.dividedBy(new BigDecimal("2.5"), RoundingMode.HALF_UP); assertEquals("GBP 0.94", test.toString()); } @Test - public void test_dividedBy_BigDecimalRoundingMode_negative() { + void test_dividedBy_BigDecimalRoundingMode_negative() { Money test = GBP_2_34.dividedBy(new BigDecimal("-2.5"), RoundingMode.FLOOR); assertEquals("GBP -0.94", test.toString()); } - @Test(expected = NullPointerException.class) - public void test_dividedBy_BigDecimalRoundingMode_nullBigDecimal() { - GBP_5_78.dividedBy((BigDecimal) null, RoundingMode.DOWN); + @Test + void test_dividedBy_BigDecimalRoundingMode_nullBigDecimal() { + assertThrows(NullPointerException.class, () -> { + GBP_5_78.dividedBy((BigDecimal) null, RoundingMode.DOWN); + }); } - @Test(expected = NullPointerException.class) - public void test_dividedBy_BigDecimalRoundingMode_nullRoundingMode() { - GBP_5_78.dividedBy(new BigDecimal("2.5"), (RoundingMode) null); + @Test + void test_dividedBy_BigDecimalRoundingMode_nullRoundingMode() { + assertThrows(NullPointerException.class, () -> { + GBP_5_78.dividedBy(new BigDecimal("2.5"), (RoundingMode) null); + }); } //----------------------------------------------------------------------- // dividedBy(double,RoundingMode) //----------------------------------------------------------------------- @Test - public void test_dividedBy_doubleRoundingMode_one() { + void test_dividedBy_doubleRoundingMode_one() { Money test = GBP_2_34.dividedBy(1d, RoundingMode.DOWN); assertSame(GBP_2_34, test); } @Test - public void test_dividedBy_doubleRoundingMode_positive() { + void test_dividedBy_doubleRoundingMode_positive() { Money test = GBP_2_34.dividedBy(2.5d, RoundingMode.DOWN); assertEquals("GBP 0.93", test.toString()); } @Test - public void test_dividedBy_doubleRoundingMode_positive_halfUp() { + void test_dividedBy_doubleRoundingMode_positive_halfUp() { Money test = GBP_2_34.dividedBy(2.5d, RoundingMode.HALF_UP); assertEquals("GBP 0.94", test.toString()); } @Test - public void test_dividedBy_doubleRoundingMode_negative() { + void test_dividedBy_doubleRoundingMode_negative() { Money test = GBP_2_34.dividedBy(-2.5d, RoundingMode.FLOOR); assertEquals("GBP -0.94", test.toString()); } - @Test(expected = NullPointerException.class) - public void test_dividedBy_doubleRoundingMode_nullRoundingMode() { - GBP_5_78.dividedBy(2.5d, (RoundingMode) null); + @Test + void test_dividedBy_doubleRoundingMode_nullRoundingMode() { + assertThrows(NullPointerException.class, () -> { + GBP_5_78.dividedBy(2.5d, (RoundingMode) null); + }); } //----------------------------------------------------------------------- // dividedBy(long,RoundingMode) //----------------------------------------------------------------------- @Test - public void test_dividedBy_long_one() { + void test_dividedBy_long_one() { Money test = GBP_2_34.dividedBy(1, RoundingMode.DOWN); assertSame(GBP_2_34, test); } @Test - public void test_dividedBy_long_positive() { + void test_dividedBy_long_positive() { Money test = GBP_2_34.dividedBy(3, RoundingMode.DOWN); assertEquals("GBP 0.78", test.toString()); } @Test - public void test_dividedBy_long_positive_roundDown() { + void test_dividedBy_long_positive_roundDown() { Money test = GBP_2_35.dividedBy(3, RoundingMode.DOWN); assertEquals("GBP 0.78", test.toString()); } @Test - public void test_dividedBy_long_positive_roundUp() { + void test_dividedBy_long_positive_roundUp() { Money test = GBP_2_35.dividedBy(3, RoundingMode.UP); assertEquals("GBP 0.79", test.toString()); } @Test - public void test_dividedBy_long_negative() { + void test_dividedBy_long_negative() { Money test = GBP_2_34.dividedBy(-3, RoundingMode.DOWN); assertEquals("GBP -0.78", test.toString()); } @@ -1888,13 +2091,13 @@ public void test_dividedBy_long_negative() { // negated() //----------------------------------------------------------------------- @Test - public void test_negated_positive() { + void test_negated_positive() { Money test = GBP_2_34.negated(); assertEquals("GBP -2.34", test.toString()); } @Test - public void test_negated_negative() { + void test_negated_negative() { Money test = Money.parse("GBP -2.34").negated(); assertEquals("GBP 2.34", test.toString()); } @@ -1903,13 +2106,13 @@ public void test_negated_negative() { // abs() //----------------------------------------------------------------------- @Test - public void test_abs_positive() { + void test_abs_positive() { Money test = GBP_2_34.abs(); assertSame(GBP_2_34, test); } @Test - public void test_abs_negative() { + void test_abs_negative() { Money test = Money.parse("GBP -2.34").abs(); assertEquals("GBP 2.34", test.toString()); } @@ -1918,55 +2121,55 @@ public void test_abs_negative() { // rounded() //----------------------------------------------------------------------- @Test - public void test_round_2down() { + void test_round_2down() { Money test = GBP_2_34.rounded(2, RoundingMode.DOWN); assertSame(GBP_2_34, test); } @Test - public void test_round_2up() { + void test_round_2up() { Money test = GBP_2_34.rounded(2, RoundingMode.DOWN); assertSame(GBP_2_34, test); } @Test - public void test_round_1down() { + void test_round_1down() { Money test = GBP_2_34.rounded(1, RoundingMode.DOWN); assertEquals("GBP 2.30", test.toString()); } @Test - public void test_round_1up() { + void test_round_1up() { Money test = GBP_2_34.rounded(1, RoundingMode.UP); assertEquals("GBP 2.40", test.toString()); } @Test - public void test_round_0down() { + void test_round_0down() { Money test = GBP_2_34.rounded(0, RoundingMode.DOWN); assertEquals("GBP 2.00", test.toString()); } @Test - public void test_round_0up() { + void test_round_0up() { Money test = GBP_2_34.rounded(0, RoundingMode.UP); assertEquals("GBP 3.00", test.toString()); } @Test - public void test_round_M1down() { + void test_round_M1down() { Money test = Money.parse("GBP 432.34").rounded(-1, RoundingMode.DOWN); assertEquals("GBP 430.00", test.toString()); } @Test - public void test_round_M1up() { + void test_round_M1up() { Money test = Money.parse("GBP 432.34").rounded(-1, RoundingMode.UP); assertEquals("GBP 440.00", test.toString()); } @Test - public void test_round_3() { + void test_round_3() { Money test = GBP_2_34.rounded(3, RoundingMode.DOWN); assertSame(GBP_2_34, test); } @@ -1975,47 +2178,57 @@ public void test_round_3() { // convertedTo(BigDecimal,RoundingMode) //----------------------------------------------------------------------- @Test - public void test_convertedTo_BigDecimalRoundingMode_positive() { + void test_convertedTo_BigDecimalRoundingMode_positive() { Money test = GBP_2_33.convertedTo(EUR, new BigDecimal("2.5"), RoundingMode.DOWN); assertEquals("EUR 5.82", test.toString()); } @Test - public void test_convertedTo_BigDecimalRoundingMode_positive_halfUp() { + void test_convertedTo_BigDecimalRoundingMode_positive_halfUp() { Money test = GBP_2_33.convertedTo(EUR, new BigDecimal("2.5"), RoundingMode.HALF_UP); assertEquals("EUR 5.83", test.toString()); } - @Test(expected = IllegalArgumentException.class) - public void test_convertedTo_BigDecimalRoundingMode_negative() { - GBP_2_33.convertedTo(EUR, new BigDecimal("-2.5"), RoundingMode.FLOOR); + @Test + void test_convertedTo_BigDecimalRoundingMode_negative() { + assertThrows(IllegalArgumentException.class, () -> { + GBP_2_33.convertedTo(EUR, new BigDecimal("-2.5"), RoundingMode.FLOOR); + }); } - @Test(expected = IllegalArgumentException.class) - public void test_convertedTo_BigDecimalRoundingMode_sameCurrency() { - GBP_2_33.convertedTo(GBP, new BigDecimal("2.5"), RoundingMode.DOWN); + @Test + void test_convertedTo_BigDecimalRoundingMode_sameCurrency() { + assertThrows(IllegalArgumentException.class, () -> { + GBP_2_33.convertedTo(GBP, new BigDecimal("2.5"), RoundingMode.DOWN); + }); } - @Test(expected = NullPointerException.class) - public void test_convertedTo_BigDecimalRoundingMode_nullCurrency() { - GBP_5_78.convertedTo((CurrencyUnit) null, new BigDecimal("2"), RoundingMode.DOWN); + @Test + void test_convertedTo_BigDecimalRoundingMode_nullCurrency() { + assertThrows(NullPointerException.class, () -> { + GBP_5_78.convertedTo((CurrencyUnit) null, new BigDecimal("2"), RoundingMode.DOWN); + }); } - @Test(expected = NullPointerException.class) - public void test_convertedTo_BigDecimalRoundingMode_nullBigDecimal() { - GBP_5_78.convertedTo(EUR, (BigDecimal) null, RoundingMode.DOWN); + @Test + void test_convertedTo_BigDecimalRoundingMode_nullBigDecimal() { + assertThrows(NullPointerException.class, () -> { + GBP_5_78.convertedTo(EUR, (BigDecimal) null, RoundingMode.DOWN); + }); } - @Test(expected = NullPointerException.class) - public void test_convertedTo_BigDecimalRoundingMode_nullRoundingMode() { - GBP_5_78.convertedTo(EUR, new BigDecimal("2.5"), (RoundingMode) null); + @Test + void test_convertedTo_BigDecimalRoundingMode_nullRoundingMode() { + assertThrows(NullPointerException.class, () -> { + GBP_5_78.convertedTo(EUR, new BigDecimal("2.5"), (RoundingMode) null); + }); } //----------------------------------------------------------------------- // toMoney() //----------------------------------------------------------------------- @Test - public void test_toBigMoney() { + void test_toBigMoney() { assertEquals(BigMoney.ofMinor(GBP, 234), GBP_2_34.toBigMoney()); } @@ -2023,35 +2236,37 @@ public void test_toBigMoney() { // isSameCurrency(Money) //----------------------------------------------------------------------- @Test - public void test_isSameCurrency_Money_same() { - assertEquals(true, GBP_2_34.isSameCurrency(GBP_2_35)); + void test_isSameCurrency_Money_same() { + assertTrue(GBP_2_34.isSameCurrency(GBP_2_35)); } @Test - public void test_isSameCurrency_Money_different() { - assertEquals(false, GBP_2_34.isSameCurrency(USD_2_34)); + void test_isSameCurrency_Money_different() { + assertFalse(GBP_2_34.isSameCurrency(USD_2_34)); } @Test - public void test_isSameCurrency_BigMoney_same() { - assertEquals(true, GBP_2_34.isSameCurrency(BigMoney.parse("GBP 2"))); + void test_isSameCurrency_BigMoney_same() { + assertTrue(GBP_2_34.isSameCurrency(BigMoney.parse("GBP 2"))); } @Test - public void test_isSameCurrency_BigMoney_different() { - assertEquals(false, GBP_2_34.isSameCurrency(BigMoney.parse("USD 2"))); + void test_isSameCurrency_BigMoney_different() { + assertFalse(GBP_2_34.isSameCurrency(BigMoney.parse("USD 2"))); } - @Test(expected = NullPointerException.class) - public void test_isSameCurrency_Money_nullMoney() { - GBP_2_34.isSameCurrency((Money) null); + @Test + void test_isSameCurrency_Money_nullMoney() { + assertThrows(NullPointerException.class, () -> { + GBP_2_34.isSameCurrency((Money) null); + }); } //----------------------------------------------------------------------- // compareTo() //----------------------------------------------------------------------- @Test - public void test_compareTo_Money() { + void test_compareTo_Money() { Money a = GBP_2_34; Money b = GBP_2_35; Money c = GBP_2_36; @@ -2070,7 +2285,7 @@ public void test_compareTo_Money() { } @Test - public void test_compareTo_BigMoney() { + void test_compareTo_BigMoney() { Money t = GBP_2_35; BigMoney a = BigMoney.ofMinor(GBP, 234); BigMoney b = BigMoney.ofMinor(GBP, 235); @@ -2080,206 +2295,220 @@ public void test_compareTo_BigMoney() { assertEquals(-1, t.compareTo(c)); } - @Test(expected = CurrencyMismatchException.class) - public void test_compareTo_currenciesDiffer() { + @Test + void test_compareTo_currenciesDiffer() { Money a = GBP_2_34; Money b = USD_2_35; - a.compareTo(b); + assertThrows(CurrencyMismatchException.class, () -> { + a.compareTo(b); + }); } - @Test(expected = ClassCastException.class) + @Test @SuppressWarnings({"unchecked", "rawtypes"}) - public void test_compareTo_wrongType() { + void test_compareTo_wrongType() { Comparable a = GBP_2_34; - a.compareTo("NotRightType"); + assertThrows(ClassCastException.class, () -> { + a.compareTo("NotRightType"); + }); } //----------------------------------------------------------------------- // isEqual() //----------------------------------------------------------------------- @Test - public void test_isEqual() { + void test_isEqual() { Money a = GBP_2_34; Money b = GBP_2_35; Money c = GBP_2_36; - assertEquals(true, a.isEqual(a)); - assertEquals(true, b.isEqual(b)); - assertEquals(true, c.isEqual(c)); + assertTrue(a.isEqual(a)); + assertTrue(b.isEqual(b)); + assertTrue(c.isEqual(c)); - assertEquals(false, a.isEqual(b)); - assertEquals(false, b.isEqual(a)); + assertFalse(a.isEqual(b)); + assertFalse(b.isEqual(a)); - assertEquals(false, a.isEqual(c)); - assertEquals(false, c.isEqual(a)); + assertFalse(a.isEqual(c)); + assertFalse(c.isEqual(a)); - assertEquals(false, b.isEqual(c)); - assertEquals(false, c.isEqual(b)); + assertFalse(b.isEqual(c)); + assertFalse(c.isEqual(b)); } @Test - public void test_isEqual_Money() { + void test_isEqual_Money() { Money a = GBP_2_34; BigMoney b = BigMoney.ofMinor(GBP, 234); - assertEquals(true, a.isEqual(b)); + assertTrue(a.isEqual(b)); } - @Test(expected = CurrencyMismatchException.class) - public void test_isEqual_currenciesDiffer() { + @Test + void test_isEqual_currenciesDiffer() { Money a = GBP_2_34; Money b = USD_2_35; - a.isEqual(b); + assertThrows(CurrencyMismatchException.class, () -> { + a.isEqual(b); + }); } //----------------------------------------------------------------------- // isGreaterThan() //----------------------------------------------------------------------- @Test - public void test_isGreaterThan() { + void test_isGreaterThan() { Money a = GBP_2_34; Money b = GBP_2_35; Money c = GBP_2_36; - assertEquals(false, a.isGreaterThan(a)); - assertEquals(false, a.isGreaterThan(b)); - assertEquals(false, a.isGreaterThan(c)); + assertFalse(a.isGreaterThan(a)); + assertFalse(a.isGreaterThan(b)); + assertFalse(a.isGreaterThan(c)); - assertEquals(true, b.isGreaterThan(a)); - assertEquals(false, b.isGreaterThan(b)); - assertEquals(false, b.isGreaterThan(c)); + assertTrue(b.isGreaterThan(a)); + assertFalse(b.isGreaterThan(b)); + assertFalse(b.isGreaterThan(c)); - assertEquals(true, c.isGreaterThan(a)); - assertEquals(true, c.isGreaterThan(b)); - assertEquals(false, c.isGreaterThan(c)); + assertTrue(c.isGreaterThan(a)); + assertTrue(c.isGreaterThan(b)); + assertFalse(c.isGreaterThan(c)); } - @Test(expected = CurrencyMismatchException.class) - public void test_isGreaterThan_currenciesDiffer() { + @Test + void test_isGreaterThan_currenciesDiffer() { Money a = GBP_2_34; Money b = USD_2_35; - a.isGreaterThan(b); + assertThrows(CurrencyMismatchException.class, () -> { + a.isGreaterThan(b); + }); } //----------------------------------------------------------------------- // isGreaterThanOrEqual() //----------------------------------------------------------------------- @Test - public void test_isGreaterThanOrEqual() { + void test_isGreaterThanOrEqual() { Money a = GBP_2_34; Money b = GBP_2_35; Money c = GBP_2_36; - assertEquals(true, a.isGreaterThanOrEqual(a)); - assertEquals(false, a.isGreaterThanOrEqual(b)); - assertEquals(false, a.isGreaterThanOrEqual(c)); + assertTrue(a.isGreaterThanOrEqual(a)); + assertFalse(a.isGreaterThanOrEqual(b)); + assertFalse(a.isGreaterThanOrEqual(c)); - assertEquals(true, b.isGreaterThanOrEqual(a)); - assertEquals(true, b.isGreaterThanOrEqual(b)); - assertEquals(false, b.isGreaterThanOrEqual(c)); + assertTrue(b.isGreaterThanOrEqual(a)); + assertTrue(b.isGreaterThanOrEqual(b)); + assertFalse(b.isGreaterThanOrEqual(c)); - assertEquals(true, c.isGreaterThanOrEqual(a)); - assertEquals(true, c.isGreaterThanOrEqual(b)); - assertEquals(true, c.isGreaterThanOrEqual(c)); + assertTrue(c.isGreaterThanOrEqual(a)); + assertTrue(c.isGreaterThanOrEqual(b)); + assertTrue(c.isGreaterThanOrEqual(c)); } - @Test(expected = CurrencyMismatchException.class) - public void test_isGreaterThanOrEqual_currenciesDiffer() { + @Test + void test_isGreaterThanOrEqual_currenciesDiffer() { Money a = GBP_2_34; Money b = USD_2_35; - a.isGreaterThanOrEqual(b); + assertThrows(CurrencyMismatchException.class, () -> { + a.isGreaterThanOrEqual(b); + }); } //----------------------------------------------------------------------- // isLessThan() //----------------------------------------------------------------------- @Test - public void test_isLessThan() { + void test_isLessThan() { Money a = GBP_2_34; Money b = GBP_2_35; Money c = GBP_2_36; - assertEquals(false, a.isLessThan(a)); - assertEquals(true, a.isLessThan(b)); - assertEquals(true, a.isLessThan(c)); + assertFalse(a.isLessThan(a)); + assertTrue(a.isLessThan(b)); + assertTrue(a.isLessThan(c)); - assertEquals(false, b.isLessThan(a)); - assertEquals(false, b.isLessThan(b)); - assertEquals(true, b.isLessThan(c)); + assertFalse(b.isLessThan(a)); + assertFalse(b.isLessThan(b)); + assertTrue(b.isLessThan(c)); - assertEquals(false, c.isLessThan(a)); - assertEquals(false, c.isLessThan(b)); - assertEquals(false, c.isLessThan(c)); + assertFalse(c.isLessThan(a)); + assertFalse(c.isLessThan(b)); + assertFalse(c.isLessThan(c)); } - @Test(expected = CurrencyMismatchException.class) - public void test_isLessThan_currenciesDiffer() { + @Test + void test_isLessThan_currenciesDiffer() { Money a = GBP_2_34; Money b = USD_2_35; - a.isLessThan(b); + assertThrows(CurrencyMismatchException.class, () -> { + a.isLessThan(b); + }); } //----------------------------------------------------------------------- // isLessThanOrEqual() //----------------------------------------------------------------------- @Test - public void test_isLessThanOrEqual() { + void test_isLessThanOrEqual() { Money a = GBP_2_34; Money b = GBP_2_35; Money c = GBP_2_36; - assertEquals(true, a.isLessThanOrEqual(a)); - assertEquals(true, a.isLessThanOrEqual(b)); - assertEquals(true, a.isLessThanOrEqual(c)); + assertTrue(a.isLessThanOrEqual(a)); + assertTrue(a.isLessThanOrEqual(b)); + assertTrue(a.isLessThanOrEqual(c)); - assertEquals(false, b.isLessThanOrEqual(a)); - assertEquals(true, b.isLessThanOrEqual(b)); - assertEquals(true, b.isLessThanOrEqual(c)); + assertFalse(b.isLessThanOrEqual(a)); + assertTrue(b.isLessThanOrEqual(b)); + assertTrue(b.isLessThanOrEqual(c)); - assertEquals(false, c.isLessThanOrEqual(a)); - assertEquals(false, c.isLessThanOrEqual(b)); - assertEquals(true, c.isLessThanOrEqual(c)); + assertFalse(c.isLessThanOrEqual(a)); + assertFalse(c.isLessThanOrEqual(b)); + assertTrue(c.isLessThanOrEqual(c)); } - @Test(expected = CurrencyMismatchException.class) - public void test_isLessThanOrEqual_currenciesDiffer() { + @Test + void test_isLessThanOrEqual_currenciesDiffer() { Money a = GBP_2_34; Money b = USD_2_35; - a.isLessThanOrEqual(b); + assertThrows(CurrencyMismatchException.class, () -> { + a.isLessThanOrEqual(b); + }); } //----------------------------------------------------------------------- // equals() hashCode() //----------------------------------------------------------------------- @Test - public void test_equals_hashCode_positive() { + void test_equals_hashCode_positive() { Money a = GBP_2_34; Money b = GBP_2_34; Money c = GBP_2_35; - assertEquals(true, a.equals(a)); - assertEquals(true, b.equals(b)); - assertEquals(true, c.equals(c)); + assertTrue(a.equals(a)); + assertTrue(b.equals(b)); + assertTrue(c.equals(c)); - assertEquals(true, a.equals(b)); - assertEquals(true, b.equals(a)); - assertEquals(true, a.hashCode() == b.hashCode()); + assertTrue(a.equals(b)); + assertTrue(b.equals(a)); + assertTrue(a.hashCode() == b.hashCode()); - assertEquals(false, a.equals(c)); - assertEquals(false, b.equals(c)); + assertFalse(a.equals(c)); + assertFalse(b.equals(c)); } @Test - public void test_equals_false() { + void test_equals_false() { Money a = GBP_2_34; - assertEquals(false, a.equals(null)); - assertEquals(false, a.equals(new Object())); + assertFalse(a.equals(null)); + assertFalse(a.equals(new Object())); } //----------------------------------------------------------------------- // toString() //----------------------------------------------------------------------- @Test - public void test_toString_positive() { + void test_toString_positive() { Money test = Money.of(GBP, BIGDEC_2_34); assertEquals("GBP 2.34", test.toString()); } @Test - public void test_toString_negative() { + void test_toString_negative() { Money test = Money.of(EUR, BIGDEC_M5_78); assertEquals("EUR -5.78", test.toString()); } diff --git a/src/test/java/org/joda/money/TestMoneyUtils_BigMoney.java b/src/test/java/org/joda/money/TestMoneyUtils_BigMoney.java index b81dbde..93dd899 100644 --- a/src/test/java/org/joda/money/TestMoneyUtils_BigMoney.java +++ b/src/test/java/org/joda/money/TestMoneyUtils_BigMoney.java @@ -15,20 +15,22 @@ */ package org.joda.money; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.lang.reflect.Constructor; import java.lang.reflect.Modifier; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Test MoneyUtils. */ -public class TestMoneyUtils_BigMoney { +class TestMoneyUtils_BigMoney { private static final BigMoney GBP_0 = BigMoney.parse("GBP 0"); private static final BigMoney GBP_20 = BigMoney.parse("GBP 20"); @@ -42,7 +44,7 @@ public class TestMoneyUtils_BigMoney { // constructor //----------------------------------------------------------------------- @Test - public void test_constructor() throws Exception { + void test_constructor() throws Exception { Constructor con = MoneyUtils.class.getDeclaredConstructor(); assertTrue(Modifier.isPrivate(con.getModifiers())); con.setAccessible(true); @@ -53,7 +55,7 @@ public void test_constructor() throws Exception { // isZero(BigMoney) //----------------------------------------------------------------------- @Test - public void test_isZero() { + void test_isZero() { assertTrue(MoneyUtils.isZero(null)); assertTrue(MoneyUtils.isZero(GBP_0)); assertFalse(MoneyUtils.isZero(GBP_30)); @@ -64,7 +66,7 @@ public void test_isZero() { // isPositive(BigMoney) //----------------------------------------------------------------------- @Test - public void test_isPositive() { + void test_isPositive() { assertFalse(MoneyUtils.isPositive(null)); assertFalse(MoneyUtils.isPositive(GBP_0)); assertTrue(MoneyUtils.isPositive(GBP_30)); @@ -75,7 +77,7 @@ public void test_isPositive() { // isPositiveOrZero(BigMoney) //----------------------------------------------------------------------- @Test - public void test_isPositiveOrZero() { + void test_isPositiveOrZero() { assertTrue(MoneyUtils.isPositiveOrZero(null)); assertTrue(MoneyUtils.isPositiveOrZero(GBP_0)); assertTrue(MoneyUtils.isPositiveOrZero(GBP_30)); @@ -86,7 +88,7 @@ public void test_isPositiveOrZero() { // isNegative(BigMoney) //----------------------------------------------------------------------- @Test - public void test_isNegative() { + void test_isNegative() { assertFalse(MoneyUtils.isNegative(null)); assertFalse(MoneyUtils.isNegative(GBP_0)); assertFalse(MoneyUtils.isNegative(GBP_30)); @@ -97,7 +99,7 @@ public void test_isNegative() { // isNegativeOrZero(BigMoney) //----------------------------------------------------------------------- @Test - public void test_isNegativeOrZero() { + void test_isNegativeOrZero() { assertTrue(MoneyUtils.isNegativeOrZero(null)); assertTrue(MoneyUtils.isNegativeOrZero(GBP_0)); assertFalse(MoneyUtils.isNegativeOrZero(GBP_30)); @@ -108,122 +110,130 @@ public void test_isNegativeOrZero() { // max(Money,Money) //----------------------------------------------------------------------- @Test - public void test_max1() { + void test_max1() { assertSame(GBP_30, MoneyUtils.max(GBP_20, GBP_30)); } @Test - public void test_max2() { + void test_max2() { assertSame(GBP_30, MoneyUtils.max(GBP_30, GBP_20)); } - @Test(expected = CurrencyMismatchException.class) - public void test_max_differentCurrencies() { - MoneyUtils.max(GBP_20, EUR_30); + @Test + void test_max_differentCurrencies() { + assertThrows(CurrencyMismatchException.class, () -> { + MoneyUtils.max(GBP_20, EUR_30); + }); } @Test - public void test_max_null1() { + void test_max_null1() { assertSame(GBP_30, MoneyUtils.max((BigMoney) null, GBP_30)); } @Test - public void test_max_null2() { + void test_max_null2() { assertSame(GBP_20, MoneyUtils.max(GBP_20, (BigMoney) null)); } @Test - public void test_max_nullBoth() { - assertEquals(null, MoneyUtils.max((BigMoney) null, (BigMoney) null)); + void test_max_nullBoth() { + assertNull(MoneyUtils.max((BigMoney) null, (BigMoney) null)); } //----------------------------------------------------------------------- // min(Money,Money) //----------------------------------------------------------------------- @Test - public void test_min1() { + void test_min1() { assertSame(GBP_20, MoneyUtils.min(GBP_20, GBP_30)); } @Test - public void test_min2() { + void test_min2() { assertSame(GBP_20, MoneyUtils.min(GBP_30, GBP_20)); } - @Test(expected = CurrencyMismatchException.class) - public void test_min_differentCurrencies() { - MoneyUtils.min(GBP_20, EUR_30); + @Test + void test_min_differentCurrencies() { + assertThrows(CurrencyMismatchException.class, () -> { + MoneyUtils.min(GBP_20, EUR_30); + }); } @Test - public void test_min_null1() { + void test_min_null1() { assertSame(GBP_30, MoneyUtils.min((BigMoney) null, GBP_30)); } @Test - public void test_min_null2() { + void test_min_null2() { assertSame(GBP_20, MoneyUtils.min(GBP_20, (BigMoney) null)); } @Test - public void test_min_nullBoth() { - assertEquals(null, MoneyUtils.min((BigMoney) null, (BigMoney) null)); + void test_min_nullBoth() { + assertNull(MoneyUtils.min((BigMoney) null, (BigMoney) null)); } //----------------------------------------------------------------------- // add(Money,Money) //----------------------------------------------------------------------- @Test - public void test_add() { + void test_add() { assertEquals(GBP_50, MoneyUtils.add(GBP_20, GBP_30)); } - @Test(expected = CurrencyMismatchException.class) - public void test_add_differentCurrencies() { - MoneyUtils.add(GBP_20, EUR_30); + @Test + void test_add_differentCurrencies() { + assertThrows(CurrencyMismatchException.class, () -> { + MoneyUtils.add(GBP_20, EUR_30); + }); } @Test - public void test_add_null1() { + void test_add_null1() { assertSame(GBP_30, MoneyUtils.add((BigMoney) null, GBP_30)); } @Test - public void test_add_null2() { + void test_add_null2() { assertSame(GBP_20, MoneyUtils.add(GBP_20, (BigMoney) null)); } @Test - public void test_add_nullBoth() { - assertEquals(null, MoneyUtils.add((BigMoney) null, (BigMoney) null)); + void test_add_nullBoth() { + assertNull(MoneyUtils.add((BigMoney) null, (BigMoney) null)); } //----------------------------------------------------------------------- // subtract(Money,Money) //----------------------------------------------------------------------- @Test - public void test_subtract() { + void test_subtract() { assertEquals(GBP_M10, MoneyUtils.subtract(GBP_20, GBP_30)); } - @Test(expected = CurrencyMismatchException.class) - public void test_subtract_differentCurrencies() { - MoneyUtils.subtract(GBP_20, EUR_30); + @Test + void test_subtract_differentCurrencies() { + assertThrows(CurrencyMismatchException.class, () -> { + MoneyUtils.subtract(GBP_20, EUR_30); + }); } @Test - public void test_subtract_null1() { + void test_subtract_null1() { assertEquals(GBP_M30, MoneyUtils.subtract((BigMoney) null, GBP_30)); } @Test - public void test_subtract_null2() { + void test_subtract_null2() { assertSame(GBP_20, MoneyUtils.subtract(GBP_20, (BigMoney) null)); } @Test - public void test_subtract_nullBoth() { - assertEquals(null, MoneyUtils.subtract((BigMoney) null, (BigMoney) null)); + void test_subtract_nullBoth() { + assertNull(MoneyUtils.subtract((BigMoney) null, (BigMoney) null)); } } diff --git a/src/test/java/org/joda/money/TestMoneyUtils_Money.java b/src/test/java/org/joda/money/TestMoneyUtils_Money.java index d46b6ff..a0a9e30 100644 --- a/src/test/java/org/joda/money/TestMoneyUtils_Money.java +++ b/src/test/java/org/joda/money/TestMoneyUtils_Money.java @@ -15,17 +15,19 @@ */ package org.joda.money; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Test MoneyUtils. */ -public class TestMoneyUtils_Money { +class TestMoneyUtils_Money { private static final Money GBP_0 = Money.parse("GBP 0"); private static final Money GBP_20 = Money.parse("GBP 20"); @@ -39,25 +41,27 @@ public class TestMoneyUtils_Money { // checkNotNull(Object,String) //----------------------------------------------------------------------- @Test - public void test_checkNotNull_notNull() { + void test_checkNotNull_notNull() { MoneyUtils.checkNotNull(new Object(), ""); } - @Test(expected = NullPointerException.class) - public void test_checkNotNull_null() { - try { - MoneyUtils.checkNotNull(null, "Hello"); - } catch (NullPointerException ex) { - assertEquals("Hello", ex.getMessage()); - throw ex; - } + @Test + void test_checkNotNull_null() { + assertThrows(NullPointerException.class, () -> { + try { + MoneyUtils.checkNotNull(null, "Hello"); + } catch (NullPointerException ex) { + assertEquals("Hello", ex.getMessage()); + throw ex; + } + }); } //----------------------------------------------------------------------- // isZero(Money) //----------------------------------------------------------------------- @Test - public void test_isZero() { + void test_isZero() { assertTrue(MoneyUtils.isZero(null)); assertTrue(MoneyUtils.isZero(GBP_0)); assertFalse(MoneyUtils.isZero(GBP_30)); @@ -68,7 +72,7 @@ public void test_isZero() { // isPositive(Money) //----------------------------------------------------------------------- @Test - public void test_isPositive() { + void test_isPositive() { assertFalse(MoneyUtils.isPositive(null)); assertFalse(MoneyUtils.isPositive(GBP_0)); assertTrue(MoneyUtils.isPositive(GBP_30)); @@ -79,7 +83,7 @@ public void test_isPositive() { // isPositiveOrZero(Money) //----------------------------------------------------------------------- @Test - public void test_isPositiveOrZero() { + void test_isPositiveOrZero() { assertTrue(MoneyUtils.isPositiveOrZero(null)); assertTrue(MoneyUtils.isPositiveOrZero(GBP_0)); assertTrue(MoneyUtils.isPositiveOrZero(GBP_30)); @@ -90,7 +94,7 @@ public void test_isPositiveOrZero() { // isNegative(Money) //----------------------------------------------------------------------- @Test - public void test_isNegative() { + void test_isNegative() { assertFalse(MoneyUtils.isNegative(null)); assertFalse(MoneyUtils.isNegative(GBP_0)); assertFalse(MoneyUtils.isNegative(GBP_30)); @@ -101,7 +105,7 @@ public void test_isNegative() { // isNegativeOrZero(Money) //----------------------------------------------------------------------- @Test - public void test_isNegativeOrZero() { + void test_isNegativeOrZero() { assertTrue(MoneyUtils.isNegativeOrZero(null)); assertTrue(MoneyUtils.isNegativeOrZero(GBP_0)); assertFalse(MoneyUtils.isNegativeOrZero(GBP_30)); @@ -112,122 +116,130 @@ public void test_isNegativeOrZero() { // max(Money,Money) //----------------------------------------------------------------------- @Test - public void test_max1() { + void test_max1() { assertSame(GBP_30, MoneyUtils.max(GBP_20, GBP_30)); } @Test - public void test_max2() { + void test_max2() { assertSame(GBP_30, MoneyUtils.max(GBP_30, GBP_20)); } - @Test(expected = CurrencyMismatchException.class) - public void test_max_differentCurrencies() { - MoneyUtils.max(GBP_20, EUR_30); + @Test + void test_max_differentCurrencies() { + assertThrows(CurrencyMismatchException.class, () -> { + MoneyUtils.max(GBP_20, EUR_30); + }); } @Test - public void test_max_null1() { + void test_max_null1() { assertSame(GBP_30, MoneyUtils.max((Money) null, GBP_30)); } @Test - public void test_max_null2() { + void test_max_null2() { assertSame(GBP_20, MoneyUtils.max(GBP_20, (Money) null)); } @Test - public void test_max_nullBoth() { - assertEquals(null, MoneyUtils.max((Money) null, (Money) null)); + void test_max_nullBoth() { + assertNull(MoneyUtils.max((Money) null, (Money) null)); } //----------------------------------------------------------------------- // min(Money,Money) //----------------------------------------------------------------------- @Test - public void test_min1() { + void test_min1() { assertSame(GBP_20, MoneyUtils.min(GBP_20, GBP_30)); } @Test - public void test_min2() { + void test_min2() { assertSame(GBP_20, MoneyUtils.min(GBP_30, GBP_20)); } - @Test(expected = CurrencyMismatchException.class) - public void test_min_differentCurrencies() { - MoneyUtils.min(GBP_20, EUR_30); + @Test + void test_min_differentCurrencies() { + assertThrows(CurrencyMismatchException.class, () -> { + MoneyUtils.min(GBP_20, EUR_30); + }); } @Test - public void test_min_null1() { + void test_min_null1() { assertSame(GBP_30, MoneyUtils.min((Money) null, GBP_30)); } @Test - public void test_min_null2() { + void test_min_null2() { assertSame(GBP_20, MoneyUtils.min(GBP_20, (Money) null)); } @Test - public void test_min_nullBoth() { - assertEquals(null, MoneyUtils.min((Money) null, (Money) null)); + void test_min_nullBoth() { + assertNull(MoneyUtils.min((Money) null, (Money) null)); } //----------------------------------------------------------------------- // add(Money,Money) //----------------------------------------------------------------------- @Test - public void test_add() { + void test_add() { assertEquals(GBP_50, MoneyUtils.add(GBP_20, GBP_30)); } - @Test(expected = CurrencyMismatchException.class) - public void test_add_differentCurrencies() { - MoneyUtils.add(GBP_20, EUR_30); + @Test + void test_add_differentCurrencies() { + assertThrows(CurrencyMismatchException.class, () -> { + MoneyUtils.add(GBP_20, EUR_30); + }); } @Test - public void test_add_null1() { + void test_add_null1() { assertSame(GBP_30, MoneyUtils.add((Money) null, GBP_30)); } @Test - public void test_add_null2() { + void test_add_null2() { assertSame(GBP_20, MoneyUtils.add(GBP_20, (Money) null)); } @Test - public void test_add_nullBoth() { - assertEquals(null, MoneyUtils.add((Money) null, (Money) null)); + void test_add_nullBoth() { + assertNull(MoneyUtils.add((Money) null, (Money) null)); } //----------------------------------------------------------------------- // subtract(Money,Money) //----------------------------------------------------------------------- @Test - public void test_subtract() { + void test_subtract() { assertEquals(GBP_M10, MoneyUtils.subtract(GBP_20, GBP_30)); } - @Test(expected = CurrencyMismatchException.class) - public void test_subtract_differentCurrencies() { - MoneyUtils.subtract(GBP_20, EUR_30); + @Test + void test_subtract_differentCurrencies() { + assertThrows(CurrencyMismatchException.class, () -> { + MoneyUtils.subtract(GBP_20, EUR_30); + }); } @Test - public void test_subtract_null1() { + void test_subtract_null1() { assertEquals(GBP_M30, MoneyUtils.subtract((Money) null, GBP_30)); } @Test - public void test_subtract_null2() { + void test_subtract_null2() { assertSame(GBP_20, MoneyUtils.subtract(GBP_20, (Money) null)); } @Test - public void test_subtract_nullBoth() { - assertEquals(null, MoneyUtils.subtract((Money) null, (Money) null)); + void test_subtract_nullBoth() { + assertNull(MoneyUtils.subtract((Money) null, (Money) null)); } } diff --git a/src/test/java/org/joda/money/TestStringConvert.java b/src/test/java/org/joda/money/TestStringConvert.java index 98102ec..6d00e99 100644 --- a/src/test/java/org/joda/money/TestStringConvert.java +++ b/src/test/java/org/joda/money/TestStringConvert.java @@ -15,37 +15,38 @@ */ package org.joda.money; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; + import org.joda.convert.StringConvert; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Test string conversion. */ -public class TestStringConvert { +class TestStringConvert { @Test - public void test_BigMoney() { + void test_BigMoney() { BigMoney test = BigMoney.of(CurrencyUnit.CHF, 1234.5678d); String str = StringConvert.INSTANCE.convertToString(test); - assertEquals(str, "CHF 1234.5678"); + assertEquals("CHF 1234.5678", str); assertEquals(test, StringConvert.INSTANCE.convertFromString(BigMoney.class, str)); } @Test - public void test_Money() { + void test_Money() { Money test = Money.of(CurrencyUnit.CHF, 1234.56d); String str = StringConvert.INSTANCE.convertToString(test); - assertEquals(str, "CHF 1234.56"); + assertEquals("CHF 1234.56", str); assertEquals(test, StringConvert.INSTANCE.convertFromString(Money.class, str)); } @Test - public void test_CurrencyUnit() { + void test_CurrencyUnit() { CurrencyUnit test = CurrencyUnit.CHF; String str = StringConvert.INSTANCE.convertToString(test); - assertEquals(str, "CHF"); + assertEquals("CHF", str); assertEquals(test, StringConvert.INSTANCE.convertFromString(CurrencyUnit.class, str)); } diff --git a/src/test/java/org/joda/money/format/TestMoneyAmountStyle.java b/src/test/java/org/joda/money/format/TestMoneyAmountStyle.java index 2ea5141..92435f4 100644 --- a/src/test/java/org/joda/money/format/TestMoneyAmountStyle.java +++ b/src/test/java/org/joda/money/format/TestMoneyAmountStyle.java @@ -15,23 +15,26 @@ */ package org.joda.money.format; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.math.BigDecimal; import java.util.Locale; import org.joda.money.BigMoney; import org.joda.money.CurrencyUnit; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * Test MoneyAmountStyle. */ -public class TestMoneyAmountStyle { +class TestMoneyAmountStyle { private static final Locale cCachedLocale = Locale.getDefault(); private static final Locale TEST_GB_LOCALE = new Locale("en", "GB", "TEST"); @@ -39,13 +42,13 @@ public class TestMoneyAmountStyle { private static final Locale TEST_LV_LOCALE = new Locale("lv", "LV", "TEST"); private static final BigMoney MONEY = BigMoney.of(CurrencyUnit.GBP, new BigDecimal("87654321.12345678")); - @Before - public void beforeMethod() { + @BeforeEach + void beforeMethod() { Locale.setDefault(TEST_GB_LOCALE); } - @After - public void afterMethod() { + @AfterEach + void afterMethod() { Locale.setDefault(cCachedLocale); } @@ -53,7 +56,7 @@ public void afterMethod() { // Constants //----------------------------------------------------------------------- @Test - public void test_ASCII_DECIMAL_POINT_GROUP3_COMMA() { + void test_ASCII_DECIMAL_POINT_GROUP3_COMMA() { MoneyAmountStyle style = MoneyAmountStyle.ASCII_DECIMAL_POINT_GROUP3_COMMA; assertEquals((Character) '0', style.getZeroCharacter()); assertEquals((Character) '+', style.getPositiveSignCharacter()); @@ -63,18 +66,18 @@ public void test_ASCII_DECIMAL_POINT_GROUP3_COMMA() { assertEquals(GroupingStyle.FULL, style.getGroupingStyle()); assertEquals((Integer) 3, style.getGroupingSize()); assertEquals((Integer) 0, style.getExtendedGroupingSize()); - assertEquals(false, style.isForcedDecimalPoint()); + assertFalse(style.isForcedDecimalPoint()); } @Test - public void test_ASCII_DECIMAL_POINT_GROUP3_COMMA_print() { + void test_ASCII_DECIMAL_POINT_GROUP3_COMMA_print() { MoneyAmountStyle style = MoneyAmountStyle.ASCII_DECIMAL_POINT_GROUP3_COMMA; MoneyFormatter test = new MoneyFormatterBuilder().appendAmount(style).toFormatter(); assertEquals("87,654,321.123,456,78", test.print(MONEY)); } @Test - public void test_ASCII_DECIMAL_POINT_GROUP3_SPACE() { + void test_ASCII_DECIMAL_POINT_GROUP3_SPACE() { MoneyAmountStyle style = MoneyAmountStyle.ASCII_DECIMAL_POINT_GROUP3_SPACE; assertEquals((Character) '0', style.getZeroCharacter()); assertEquals((Character) '+', style.getPositiveSignCharacter()); @@ -84,18 +87,18 @@ public void test_ASCII_DECIMAL_POINT_GROUP3_SPACE() { assertEquals(GroupingStyle.FULL, style.getGroupingStyle()); assertEquals((Integer) 3, style.getGroupingSize()); assertEquals((Integer) 0, style.getExtendedGroupingSize()); - assertEquals(false, style.isForcedDecimalPoint()); + assertFalse(style.isForcedDecimalPoint()); } @Test - public void test_ASCII_ASCII_DECIMAL_POINT_GROUP3_SPACE_print() { + void test_ASCII_ASCII_DECIMAL_POINT_GROUP3_SPACE_print() { MoneyAmountStyle style = MoneyAmountStyle.ASCII_DECIMAL_POINT_GROUP3_SPACE; MoneyFormatter test = new MoneyFormatterBuilder().appendAmount(style).toFormatter(); assertEquals("87 654 321.123 456 78", test.print(MONEY)); } @Test - public void test_ASCII_DECIMAL_POINT_NO_GROUPING() { + void test_ASCII_DECIMAL_POINT_NO_GROUPING() { MoneyAmountStyle style = MoneyAmountStyle.ASCII_DECIMAL_POINT_NO_GROUPING; assertEquals((Character) '0', style.getZeroCharacter()); assertEquals((Character) '+', style.getPositiveSignCharacter()); @@ -105,18 +108,18 @@ public void test_ASCII_DECIMAL_POINT_NO_GROUPING() { assertEquals(GroupingStyle.NONE, style.getGroupingStyle()); assertEquals((Integer) 3, style.getGroupingSize()); assertEquals((Integer) 0, style.getExtendedGroupingSize()); - assertEquals(false, style.isForcedDecimalPoint()); + assertFalse(style.isForcedDecimalPoint()); } @Test - public void test_ASCII_DECIMAL_POINT_NO_GROUPING_print() { + void test_ASCII_DECIMAL_POINT_NO_GROUPING_print() { MoneyAmountStyle style = MoneyAmountStyle.ASCII_DECIMAL_POINT_NO_GROUPING; MoneyFormatter test = new MoneyFormatterBuilder().appendAmount(style).toFormatter(); assertEquals("87654321.12345678", test.print(MONEY)); } @Test - public void test_ASCII_ASCII_DECIMAL_COMMA_GROUP3_DOT() { + void test_ASCII_ASCII_DECIMAL_COMMA_GROUP3_DOT() { MoneyAmountStyle style = MoneyAmountStyle.ASCII_DECIMAL_COMMA_GROUP3_DOT; assertEquals((Character) '0', style.getZeroCharacter()); assertEquals((Character) '+', style.getPositiveSignCharacter()); @@ -126,18 +129,18 @@ public void test_ASCII_ASCII_DECIMAL_COMMA_GROUP3_DOT() { assertEquals(GroupingStyle.FULL, style.getGroupingStyle()); assertEquals((Integer) 3, style.getGroupingSize()); assertEquals((Integer) 0, style.getExtendedGroupingSize()); - assertEquals(false, style.isForcedDecimalPoint()); + assertFalse(style.isForcedDecimalPoint()); } @Test - public void test_ASCII_DECIMAL_COMMA_GROUP3_DOT_print() { + void test_ASCII_DECIMAL_COMMA_GROUP3_DOT_print() { MoneyAmountStyle style = MoneyAmountStyle.ASCII_DECIMAL_COMMA_GROUP3_DOT; MoneyFormatter test = new MoneyFormatterBuilder().appendAmount(style).toFormatter(); assertEquals("87.654.321,123.456.78", test.print(MONEY)); } @Test - public void test_ASCII_DECIMAL_COMMA_GROUP3_SPACE() { + void test_ASCII_DECIMAL_COMMA_GROUP3_SPACE() { MoneyAmountStyle style = MoneyAmountStyle.ASCII_DECIMAL_COMMA_GROUP3_SPACE; assertEquals((Character) '0', style.getZeroCharacter()); assertEquals((Character) '+', style.getPositiveSignCharacter()); @@ -147,18 +150,18 @@ public void test_ASCII_DECIMAL_COMMA_GROUP3_SPACE() { assertEquals(GroupingStyle.FULL, style.getGroupingStyle()); assertEquals((Integer) 3, style.getGroupingSize()); assertEquals((Integer) 0, style.getExtendedGroupingSize()); - assertEquals(false, style.isForcedDecimalPoint()); + assertFalse(style.isForcedDecimalPoint()); } @Test - public void test_ASCII_DECIMAL_COMMA_GROUP3_SPACE_print() { + void test_ASCII_DECIMAL_COMMA_GROUP3_SPACE_print() { MoneyAmountStyle style = MoneyAmountStyle.ASCII_DECIMAL_COMMA_GROUP3_SPACE; MoneyFormatter test = new MoneyFormatterBuilder().appendAmount(style).toFormatter(); assertEquals("87 654 321,123 456 78", test.print(MONEY)); } @Test - public void test_ASCII_DECIMAL_COMMA_NO_GROUPING() { + void test_ASCII_DECIMAL_COMMA_NO_GROUPING() { MoneyAmountStyle style = MoneyAmountStyle.ASCII_DECIMAL_COMMA_NO_GROUPING; assertEquals((Character) '0', style.getZeroCharacter()); assertEquals((Character) '+', style.getPositiveSignCharacter()); @@ -168,60 +171,60 @@ public void test_ASCII_DECIMAL_COMMA_NO_GROUPING() { assertEquals(GroupingStyle.NONE, style.getGroupingStyle()); assertEquals((Integer) 3, style.getGroupingSize()); assertEquals((Integer) 0, style.getExtendedGroupingSize()); - assertEquals(false, style.isForcedDecimalPoint()); + assertFalse(style.isForcedDecimalPoint()); } @Test - public void test_ASCII_DECIMAL_COMMA_NO_GROUPING_print() { + void test_ASCII_DECIMAL_COMMA_NO_GROUPING_print() { MoneyAmountStyle style = MoneyAmountStyle.ASCII_DECIMAL_COMMA_NO_GROUPING; MoneyFormatter test = new MoneyFormatterBuilder().appendAmount(style).toFormatter(); assertEquals("87654321,12345678", test.print(MONEY)); } @Test - public void test_LOCALIZED_GROUPING() { + void test_LOCALIZED_GROUPING() { MoneyAmountStyle style = MoneyAmountStyle.LOCALIZED_GROUPING; - assertEquals(null, style.getZeroCharacter()); - assertEquals(null, style.getPositiveSignCharacter()); - assertEquals(null, style.getNegativeSignCharacter()); - assertEquals(null, style.getDecimalPointCharacter()); - assertEquals(null, style.getGroupingCharacter()); + assertNull(style.getZeroCharacter()); + assertNull(style.getPositiveSignCharacter()); + assertNull(style.getNegativeSignCharacter()); + assertNull(style.getDecimalPointCharacter()); + assertNull(style.getGroupingCharacter()); assertEquals(GroupingStyle.FULL, style.getGroupingStyle()); - assertEquals(null, style.getGroupingSize()); - assertEquals(null, style.getExtendedGroupingSize()); - assertEquals(false, style.isForcedDecimalPoint()); + assertNull(style.getGroupingSize()); + assertNull(style.getExtendedGroupingSize()); + assertFalse(style.isForcedDecimalPoint()); } @Test - public void test_LOCALIZED_GROUPING_print() { + void test_LOCALIZED_GROUPING_print() { MoneyAmountStyle style = MoneyAmountStyle.LOCALIZED_GROUPING; MoneyFormatter test = new MoneyFormatterBuilder().appendAmount(style).toFormatter(); assertEquals("87,654,321.123,456,78", test.print(MONEY)); } @Test - public void test_LOCALIZED_NO_GROUPING() { + void test_LOCALIZED_NO_GROUPING() { MoneyAmountStyle style = MoneyAmountStyle.LOCALIZED_NO_GROUPING; - assertEquals(null, style.getZeroCharacter()); - assertEquals(null, style.getPositiveSignCharacter()); - assertEquals(null, style.getNegativeSignCharacter()); - assertEquals(null, style.getDecimalPointCharacter()); - assertEquals(null, style.getGroupingCharacter()); + assertNull(style.getZeroCharacter()); + assertNull(style.getPositiveSignCharacter()); + assertNull(style.getNegativeSignCharacter()); + assertNull(style.getDecimalPointCharacter()); + assertNull(style.getGroupingCharacter()); assertEquals(GroupingStyle.NONE, style.getGroupingStyle()); - assertEquals(null, style.getGroupingSize()); - assertEquals(null, style.getExtendedGroupingSize()); - assertEquals(false, style.isForcedDecimalPoint()); + assertNull(style.getGroupingSize()); + assertNull(style.getExtendedGroupingSize()); + assertFalse(style.isForcedDecimalPoint()); } @Test - public void test_LOCALIZED_NO_GROUPING_print() { + void test_LOCALIZED_NO_GROUPING_print() { MoneyAmountStyle style = MoneyAmountStyle.LOCALIZED_NO_GROUPING; MoneyFormatter test = new MoneyFormatterBuilder().appendAmount(style).toFormatter(); assertEquals("87654321.12345678", test.print(MONEY)); } @Test - public void test_print_groupBeforeDecimal() { + void test_print_groupBeforeDecimal() { MoneyAmountStyle style = MoneyAmountStyle.LOCALIZED_GROUPING.withGroupingStyle(GroupingStyle.BEFORE_DECIMAL_POINT); MoneyFormatter test = new MoneyFormatterBuilder().appendAmount(style).toFormatter(); assertEquals("87,654,321.12345678", test.print(MONEY)); @@ -231,7 +234,7 @@ public void test_print_groupBeforeDecimal() { // of(Locale) //----------------------------------------------------------------------- @Test - public void test_of_Locale_GB() { + void test_of_Locale_GB() { MoneyAmountStyle style = MoneyAmountStyle.of(TEST_GB_LOCALE); assertEquals((Character) '0', style.getZeroCharacter()); assertEquals((Character) '+', style.getPositiveSignCharacter()); @@ -241,11 +244,11 @@ public void test_of_Locale_GB() { assertEquals(GroupingStyle.FULL, style.getGroupingStyle()); assertEquals((Integer) 3, style.getGroupingSize()); assertEquals((Integer) 0, style.getExtendedGroupingSize()); - assertEquals(false, style.isForcedDecimalPoint()); + assertFalse(style.isForcedDecimalPoint()); } @Test - public void test_of_Locale_DE() { + void test_of_Locale_DE() { MoneyAmountStyle style = MoneyAmountStyle.of(TEST_DE_LOCALE); assertEquals((Character) '0', style.getZeroCharacter()); assertEquals((Character) '+', style.getPositiveSignCharacter()); @@ -255,14 +258,14 @@ public void test_of_Locale_DE() { assertEquals(GroupingStyle.FULL, style.getGroupingStyle()); assertEquals((Integer) 3, style.getGroupingSize()); assertEquals((Integer) 0, style.getExtendedGroupingSize()); - assertEquals(false, style.isForcedDecimalPoint()); + assertFalse(style.isForcedDecimalPoint()); } //----------------------------------------------------------------------- // localize(Locale) //----------------------------------------------------------------------- @Test - public void test_localize_GB() { + void test_localize_GB() { MoneyAmountStyle style = MoneyAmountStyle.LOCALIZED_GROUPING.localize(TEST_GB_LOCALE); assertEquals((Character) '0', style.getZeroCharacter()); assertEquals((Character) '+', style.getPositiveSignCharacter()); @@ -272,11 +275,11 @@ public void test_localize_GB() { assertEquals(GroupingStyle.FULL, style.getGroupingStyle()); assertEquals((Integer) 3, style.getGroupingSize()); assertEquals((Integer) 0, style.getExtendedGroupingSize()); - assertEquals(false, style.isForcedDecimalPoint()); + assertFalse(style.isForcedDecimalPoint()); } @Test - public void test_localize_DE() { + void test_localize_DE() { MoneyAmountStyle style = MoneyAmountStyle.LOCALIZED_GROUPING.localize(TEST_DE_LOCALE); assertEquals((Character) '0', style.getZeroCharacter()); assertEquals((Character) '+', style.getPositiveSignCharacter()); @@ -286,11 +289,11 @@ public void test_localize_DE() { assertEquals(GroupingStyle.FULL, style.getGroupingStyle()); assertEquals((Integer) 3, style.getGroupingSize()); assertEquals((Integer) 0, style.getExtendedGroupingSize()); - assertEquals(false, style.isForcedDecimalPoint()); + assertFalse(style.isForcedDecimalPoint()); } @Test - public void test_localize_DE_fixedZero() { + void test_localize_DE_fixedZero() { MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING.withZeroCharacter('_'); MoneyAmountStyle style = base.localize(TEST_DE_LOCALE); assertEquals((Character) '_', style.getZeroCharacter()); @@ -301,11 +304,11 @@ public void test_localize_DE_fixedZero() { assertEquals(GroupingStyle.FULL, style.getGroupingStyle()); assertEquals((Integer) 3, style.getGroupingSize()); assertEquals((Integer) 0, style.getExtendedGroupingSize()); - assertEquals(false, style.isForcedDecimalPoint()); + assertFalse(style.isForcedDecimalPoint()); } @Test - public void test_localize_DE_fixedPositive() { + void test_localize_DE_fixedPositive() { MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING.withPositiveSignCharacter('_'); MoneyAmountStyle style = base.localize(TEST_DE_LOCALE); assertEquals((Character) '0', style.getZeroCharacter()); @@ -316,11 +319,11 @@ public void test_localize_DE_fixedPositive() { assertEquals(GroupingStyle.FULL, style.getGroupingStyle()); assertEquals((Integer) 3, style.getGroupingSize()); assertEquals((Integer) 0, style.getExtendedGroupingSize()); - assertEquals(false, style.isForcedDecimalPoint()); + assertFalse(style.isForcedDecimalPoint()); } @Test - public void test_localize_DE_fixedNegative() { + void test_localize_DE_fixedNegative() { MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING.withNegativeSignCharacter('_'); MoneyAmountStyle style = base.localize(TEST_DE_LOCALE); assertEquals((Character) '0', style.getZeroCharacter()); @@ -331,11 +334,11 @@ public void test_localize_DE_fixedNegative() { assertEquals(GroupingStyle.FULL, style.getGroupingStyle()); assertEquals((Integer) 3, style.getGroupingSize()); assertEquals((Integer) 0, style.getExtendedGroupingSize()); - assertEquals(false, style.isForcedDecimalPoint()); + assertFalse(style.isForcedDecimalPoint()); } @Test - public void test_localize_DE_fixedDecimal() { + void test_localize_DE_fixedDecimal() { MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING.withDecimalPointCharacter('_'); MoneyAmountStyle style = base.localize(TEST_DE_LOCALE); assertEquals((Character) '0', style.getZeroCharacter()); @@ -346,11 +349,11 @@ public void test_localize_DE_fixedDecimal() { assertEquals(GroupingStyle.FULL, style.getGroupingStyle()); assertEquals((Integer) 3, style.getGroupingSize()); assertEquals((Integer) 0, style.getExtendedGroupingSize()); - assertEquals(false, style.isForcedDecimalPoint()); + assertFalse(style.isForcedDecimalPoint()); } @Test - public void test_localize_DE_fixedGrouping() { + void test_localize_DE_fixedGrouping() { MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING.withGroupingCharacter('_'); MoneyAmountStyle style = base.localize(TEST_DE_LOCALE); assertEquals((Character) '0', style.getZeroCharacter()); @@ -361,11 +364,11 @@ public void test_localize_DE_fixedGrouping() { assertEquals(GroupingStyle.FULL, style.getGroupingStyle()); assertEquals((Integer) 3, style.getGroupingSize()); assertEquals((Integer) 0, style.getExtendedGroupingSize()); - assertEquals(false, style.isForcedDecimalPoint()); + assertFalse(style.isForcedDecimalPoint()); } @Test - public void test_localize_DE_fixedZeroAndDecimal() { + void test_localize_DE_fixedZeroAndDecimal() { MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING.withZeroCharacter('_').withDecimalPointCharacter('-'); MoneyAmountStyle style = base.localize(TEST_DE_LOCALE); assertEquals((Character) '_', style.getZeroCharacter()); @@ -376,11 +379,11 @@ public void test_localize_DE_fixedZeroAndDecimal() { assertEquals(GroupingStyle.FULL, style.getGroupingStyle()); assertEquals((Integer) 3, style.getGroupingSize()); assertEquals((Integer) 0, style.getExtendedGroupingSize()); - assertEquals(false, style.isForcedDecimalPoint()); + assertFalse(style.isForcedDecimalPoint()); } @Test - public void test_localize_DE_noGrouping() { + void test_localize_DE_noGrouping() { MoneyAmountStyle style = MoneyAmountStyle.LOCALIZED_NO_GROUPING.localize(TEST_DE_LOCALE); assertEquals((Character) '0', style.getZeroCharacter()); assertEquals((Character) '+', style.getPositiveSignCharacter()); @@ -390,11 +393,11 @@ public void test_localize_DE_noGrouping() { assertEquals(GroupingStyle.NONE, style.getGroupingStyle()); assertEquals((Integer) 3, style.getGroupingSize()); assertEquals((Integer) 0, style.getExtendedGroupingSize()); - assertEquals(false, style.isForcedDecimalPoint()); + assertFalse(style.isForcedDecimalPoint()); } @Test - public void test_localize_LV() { + void test_localize_LV() { MoneyAmountStyle style = MoneyAmountStyle.LOCALIZED_NO_GROUPING.localize(TEST_LV_LOCALE); assertEquals((Character) '0', style.getZeroCharacter()); assertEquals((Character) '+', style.getPositiveSignCharacter()); @@ -404,23 +407,23 @@ public void test_localize_LV() { assertEquals(GroupingStyle.NONE, style.getGroupingStyle()); assertEquals((Integer) 3, style.getGroupingSize()); assertEquals((Integer) 0, style.getExtendedGroupingSize()); - assertEquals(false, style.isForcedDecimalPoint()); + assertFalse(style.isForcedDecimalPoint()); } //----------------------------------------------------------------------- // With //----------------------------------------------------------------------- @Test - public void test_withZeroCharacter() { + void test_withZeroCharacter() { MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING; - assertEquals(null, base.getZeroCharacter()); + assertNull(base.getZeroCharacter()); MoneyAmountStyle test = base.withZeroCharacter('_'); - assertEquals(null, base.getZeroCharacter()); + assertNull(base.getZeroCharacter()); assertEquals((Character) '_', test.getZeroCharacter()); } @Test - public void test_withZeroCharacter_same() { + void test_withZeroCharacter_same() { MoneyAmountStyle base = MoneyAmountStyle.ASCII_DECIMAL_POINT_GROUP3_COMMA; assertEquals((Character) '0', base.getZeroCharacter()); MoneyAmountStyle test = base.withZeroCharacter('0'); @@ -428,25 +431,25 @@ public void test_withZeroCharacter_same() { } @Test - public void test_withZeroCharacter_sameNull() { + void test_withZeroCharacter_sameNull() { MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING; - assertEquals(null, base.getZeroCharacter()); + assertNull(base.getZeroCharacter()); MoneyAmountStyle test = base.withZeroCharacter(null); assertSame(base, test); } //----------------------------------------------------------------------- @Test - public void test_withPositiveSignCharacter() { + void test_withPositiveSignCharacter() { MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING; - assertEquals(null, base.getPositiveSignCharacter()); + assertNull(base.getPositiveSignCharacter()); MoneyAmountStyle test = base.withPositiveSignCharacter('_'); - assertEquals(null, base.getPositiveSignCharacter()); + assertNull(base.getPositiveSignCharacter()); assertEquals((Character) '_', test.getPositiveSignCharacter()); } @Test - public void test_withPositiveSignCharacter_same() { + void test_withPositiveSignCharacter_same() { MoneyAmountStyle base = MoneyAmountStyle.ASCII_DECIMAL_POINT_GROUP3_COMMA; assertEquals((Character) '+', base.getPositiveSignCharacter()); MoneyAmountStyle test = base.withPositiveSignCharacter('+'); @@ -454,25 +457,25 @@ public void test_withPositiveSignCharacter_same() { } @Test - public void test_withPositiveSignCharacter_sameNull() { + void test_withPositiveSignCharacter_sameNull() { MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING; - assertEquals(null, base.getPositiveSignCharacter()); + assertNull(base.getPositiveSignCharacter()); MoneyAmountStyle test = base.withPositiveSignCharacter(null); assertSame(base, test); } //----------------------------------------------------------------------- @Test - public void test_withNegativeSignCharacter() { + void test_withNegativeSignCharacter() { MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING; - assertEquals(null, base.getNegativeSignCharacter()); + assertNull(base.getNegativeSignCharacter()); MoneyAmountStyle test = base.withNegativeSignCharacter('_'); - assertEquals(null, base.getNegativeSignCharacter()); + assertNull(base.getNegativeSignCharacter()); assertEquals((Character) '_', test.getNegativeSignCharacter()); } @Test - public void test_withNegativeSignCharacter_same() { + void test_withNegativeSignCharacter_same() { MoneyAmountStyle base = MoneyAmountStyle.ASCII_DECIMAL_POINT_GROUP3_COMMA; assertEquals((Character) '-', base.getNegativeSignCharacter()); MoneyAmountStyle test = base.withNegativeSignCharacter('-'); @@ -480,25 +483,25 @@ public void test_withNegativeSignCharacter_same() { } @Test - public void test_withNegativeSignCharacter_sameNull() { + void test_withNegativeSignCharacter_sameNull() { MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING; - assertEquals(null, base.getNegativeSignCharacter()); + assertNull(base.getNegativeSignCharacter()); MoneyAmountStyle test = base.withNegativeSignCharacter(null); assertSame(base, test); } //----------------------------------------------------------------------- @Test - public void test_withDecimalPointCharacter() { + void test_withDecimalPointCharacter() { MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING; - assertEquals(null, base.getDecimalPointCharacter()); + assertNull(base.getDecimalPointCharacter()); MoneyAmountStyle test = base.withDecimalPointCharacter('_'); - assertEquals(null, base.getDecimalPointCharacter()); + assertNull(base.getDecimalPointCharacter()); assertEquals((Character) '_', test.getDecimalPointCharacter()); } @Test - public void test_withDecimalPointCharacter_same() { + void test_withDecimalPointCharacter_same() { MoneyAmountStyle base = MoneyAmountStyle.ASCII_DECIMAL_POINT_GROUP3_COMMA; assertEquals((Character) '.', base.getDecimalPointCharacter()); MoneyAmountStyle test = base.withDecimalPointCharacter('.'); @@ -506,25 +509,25 @@ public void test_withDecimalPointCharacter_same() { } @Test - public void test_withDecimalPointCharacter_sameNull() { + void test_withDecimalPointCharacter_sameNull() { MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING; - assertEquals(null, base.getDecimalPointCharacter()); + assertNull(base.getDecimalPointCharacter()); MoneyAmountStyle test = base.withDecimalPointCharacter(null); assertSame(base, test); } //----------------------------------------------------------------------- @Test - public void test_withGroupingCharacter() { + void test_withGroupingCharacter() { MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING; - assertEquals(null, base.getGroupingCharacter()); + assertNull(base.getGroupingCharacter()); MoneyAmountStyle test = base.withGroupingCharacter('_'); - assertEquals(null, base.getGroupingCharacter()); + assertNull(base.getGroupingCharacter()); assertEquals((Character) '_', test.getGroupingCharacter()); } @Test - public void test_withGroupingCharacter_same() { + void test_withGroupingCharacter_same() { MoneyAmountStyle base = MoneyAmountStyle.ASCII_DECIMAL_POINT_GROUP3_COMMA; assertEquals((Character) ',', base.getGroupingCharacter()); MoneyAmountStyle test = base.withGroupingCharacter(','); @@ -532,16 +535,16 @@ public void test_withGroupingCharacter_same() { } @Test - public void test_withGroupingCharacter_sameNull() { + void test_withGroupingCharacter_sameNull() { MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING; - assertEquals(null, base.getGroupingCharacter()); + assertNull(base.getGroupingCharacter()); MoneyAmountStyle test = base.withGroupingCharacter(null); assertSame(base, test); } //----------------------------------------------------------------------- @Test - public void test_withGroupingStyle() { + void test_withGroupingStyle() { MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING; assertEquals(GroupingStyle.FULL, base.getGroupingStyle()); MoneyAmountStyle test = base.withGroupingStyle(GroupingStyle.BEFORE_DECIMAL_POINT); @@ -550,7 +553,7 @@ public void test_withGroupingStyle() { } @Test - public void test_withGroupingStyle_same() { + void test_withGroupingStyle_same() { MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING; assertEquals(GroupingStyle.FULL, base.getGroupingStyle()); MoneyAmountStyle test = base.withGroupingStyle(GroupingStyle.FULL); @@ -559,16 +562,16 @@ public void test_withGroupingStyle_same() { //----------------------------------------------------------------------- @Test - public void test_withGroupingSize() { + void test_withGroupingSize() { MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING; - assertEquals(null, base.getGroupingSize()); + assertNull(base.getGroupingSize()); MoneyAmountStyle test = base.withGroupingSize(6); - assertEquals(null, base.getGroupingSize()); + assertNull(base.getGroupingSize()); assertEquals((Integer) 6, test.getGroupingSize()); } @Test - public void test_withGroupingSize_same() { + void test_withGroupingSize_same() { MoneyAmountStyle base = MoneyAmountStyle.ASCII_DECIMAL_POINT_GROUP3_COMMA; assertEquals((Integer) 3, base.getGroupingSize()); MoneyAmountStyle test = base.withGroupingSize(3); @@ -576,51 +579,53 @@ public void test_withGroupingSize_same() { } @Test - public void test_withGroupingSize_sameNull() { + void test_withGroupingSize_sameNull() { MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING; - assertEquals(null, base.getGroupingSize()); + assertNull(base.getGroupingSize()); MoneyAmountStyle test = base.withGroupingSize(null); assertSame(base, test); } - @Test(expected = IllegalArgumentException.class) - public void test_withGroupingSize_negative() { + @Test + void test_withGroupingSize_negative() { MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING; - base.withGroupingSize(-1); + assertThrows(IllegalArgumentException.class, () -> { + base.withGroupingSize(-1); + }); } //----------------------------------------------------------------------- @Test - public void test_withForcedDecimalPoint() { + void test_withForcedDecimalPoint() { MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING; - assertEquals(false, base.isForcedDecimalPoint()); + assertFalse(base.isForcedDecimalPoint()); MoneyAmountStyle test = base.withForcedDecimalPoint(true); - assertEquals(false, base.isForcedDecimalPoint()); - assertEquals(true, test.isForcedDecimalPoint()); + assertFalse(base.isForcedDecimalPoint()); + assertTrue(test.isForcedDecimalPoint()); } @Test - public void test_withForcedDecimalPoint_same() { + void test_withForcedDecimalPoint_same() { MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING; - assertEquals(false, base.isForcedDecimalPoint()); + assertFalse(base.isForcedDecimalPoint()); MoneyAmountStyle test = base.withForcedDecimalPoint(false); assertSame(base, test); } //----------------------------------------------------------------------- @Test - public void test_withAbsValue() { + void test_withAbsValue() { MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING; - assertEquals(false, base.isAbsValue()); + assertFalse(base.isAbsValue()); MoneyAmountStyle test = base.withAbsValue(true); - assertEquals(false, base.isAbsValue()); - assertEquals(true, test.isAbsValue()); + assertFalse(base.isAbsValue()); + assertTrue(test.isAbsValue()); } @Test - public void test_withAbsValue_same() { + void test_withAbsValue_same() { MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING; - assertEquals(false, base.isAbsValue()); + assertFalse(base.isAbsValue()); MoneyAmountStyle test = base.withAbsValue(false); assertSame(base, test); } @@ -629,197 +634,197 @@ public void test_withAbsValue_same() { // equals //----------------------------------------------------------------------- @Test - public void test_equals_same() { + void test_equals_same() { MoneyAmountStyle a = MoneyAmountStyle.LOCALIZED_GROUPING; - assertEquals(true, a.equals(a)); + assertTrue(a.equals(a)); } @Test - public void test_equals_otherType() { + void test_equals_otherType() { MoneyAmountStyle a = MoneyAmountStyle.LOCALIZED_GROUPING; - assertEquals(false, a.equals(new Object())); + assertFalse(a.equals(new Object())); } @Test - public void test_equals_null() { + void test_equals_null() { MoneyAmountStyle a = MoneyAmountStyle.LOCALIZED_GROUPING; - assertEquals(false, a.equals(null)); + assertFalse(a.equals(null)); } @Test - public void test_equals_equal_zeroChar() { + void test_equals_equal_zeroChar() { MoneyAmountStyle a = MoneyAmountStyle.LOCALIZED_GROUPING.withZeroCharacter('_'); MoneyAmountStyle b = MoneyAmountStyle.LOCALIZED_GROUPING.withZeroCharacter('_'); - assertEquals(true, a.equals(b)); - assertEquals(true, b.equals(a)); + assertTrue(a.equals(b)); + assertTrue(b.equals(a)); assertEquals(b.hashCode(), a.hashCode()); } @Test - public void test_equals_notEqual_zeroChar() { + void test_equals_notEqual_zeroChar() { MoneyAmountStyle a = MoneyAmountStyle.LOCALIZED_GROUPING; MoneyAmountStyle b = MoneyAmountStyle.LOCALIZED_GROUPING.withZeroCharacter('_'); - assertEquals(false, a.equals(b)); - assertEquals(false, b.equals(a)); + assertFalse(a.equals(b)); + assertFalse(b.equals(a)); } @Test - public void test_equals_equal_positiveChar() { + void test_equals_equal_positiveChar() { MoneyAmountStyle a = MoneyAmountStyle.LOCALIZED_GROUPING.withPositiveSignCharacter('_'); MoneyAmountStyle b = MoneyAmountStyle.LOCALIZED_GROUPING.withPositiveSignCharacter('_'); - assertEquals(true, a.equals(b)); - assertEquals(true, b.equals(a)); + assertTrue(a.equals(b)); + assertTrue(b.equals(a)); assertEquals(b.hashCode(), a.hashCode()); } @Test - public void test_equals_notEqual_positiveChar() { + void test_equals_notEqual_positiveChar() { MoneyAmountStyle a = MoneyAmountStyle.LOCALIZED_GROUPING; MoneyAmountStyle b = MoneyAmountStyle.LOCALIZED_GROUPING.withPositiveSignCharacter('_'); - assertEquals(false, a.equals(b)); - assertEquals(false, b.equals(a)); + assertFalse(a.equals(b)); + assertFalse(b.equals(a)); } @Test - public void test_equals_equal_negativeChar() { + void test_equals_equal_negativeChar() { MoneyAmountStyle a = MoneyAmountStyle.LOCALIZED_GROUPING.withNegativeSignCharacter('_'); MoneyAmountStyle b = MoneyAmountStyle.LOCALIZED_GROUPING.withNegativeSignCharacter('_'); - assertEquals(true, a.equals(b)); - assertEquals(true, b.equals(a)); + assertTrue(a.equals(b)); + assertTrue(b.equals(a)); assertEquals(b.hashCode(), a.hashCode()); } @Test - public void test_equals_notEqual_negativeChar() { + void test_equals_notEqual_negativeChar() { MoneyAmountStyle a = MoneyAmountStyle.LOCALIZED_GROUPING; MoneyAmountStyle b = MoneyAmountStyle.LOCALIZED_GROUPING.withNegativeSignCharacter('_'); - assertEquals(false, a.equals(b)); - assertEquals(false, b.equals(a)); + assertFalse(a.equals(b)); + assertFalse(b.equals(a)); } @Test - public void test_equals_equal_decimalPointChar() { + void test_equals_equal_decimalPointChar() { MoneyAmountStyle a = MoneyAmountStyle.LOCALIZED_GROUPING.withDecimalPointCharacter('_'); MoneyAmountStyle b = MoneyAmountStyle.LOCALIZED_GROUPING.withDecimalPointCharacter('_'); - assertEquals(true, a.equals(b)); - assertEquals(true, b.equals(a)); + assertTrue(a.equals(b)); + assertTrue(b.equals(a)); assertEquals(b.hashCode(), a.hashCode()); } @Test - public void test_equals_notEqual_decimalPointChar() { + void test_equals_notEqual_decimalPointChar() { MoneyAmountStyle a = MoneyAmountStyle.LOCALIZED_GROUPING; MoneyAmountStyle b = MoneyAmountStyle.LOCALIZED_GROUPING.withDecimalPointCharacter('_'); - assertEquals(false, a.equals(b)); - assertEquals(false, b.equals(a)); + assertFalse(a.equals(b)); + assertFalse(b.equals(a)); } @Test - public void test_equals_equal_groupingChar() { + void test_equals_equal_groupingChar() { MoneyAmountStyle a = MoneyAmountStyle.LOCALIZED_GROUPING.withGroupingCharacter('_'); MoneyAmountStyle b = MoneyAmountStyle.LOCALIZED_GROUPING.withGroupingCharacter('_'); - assertEquals(true, a.equals(b)); - assertEquals(true, b.equals(a)); + assertTrue(a.equals(b)); + assertTrue(b.equals(a)); assertEquals(b.hashCode(), a.hashCode()); } @Test - public void test_equals_notEqual_groupingChar() { + void test_equals_notEqual_groupingChar() { MoneyAmountStyle a = MoneyAmountStyle.LOCALIZED_GROUPING; MoneyAmountStyle b = MoneyAmountStyle.LOCALIZED_GROUPING.withGroupingCharacter('_'); - assertEquals(false, a.equals(b)); - assertEquals(false, b.equals(a)); + assertFalse(a.equals(b)); + assertFalse(b.equals(a)); } @Test - public void test_equals_equal_groupingStyle() { + void test_equals_equal_groupingStyle() { MoneyAmountStyle a = MoneyAmountStyle.LOCALIZED_GROUPING.withGroupingStyle(GroupingStyle.BEFORE_DECIMAL_POINT); MoneyAmountStyle b = MoneyAmountStyle.LOCALIZED_GROUPING.withGroupingStyle(GroupingStyle.BEFORE_DECIMAL_POINT); - assertEquals(true, a.equals(b)); - assertEquals(true, b.equals(a)); + assertTrue(a.equals(b)); + assertTrue(b.equals(a)); assertEquals(b.hashCode(), a.hashCode()); } @Test - public void test_equals_notEqual_groupingStyle() { + void test_equals_notEqual_groupingStyle() { MoneyAmountStyle a = MoneyAmountStyle.LOCALIZED_GROUPING.withGroupingStyle(GroupingStyle.BEFORE_DECIMAL_POINT); MoneyAmountStyle b = MoneyAmountStyle.LOCALIZED_GROUPING.withGroupingStyle(GroupingStyle.NONE); - assertEquals(false, a.equals(b)); - assertEquals(false, b.equals(a)); + assertFalse(a.equals(b)); + assertFalse(b.equals(a)); } @Test - public void test_equals_equal_groupingSize() { + void test_equals_equal_groupingSize() { MoneyAmountStyle a = MoneyAmountStyle.LOCALIZED_GROUPING.withGroupingSize(4); MoneyAmountStyle b = MoneyAmountStyle.LOCALIZED_GROUPING.withGroupingSize(4); - assertEquals(true, a.equals(b)); - assertEquals(true, b.equals(a)); + assertTrue(a.equals(b)); + assertTrue(b.equals(a)); assertEquals(b.hashCode(), a.hashCode()); } @Test - public void test_equals_notEqual_groupingSize() { + void test_equals_notEqual_groupingSize() { MoneyAmountStyle a = MoneyAmountStyle.LOCALIZED_GROUPING; MoneyAmountStyle b = MoneyAmountStyle.LOCALIZED_GROUPING.withGroupingSize(4); - assertEquals(false, a.equals(b)); - assertEquals(false, b.equals(a)); + assertFalse(a.equals(b)); + assertFalse(b.equals(a)); } @Test - public void test_equals_equal_forcedDecimalPoint_false() { + void test_equals_equal_forcedDecimalPoint_false() { MoneyAmountStyle a = MoneyAmountStyle.LOCALIZED_GROUPING.withForcedDecimalPoint(true).withForcedDecimalPoint(false); MoneyAmountStyle b = MoneyAmountStyle.LOCALIZED_GROUPING.withForcedDecimalPoint(true).withForcedDecimalPoint(false); - assertEquals(true, a.equals(b)); - assertEquals(true, b.equals(a)); + assertTrue(a.equals(b)); + assertTrue(b.equals(a)); assertEquals(b.hashCode(), a.hashCode()); } @Test - public void test_equals_equal_forcedDecimalPoint_true() { + void test_equals_equal_forcedDecimalPoint_true() { MoneyAmountStyle a = MoneyAmountStyle.LOCALIZED_GROUPING.withForcedDecimalPoint(true); MoneyAmountStyle b = MoneyAmountStyle.LOCALIZED_GROUPING.withForcedDecimalPoint(true); - assertEquals(true, a.equals(b)); - assertEquals(true, b.equals(a)); + assertTrue(a.equals(b)); + assertTrue(b.equals(a)); assertEquals(b.hashCode(), a.hashCode()); } @Test - public void test_equals_notEqual_forcedDecimalPoint() { + void test_equals_notEqual_forcedDecimalPoint() { MoneyAmountStyle a = MoneyAmountStyle.LOCALIZED_GROUPING; MoneyAmountStyle b = MoneyAmountStyle.LOCALIZED_GROUPING.withForcedDecimalPoint(true); - assertEquals(false, a.equals(b)); - assertEquals(false, b.equals(a)); + assertFalse(a.equals(b)); + assertFalse(b.equals(a)); } @Test - public void test_equals_equal_absValue_false() { + void test_equals_equal_absValue_false() { MoneyAmountStyle a = MoneyAmountStyle.LOCALIZED_GROUPING.withAbsValue(true).withAbsValue(false); MoneyAmountStyle b = MoneyAmountStyle.LOCALIZED_GROUPING.withAbsValue(true).withAbsValue(false); - assertEquals(true, a.equals(b)); - assertEquals(true, b.equals(a)); + assertTrue(a.equals(b)); + assertTrue(b.equals(a)); assertEquals(b.hashCode(), a.hashCode()); } @Test - public void test_equals_equal_absValue_true() { + void test_equals_equal_absValue_true() { MoneyAmountStyle a = MoneyAmountStyle.LOCALIZED_GROUPING.withAbsValue(true); MoneyAmountStyle b = MoneyAmountStyle.LOCALIZED_GROUPING.withAbsValue(true); - assertEquals(true, a.equals(b)); - assertEquals(true, b.equals(a)); + assertTrue(a.equals(b)); + assertTrue(b.equals(a)); assertEquals(b.hashCode(), a.hashCode()); } @Test - public void test_equals_notEqual_absValue() { + void test_equals_notEqual_absValue() { MoneyAmountStyle a = MoneyAmountStyle.LOCALIZED_GROUPING; MoneyAmountStyle b = MoneyAmountStyle.LOCALIZED_GROUPING.withAbsValue(true); - assertEquals(false, a.equals(b)); - assertEquals(false, b.equals(a)); + assertFalse(a.equals(b)); + assertFalse(b.equals(a)); } //----------------------------------------------------------------------- @Test - public void test_toString() { + void test_toString() { MoneyAmountStyle test = MoneyAmountStyle.LOCALIZED_GROUPING; assertTrue(test.toString().startsWith("MoneyAmountStyle")); } diff --git a/src/test/java/org/joda/money/format/TestMoneyFormatter.java b/src/test/java/org/joda/money/format/TestMoneyFormatter.java index 100c75e..b4681ae 100644 --- a/src/test/java/org/joda/money/format/TestMoneyFormatter.java +++ b/src/test/java/org/joda/money/format/TestMoneyFormatter.java @@ -15,7 +15,11 @@ */ package org.joda.money.format; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -30,20 +34,16 @@ import org.joda.money.BigMoneyProvider; import org.joda.money.CurrencyUnit; import org.joda.money.Money; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; - -import com.tngtech.java.junit.dataprovider.DataProvider; -import com.tngtech.java.junit.dataprovider.DataProviderRunner; -import com.tngtech.java.junit.dataprovider.UseDataProvider; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; /** * Test MoneyFormatter. */ -@RunWith(DataProviderRunner.class) -public class TestMoneyFormatter { +class TestMoneyFormatter { private static final Locale cCachedLocale = Locale.getDefault(); private static final Locale TEST_GB_LOCALE = new Locale("en", "GB", "TEST"); @@ -54,8 +54,8 @@ public class TestMoneyFormatter { private MoneyFormatter iParseTest; private MoneyFormatter iCannotParse; - @Before - public void beforeMethod() { + @BeforeEach + void beforeMethod() { Locale.setDefault(TEST_GB_LOCALE); iPrintTest = new MoneyFormatterBuilder() .appendCurrencyCode() @@ -82,8 +82,8 @@ public void print(MoneyPrintContext context, Appendable appendable, BigMoney mon .toFormatter(); } - @After - public void afterMethod() { + @AfterEach + void afterMethod() { Locale.setDefault(cCachedLocale); iPrintTest = null; } @@ -92,7 +92,7 @@ public void afterMethod() { // serialization //----------------------------------------------------------------------- @Test - public void test_serialization() throws Exception { + void test_serialization() throws Exception { MoneyFormatter a = iPrintTest; ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (ObjectOutputStream oos = new ObjectOutputStream(baos)) { @@ -109,197 +109,244 @@ public void test_serialization() throws Exception { // getLocale() withLocale(Locale) //----------------------------------------------------------------------- @Test - public void test_getLocale() { + void test_getLocale() { assertEquals(TEST_GB_LOCALE, iPrintTest.getLocale()); } @Test - public void test_withLocale() { + void test_withLocale() { MoneyFormatter test = iPrintTest.withLocale(TEST_FR_LOCALE); assertEquals(TEST_GB_LOCALE, iPrintTest.getLocale()); assertEquals(TEST_FR_LOCALE, test.getLocale()); } - @Test(expected = NullPointerException.class) - public void test_withLocale_nullLocale() { - iPrintTest.withLocale((Locale) null); + @Test + void test_withLocale_nullLocale() { + assertThrows(NullPointerException.class, () -> { + iPrintTest.withLocale((Locale) null); + }); } //----------------------------------------------------------------------- // print(BigMoneyProvider) //----------------------------------------------------------------------- @Test - public void test_print_BigMoneyProvider() { + void test_print_BigMoneyProvider() { assertEquals("GBP hello", iPrintTest.print(MONEY_GBP_12_34)); } - @Test(expected = UnsupportedOperationException.class) - public void test_print_BigMoneyProvider_cannotPrint() { - iCannotPrint.print(MONEY_GBP_12_34); + @Test + void test_print_BigMoneyProvider_cannotPrint() { + assertThrows(UnsupportedOperationException.class, () -> { + iCannotPrint.print(MONEY_GBP_12_34); + }); } - @Test(expected = NullPointerException.class) - public void test_print_BigMoneyProvider_nullBigMoneyProvider() { - iPrintTest.print((BigMoneyProvider) null); + @Test + void test_print_BigMoneyProvider_nullBigMoneyProvider() { + assertThrows(NullPointerException.class, () -> { + iPrintTest.print((BigMoneyProvider) null); + }); } //----------------------------------------------------------------------- // print(Appendable,BigMoneyProvider) //----------------------------------------------------------------------- @Test - public void test_print_AppendableBigMoneyProvider() { + void test_print_AppendableBigMoneyProvider() { StringBuilder buf = new StringBuilder(); iPrintTest.print(buf, MONEY_GBP_12_34); assertEquals("GBP hello", buf.toString()); } - @Test(expected = MoneyFormatException.class) - public void test_print_AppendableBigMoneyProvider_IOException() { - Appendable appendable = new IOAppendable(); - try { - iPrintTest.print(appendable, MONEY_GBP_12_34); - } catch (MoneyFormatException ex) { - assertEquals(IOException.class, ex.getCause().getClass()); - throw ex; - } + @Test + void test_print_AppendableBigMoneyProvider_IOException() { + assertThrows(MoneyFormatException.class, () -> { + Appendable appendable = new IOAppendable(); + try { + iPrintTest.print(appendable, MONEY_GBP_12_34); + } catch (MoneyFormatException ex) { + assertEquals(IOException.class, ex.getCause().getClass()); + throw ex; + } + }); } - @Test(expected = UnsupportedOperationException.class) - public void test_print_AppendableBigMoneyProvider_cannotPrint() { - iCannotPrint.print(new StringBuilder(), MONEY_GBP_12_34); + @Test + void test_print_AppendableBigMoneyProvider_cannotPrint() { + assertThrows(UnsupportedOperationException.class, () -> { + iCannotPrint.print(new StringBuilder(), MONEY_GBP_12_34); + }); } - @Test(expected = NullPointerException.class) - public void test_print_AppendableBigMoneyProvider_nullAppendable() { - iPrintTest.print((Appendable) null, MONEY_GBP_12_34); + @Test + void test_print_AppendableBigMoneyProvider_nullAppendable() { + assertThrows(NullPointerException.class, () -> { + iPrintTest.print((Appendable) null, MONEY_GBP_12_34); + }); } - @Test(expected = NullPointerException.class) - public void test_print_AppendableBigMoneyProvider_nullBigMoneyProvider() { - iPrintTest.print(new StringBuilder(), (BigMoneyProvider) null); + @Test + void test_print_AppendableBigMoneyProvider_nullBigMoneyProvider() { + assertThrows(NullPointerException.class, () -> { + iPrintTest.print(new StringBuilder(), (BigMoneyProvider) null); + }); } //----------------------------------------------------------------------- // printIO(Appendable,BigMoneyProvider) //----------------------------------------------------------------------- @Test - public void test_printIO_AppendableBigMoneyProvider() throws IOException { + void test_printIO_AppendableBigMoneyProvider() throws IOException { StringBuilder buf = new StringBuilder(); iPrintTest.printIO(buf, MONEY_GBP_12_34); assertEquals("GBP hello", buf.toString()); } - @Test(expected = IOException.class) - public void test_printIO_AppendableBigMoneyProvider_IOException() throws IOException { + @Test + void test_printIO_AppendableBigMoneyProvider_IOException() { Appendable appendable = new IOAppendable(); - iPrintTest.printIO(appendable, MONEY_GBP_12_34); + assertThrows(IOException.class, () -> { + iPrintTest.printIO(appendable, MONEY_GBP_12_34); + }); } - @Test(expected = UnsupportedOperationException.class) - public void test_printIO_AppendableBigMoneyProvider_cannotPrint() throws IOException { - iCannotPrint.printIO(new StringBuilder(), MONEY_GBP_12_34); + @Test + void test_printIO_AppendableBigMoneyProvider_cannotPrint() { + assertThrows(UnsupportedOperationException.class, () -> { + iCannotPrint.printIO(new StringBuilder(), MONEY_GBP_12_34); + }); } - @Test(expected = NullPointerException.class) - public void test_printIO_AppendableBigMoneyProvider_nullAppendable() throws IOException { - iPrintTest.printIO((Appendable) null, MONEY_GBP_12_34); + @Test + void test_printIO_AppendableBigMoneyProvider_nullAppendable() { + assertThrows(NullPointerException.class, () -> { + iPrintTest.printIO((Appendable) null, MONEY_GBP_12_34); + }); } - @Test(expected = NullPointerException.class) - public void test_printIO_AppendableBigMoneyProvider_nullBigMoneyProvider() throws IOException { - iPrintTest.printIO(new StringBuilder(), (BigMoneyProvider) null); + @Test + void test_printIO_AppendableBigMoneyProvider_nullBigMoneyProvider() { + assertThrows(NullPointerException.class, () -> { + iPrintTest.printIO(new StringBuilder(), (BigMoneyProvider) null); + }); } //----------------------------------------------------------------------- // parseBigMoney(CharSequence) //----------------------------------------------------------------------- @Test - public void test_parseBigMoney_CharSequence() { + void test_parseBigMoney_CharSequence() { CharSequence input = new StringBuilder("12.34 GBP"); BigMoney test = iParseTest.parseBigMoney(input); assertEquals(MONEY_GBP_12_34.toBigMoney(), test); } - @Test(expected = MoneyFormatException.class) - public void test_parseBigMoney_CharSequence_invalidCurrency() { - iParseTest.parseBigMoney("12.34 GBX"); + @Test + void test_parseBigMoney_CharSequence_invalidCurrency() { + assertThrows(MoneyFormatException.class, () -> { + iParseTest.parseBigMoney("12.34 GBX"); + }); } - @Test(expected = MoneyFormatException.class) - public void test_parseBigMoney_CharSequence_notFullyParsed() { - iParseTest.parseBigMoney("12.34 GBP X"); + @Test + void test_parseBigMoney_CharSequence_notFullyParsed() { + assertThrows(MoneyFormatException.class, () -> { + iParseTest.parseBigMoney("12.34 GBP X"); + }); } - @Test(expected = MoneyFormatException.class) - public void test_parseBigMoney_CharSequence_incomplete() { - iParseTest.parseBigMoney("12.34 GBP "); + @Test + void test_parseBigMoney_CharSequence_incomplete() { + assertThrows(MoneyFormatException.class, () -> { + iParseTest.parseBigMoney("12.34 GBP "); + }); } - @Test(expected = MoneyFormatException.class) - public void test_parseBigMoney_CharSequence_incompleteLongText() { - iParseTest.parseBigMoney("12.34 GBP ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAB"); + @Test + void test_parseBigMoney_CharSequence_incompleteLongText() { + assertThrows(MoneyFormatException.class, () -> { + iParseTest.parseBigMoney("12.34 GBP ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAB"); + }); } - @Test(expected = MoneyFormatException.class) - public void test_parseBigMoney_CharSequence_incompleteEmptyParser() { - iCannotPrint.parseBigMoney("12.34 GBP"); + @Test + void test_parseBigMoney_CharSequence_incompleteEmptyParser() { + assertThrows(MoneyFormatException.class, () -> { + iCannotPrint.parseBigMoney("12.34 GBP"); + }); } - @Test(expected = MoneyFormatException.class) - public void test_parseBigMoney_CharSequence_missingCurrency() { + @Test + void test_parseBigMoney_CharSequence_missingCurrency() { MoneyFormatter f = new MoneyFormatterBuilder().appendAmount().toFormatter(); - f.parseBigMoney("12.34"); + assertThrows(MoneyFormatException.class, () -> { + f.parseBigMoney("12.34"); + }); } - @Test(expected = UnsupportedOperationException.class) - public void test_parseBigMoney_CharSequence_cannotParse() { - iCannotParse.parseBigMoney(new StringBuilder()); + @Test + void test_parseBigMoney_CharSequence_cannotParse() { + assertThrows(UnsupportedOperationException.class, () -> { + iCannotParse.parseBigMoney(new StringBuilder()); + }); } - @Test(expected = NullPointerException.class) - public void test_parseBigMoney_CharSequence_nullCharSequence() { - iParseTest.parseBigMoney((CharSequence) null); + @Test + void test_parseBigMoney_CharSequence_nullCharSequence() { + assertThrows(NullPointerException.class, () -> { + iParseTest.parseBigMoney((CharSequence) null); + }); } //----------------------------------------------------------------------- // parseMoney(CharSequence) //----------------------------------------------------------------------- @Test - public void test_parseMoney_CharSequence() { + void test_parseMoney_CharSequence() { CharSequence input = new StringBuilder("12.34 GBP"); Money test = iParseTest.parseMoney(input); assertEquals(MONEY_GBP_12_34, test); } - @Test(expected = MoneyFormatException.class) - public void test_parseMoney_CharSequence_invalidCurrency() { - iParseTest.parseMoney("12.34 GBX"); + @Test + void test_parseMoney_CharSequence_invalidCurrency() { + assertThrows(MoneyFormatException.class, () -> { + iParseTest.parseMoney("12.34 GBX"); + }); } - @Test(expected = MoneyFormatException.class) - public void test_parseMoney_CharSequence_notFullyParsed() { - iParseTest.parseMoney("12.34 GBP X"); + @Test + void test_parseMoney_CharSequence_notFullyParsed() { + assertThrows(MoneyFormatException.class, () -> { + iParseTest.parseMoney("12.34 GBP X"); + }); } - @Test(expected = MoneyFormatException.class) - public void test_parseMoney_CharSequence_incomplete() { - iCannotPrint.parseMoney("12.34 GBP"); + @Test + void test_parseMoney_CharSequence_incomplete() { + assertThrows(MoneyFormatException.class, () -> { + iCannotPrint.parseMoney("12.34 GBP"); + }); } - @Test(expected = UnsupportedOperationException.class) - public void test_parseMoney_CharSequence_cannotParse() { - iCannotParse.parseMoney(new StringBuilder()); + @Test + void test_parseMoney_CharSequence_cannotParse() { + assertThrows(UnsupportedOperationException.class, () -> { + iCannotParse.parseMoney(new StringBuilder()); + }); } - @Test(expected = NullPointerException.class) - public void test_parseMoney_CharSequence_nullCharSequence() { - iParseTest.parseMoney((CharSequence) null); + @Test + void test_parseMoney_CharSequence_nullCharSequence() { + assertThrows(NullPointerException.class, () -> { + iParseTest.parseMoney((CharSequence) null); + }); } //----------------------------------------------------------------------- // parse(CharSequence,int) //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_parse() { return new Object[][] { new Object[] {"12.34 GBP", MONEY_GBP_12_34.getAmount(), MONEY_GBP_12_34.getCurrencyUnit(), 9, -1, false, true, true}, @@ -323,9 +370,9 @@ public static Object[][] data_parse() { }; } - @Test - @UseDataProvider("data_parse") - public void test_parse_CharSequenceInt( + @ParameterizedTest + @MethodSource("data_parse") + void test_parse_CharSequenceInt( String str, BigDecimal amount, CurrencyUnit currency, @@ -352,22 +399,22 @@ public void test_parse_CharSequenceInt( } @Test - public void test_parse_CharSequenceInt_incomplete() { + void test_parse_CharSequenceInt_incomplete() { // this parser does nothing MoneyParseContext test = iCannotPrint.parse("12.34 GBP", 0); - assertEquals(null, test.getAmount()); - assertEquals(null, test.getCurrency()); + assertNull(test.getAmount()); + assertNull(test.getCurrency()); assertEquals(0, test.getIndex()); assertEquals(-1, test.getErrorIndex()); assertEquals("12.34 GBP", test.getText().toString()); assertEquals(9, test.getTextLength()); - assertEquals(false, test.isError()); - assertEquals(false, test.isFullyParsed()); - assertEquals(false, test.isComplete()); + assertFalse(test.isError()); + assertFalse(test.isFullyParsed()); + assertFalse(test.isComplete()); } @Test - public void test_parse_CharSequenceInt_continueAfterDoubleDecimal() { + void test_parse_CharSequenceInt_continueAfterDoubleDecimal() { MoneyFormatter f = new MoneyFormatterBuilder() .appendAmountLocalized().appendLiteral(".").appendCurrencyCode().toFormatter(); MoneyParseContext test = f.parse("12..GBP", 0); @@ -377,13 +424,13 @@ public void test_parse_CharSequenceInt_continueAfterDoubleDecimal() { assertEquals(-1, test.getErrorIndex()); assertEquals("12..GBP", test.getText().toString()); assertEquals(7, test.getTextLength()); - assertEquals(false, test.isError()); - assertEquals(true, test.isFullyParsed()); - assertEquals(true, test.isComplete()); + assertFalse(test.isError()); + assertTrue(test.isFullyParsed()); + assertTrue(test.isComplete()); } @Test - public void test_parse_CharSequenceInt_continueAfterSingleComma() { + void test_parse_CharSequenceInt_continueAfterSingleComma() { MoneyFormatter f = new MoneyFormatterBuilder() .appendAmountLocalized().appendLiteral(",").appendCurrencyCode().toFormatter(); MoneyParseContext test = f.parse("12,GBP", 0); @@ -393,13 +440,13 @@ public void test_parse_CharSequenceInt_continueAfterSingleComma() { assertEquals(-1, test.getErrorIndex()); assertEquals("12,GBP", test.getText().toString()); assertEquals(6, test.getTextLength()); - assertEquals(false, test.isError()); - assertEquals(true, test.isFullyParsed()); - assertEquals(true, test.isComplete()); + assertFalse(test.isError()); + assertTrue(test.isFullyParsed()); + assertTrue(test.isComplete()); } @Test - public void test_parse_CharSequenceInt_continueAfterDoubleComma() { + void test_parse_CharSequenceInt_continueAfterDoubleComma() { MoneyFormatter f = new MoneyFormatterBuilder() .appendAmountLocalized().appendLiteral(",,").appendCurrencyCode().toFormatter(); MoneyParseContext test = f.parse("12,,GBP", 0); @@ -409,76 +456,94 @@ public void test_parse_CharSequenceInt_continueAfterDoubleComma() { assertEquals(-1, test.getErrorIndex()); assertEquals("12,,GBP", test.getText().toString()); assertEquals(7, test.getTextLength()); - assertEquals(false, test.isError()); - assertEquals(true, test.isFullyParsed()); - assertEquals(true, test.isComplete()); + assertFalse(test.isError()); + assertTrue(test.isFullyParsed()); + assertTrue(test.isComplete()); } - @Test(expected = UnsupportedOperationException.class) - public void test_parse_CharSequenceInt_cannotParse() { - iCannotParse.parse(new StringBuilder(), 0); + @Test + void test_parse_CharSequenceInt_cannotParse() { + assertThrows(UnsupportedOperationException.class, () -> { + iCannotParse.parse(new StringBuilder(), 0); + }); } - @Test(expected = NullPointerException.class) - public void test_parse_CharSequenceInt_nullCharSequence() { - iParseTest.parse((CharSequence) null, 0); + @Test + void test_parse_CharSequenceInt_nullCharSequence() { + assertThrows(NullPointerException.class, () -> { + iParseTest.parse((CharSequence) null, 0); + }); } - @Test(expected = IndexOutOfBoundsException.class) - public void test_parse_CharSequenceInt_startIndexTooSmall() { - iParseTest.parse("", -1); + @Test + void test_parse_CharSequenceInt_startIndexTooSmall() { + assertThrows(IndexOutOfBoundsException.class, () -> { + iParseTest.parse("", -1); + }); } - @Test(expected = IndexOutOfBoundsException.class) - public void test_parse_CharSequenceInt_startIndexTooBig() { - iParseTest.parse("", 1); + @Test + void test_parse_CharSequenceInt_startIndexTooBig() { + assertThrows(IndexOutOfBoundsException.class, () -> { + iParseTest.parse("", 1); + }); } //----------------------------------------------------------------------- @Test - public void test_printParse_zeroChar() { + void test_printParse_zeroChar() { MoneyAmountStyle style = MoneyAmountStyle.ASCII_DECIMAL_POINT_GROUP3_COMMA.withZeroCharacter('A'); MoneyFormatter f = new MoneyFormatterBuilder().appendCurrencyCode().appendLiteral(" ").appendAmount(style).toFormatter(); assertEquals("GBP BC.DE", f.print(MONEY_GBP_12_34)); assertEquals(MONEY_GBP_12_34, f.parseMoney("GBP BC.DE")); } - @Test(expected = MoneyFormatException.class) - public void test_parseMoney_notFullyParsed() { - iParseTest.parseMoney("GBP hello notfullyparsed"); + @Test + void test_parseMoney_notFullyParsed() { + assertThrows(MoneyFormatException.class, () -> { + iParseTest.parseMoney("GBP hello notfullyparsed"); + }); } - @Test(expected = MoneyFormatException.class) - public void test_parseMoney_noAmount() { - iParseTest.parseMoney("GBP hello"); + @Test + void test_parseMoney_noAmount() { + assertThrows(MoneyFormatException.class, () -> { + iParseTest.parseMoney("GBP hello"); + }); } - @Test(expected = MoneyFormatException.class) - public void test_parseBigMoney_notFullyParsed() { - iParseTest.parseBigMoney("GBP hello notfullyparsed"); + @Test + void test_parseBigMoney_notFullyParsed() { + assertThrows(MoneyFormatException.class, () -> { + iParseTest.parseBigMoney("GBP hello notfullyparsed"); + }); } - @Test(expected = MoneyFormatException.class) - public void test_parseBigMoney_noAmount() { - iParseTest.parseBigMoney("GBP hello"); + @Test + void test_parseBigMoney_noAmount() { + assertThrows(MoneyFormatException.class, () -> { + iParseTest.parseBigMoney("GBP hello"); + }); } - @Test(expected = MoneyFormatException.class) - public void test_parse_notFullyParsed() { - MoneyParseContext context = iParseTest.parse("GBP hello notfullyparsed", 1); - context.toBigMoney(); + @Test + void test_parse_notFullyParsed() { + assertThrows(MoneyFormatException.class, () -> { + MoneyParseContext context = iParseTest.parse("GBP hello notfullyparsed", 1); + context.toBigMoney(); + }); } //----------------------------------------------------------------------- // toString() //----------------------------------------------------------------------- @Test - public void test_toString() { + void test_toString() { assertEquals("${code}' hello'", iPrintTest.toString()); } @Test - public void test_toString_differentPrinterParser() { + void test_toString_differentPrinterParser() { MoneyPrinter printer = new MoneyPrinter() { @Override public void print(MoneyPrintContext context, Appendable appendable, BigMoney money) throws IOException { diff --git a/src/test/java/org/joda/money/format/TestMoneyFormatterBuilder.java b/src/test/java/org/joda/money/format/TestMoneyFormatterBuilder.java index ce2c866..56c586b 100644 --- a/src/test/java/org/joda/money/format/TestMoneyFormatterBuilder.java +++ b/src/test/java/org/joda/money/format/TestMoneyFormatterBuilder.java @@ -15,7 +15,11 @@ */ package org.joda.money.format; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.math.BigDecimal; @@ -26,20 +30,16 @@ import org.joda.money.BigMoneyProvider; import org.joda.money.CurrencyUnit; import org.joda.money.Money; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; - -import com.tngtech.java.junit.dataprovider.DataProvider; -import com.tngtech.java.junit.dataprovider.DataProviderRunner; -import com.tngtech.java.junit.dataprovider.UseDataProvider; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; /** * Test MoneyFormatterBuilder. */ -@RunWith(DataProviderRunner.class) -public class TestMoneyFormatterBuilder { +class TestMoneyFormatterBuilder { private static final CurrencyUnit GBP = CurrencyUnit.GBP; private static final CurrencyUnit JPY = CurrencyUnit.JPY; @@ -63,21 +63,21 @@ public class TestMoneyFormatterBuilder { private MoneyFormatterBuilder iBuilder; - @Before - public void beforeMethod() { + @BeforeEach + void beforeMethod() { Locale.setDefault(TEST_GB_LOCALE); iBuilder = new MoneyFormatterBuilder(); } - @After - public void afterMethod() { + @AfterEach + void afterMethod() { Locale.setDefault(cCachedLocale); iBuilder = null; } //----------------------------------------------------------------------- @Test - public void test_empty() { + void test_empty() { MoneyFormatter test = iBuilder.toFormatter(); assertEquals("", test.print(GBP_2_34)); assertEquals("", test.toString()); @@ -85,7 +85,7 @@ public void test_empty() { //----------------------------------------------------------------------- @Test - public void test_appendCurrencyCode_print() { + void test_appendCurrencyCode_print() { iBuilder.appendCurrencyCode(); MoneyFormatter test = iBuilder.toFormatter(); assertEquals("GBP", test.print(GBP_2_34)); @@ -93,44 +93,44 @@ public void test_appendCurrencyCode_print() { } @Test - public void test_appendCurrencyCode_parse_ok() { + void test_appendCurrencyCode_parse_ok() { iBuilder.appendCurrencyCode(); MoneyFormatter test = iBuilder.toFormatter(); MoneyParseContext parsed = test.parse("GBP", 0); - assertEquals(false, parsed.isError()); + assertFalse(parsed.isError()); assertEquals(3, parsed.getIndex()); assertEquals(-1, parsed.getErrorIndex()); - assertEquals(null, parsed.getAmount()); + assertNull(parsed.getAmount()); assertEquals(CurrencyUnit.GBP, parsed.getCurrency()); } @Test - public void test_appendCurrencyCode_parse_tooShort() { + void test_appendCurrencyCode_parse_tooShort() { iBuilder.appendCurrencyCode(); MoneyFormatter test = iBuilder.toFormatter(); MoneyParseContext parsed = test.parse("GB", 0); - assertEquals(true, parsed.isError()); + assertTrue(parsed.isError()); assertEquals(0, parsed.getIndex()); assertEquals(0, parsed.getErrorIndex()); - assertEquals(null, parsed.getAmount()); - assertEquals(null, parsed.getCurrency()); + assertNull(parsed.getAmount()); + assertNull(parsed.getCurrency()); } @Test - public void test_appendCurrencyCode_parse_empty() { + void test_appendCurrencyCode_parse_empty() { iBuilder.appendCurrencyCode(); MoneyFormatter test = iBuilder.toFormatter(); MoneyParseContext parsed = test.parse("", 0); - assertEquals(true, parsed.isError()); + assertTrue(parsed.isError()); assertEquals(0, parsed.getIndex()); assertEquals(0, parsed.getErrorIndex()); - assertEquals(null, parsed.getAmount()); - assertEquals(null, parsed.getCurrency()); + assertNull(parsed.getAmount()); + assertNull(parsed.getCurrency()); } //----------------------------------------------------------------------- @Test - public void test_appendCurrencyNumeric3Code_print() { + void test_appendCurrencyNumeric3Code_print() { iBuilder.appendCurrencyNumeric3Code(); MoneyFormatter test = iBuilder.toFormatter(); assertEquals("826", test.print(GBP_2_34)); @@ -138,56 +138,56 @@ public void test_appendCurrencyNumeric3Code_print() { } @Test - public void test_appendCurrencyNumeric3Code_parse_ok() { + void test_appendCurrencyNumeric3Code_parse_ok() { iBuilder.appendCurrencyNumeric3Code(); MoneyFormatter test = iBuilder.toFormatter(); MoneyParseContext parsed = test.parse("826A", 0); - assertEquals(false, parsed.isError()); + assertFalse(parsed.isError()); assertEquals(3, parsed.getIndex()); assertEquals(-1, parsed.getErrorIndex()); - assertEquals(null, parsed.getAmount()); + assertNull(parsed.getAmount()); assertEquals(CurrencyUnit.GBP, parsed.getCurrency()); } @Test - public void test_appendCurrencyNumeric3Code_parse_tooShort() { + void test_appendCurrencyNumeric3Code_parse_tooShort() { iBuilder.appendCurrencyNumeric3Code(); MoneyFormatter test = iBuilder.toFormatter(); MoneyParseContext parsed = test.parse("82", 0); - assertEquals(true, parsed.isError()); + assertTrue(parsed.isError()); assertEquals(0, parsed.getIndex()); assertEquals(0, parsed.getErrorIndex()); - assertEquals(null, parsed.getAmount()); - assertEquals(null, parsed.getCurrency()); + assertNull(parsed.getAmount()); + assertNull(parsed.getCurrency()); } @Test - public void test_appendCurrencyNumeric3Code_parse_badCurrency() { + void test_appendCurrencyNumeric3Code_parse_badCurrency() { iBuilder.appendCurrencyNumeric3Code(); MoneyFormatter test = iBuilder.toFormatter(); MoneyParseContext parsed = test.parse("991A", 0); - assertEquals(true, parsed.isError()); + assertTrue(parsed.isError()); assertEquals(0, parsed.getIndex()); assertEquals(0, parsed.getErrorIndex()); - assertEquals(null, parsed.getAmount()); - assertEquals(null, parsed.getCurrency()); + assertNull(parsed.getAmount()); + assertNull(parsed.getCurrency()); } @Test - public void test_appendCurrencyNumeric3Code_parse_empty() { + void test_appendCurrencyNumeric3Code_parse_empty() { iBuilder.appendCurrencyNumeric3Code(); MoneyFormatter test = iBuilder.toFormatter(); MoneyParseContext parsed = test.parse("", 0); - assertEquals(true, parsed.isError()); + assertTrue(parsed.isError()); assertEquals(0, parsed.getIndex()); assertEquals(0, parsed.getErrorIndex()); - assertEquals(null, parsed.getAmount()); - assertEquals(null, parsed.getCurrency()); + assertNull(parsed.getAmount()); + assertNull(parsed.getCurrency()); } //----------------------------------------------------------------------- @Test - public void test_appendCurrencyNumericCode_print() { + void test_appendCurrencyNumericCode_print() { iBuilder.appendCurrencyNumericCode(); MoneyFormatter test = iBuilder.toFormatter(); assertEquals("826", test.print(GBP_2_34)); @@ -195,92 +195,92 @@ public void test_appendCurrencyNumericCode_print() { } @Test - public void test_appendCurrencyNumericCode_parse_ok() { + void test_appendCurrencyNumericCode_parse_ok() { iBuilder.appendCurrencyNumericCode(); MoneyFormatter test = iBuilder.toFormatter(); MoneyParseContext parsed = test.parse("826A", 0); - assertEquals(false, parsed.isError()); + assertFalse(parsed.isError()); assertEquals(3, parsed.getIndex()); assertEquals(-1, parsed.getErrorIndex()); - assertEquals(null, parsed.getAmount()); + assertNull(parsed.getAmount()); assertEquals(CurrencyUnit.GBP, parsed.getCurrency()); } @Test - public void test_appendCurrencyNumericCode_parse_ok_padded() { + void test_appendCurrencyNumericCode_parse_ok_padded() { iBuilder.appendCurrencyNumericCode(); MoneyFormatter test = iBuilder.toFormatter(); MoneyParseContext parsed = test.parse("008A", 0); - assertEquals(false, parsed.isError()); + assertFalse(parsed.isError()); assertEquals(3, parsed.getIndex()); assertEquals(-1, parsed.getErrorIndex()); - assertEquals(null, parsed.getAmount()); + assertNull(parsed.getAmount()); assertEquals("ALL", parsed.getCurrency().getCode()); } @Test - public void test_appendCurrencyNumericCode_parse_ok_notPadded1() { + void test_appendCurrencyNumericCode_parse_ok_notPadded1() { iBuilder.appendCurrencyNumericCode(); MoneyFormatter test = iBuilder.toFormatter(); MoneyParseContext parsed = test.parse("8A", 0); - assertEquals(false, parsed.isError()); + assertFalse(parsed.isError()); assertEquals(1, parsed.getIndex()); assertEquals(-1, parsed.getErrorIndex()); - assertEquals(null, parsed.getAmount()); + assertNull(parsed.getAmount()); assertEquals("ALL", parsed.getCurrency().getCode()); } @Test - public void test_appendCurrencyNumericCode_parse_ok_notPadded2() { + void test_appendCurrencyNumericCode_parse_ok_notPadded2() { iBuilder.appendCurrencyNumericCode(); MoneyFormatter test = iBuilder.toFormatter(); MoneyParseContext parsed = test.parse("51 ", 0); - assertEquals(false, parsed.isError()); + assertFalse(parsed.isError()); assertEquals(2, parsed.getIndex()); assertEquals(-1, parsed.getErrorIndex()); - assertEquals(null, parsed.getAmount()); + assertNull(parsed.getAmount()); assertEquals("AMD", parsed.getCurrency().getCode()); } @Test - public void test_appendCurrencyNumericCode_parse_tooShort() { + void test_appendCurrencyNumericCode_parse_tooShort() { iBuilder.appendCurrencyNumericCode(); MoneyFormatter test = iBuilder.toFormatter(); MoneyParseContext parsed = test.parse("", 0); - assertEquals(true, parsed.isError()); + assertTrue(parsed.isError()); assertEquals(0, parsed.getIndex()); assertEquals(0, parsed.getErrorIndex()); - assertEquals(null, parsed.getAmount()); - assertEquals(null, parsed.getCurrency()); + assertNull(parsed.getAmount()); + assertNull(parsed.getCurrency()); } @Test - public void test_appendCurrencyNumericCode_parse_badCurrency() { + void test_appendCurrencyNumericCode_parse_badCurrency() { iBuilder.appendCurrencyNumericCode(); MoneyFormatter test = iBuilder.toFormatter(); MoneyParseContext parsed = test.parse("991A", 0); - assertEquals(true, parsed.isError()); + assertTrue(parsed.isError()); assertEquals(0, parsed.getIndex()); assertEquals(0, parsed.getErrorIndex()); - assertEquals(null, parsed.getAmount()); - assertEquals(null, parsed.getCurrency()); + assertNull(parsed.getAmount()); + assertNull(parsed.getCurrency()); } @Test - public void test_appendCurrencyNumericCode_parse_empty() { + void test_appendCurrencyNumericCode_parse_empty() { iBuilder.appendCurrencyNumericCode(); MoneyFormatter test = iBuilder.toFormatter(); MoneyParseContext parsed = test.parse("", 0); - assertEquals(true, parsed.isError()); + assertTrue(parsed.isError()); assertEquals(0, parsed.getIndex()); assertEquals(0, parsed.getErrorIndex()); - assertEquals(null, parsed.getAmount()); - assertEquals(null, parsed.getCurrency()); + assertNull(parsed.getAmount()); + assertNull(parsed.getCurrency()); } //----------------------------------------------------------------------- @Test - public void test_appendCurrencySymbolLocalized_print() { + void test_appendCurrencySymbolLocalized_print() { iBuilder.appendCurrencySymbolLocalized(); MoneyFormatter test = iBuilder.toFormatter(); assertEquals("\u00a3", test.print(GBP_2_34)); @@ -288,15 +288,15 @@ public void test_appendCurrencySymbolLocalized_print() { } @Test - public void test_appendCurrencySymbolLocalized_parse() { + void test_appendCurrencySymbolLocalized_parse() { iBuilder.appendCurrencySymbolLocalized(); MoneyFormatter test = iBuilder.toFormatter(); - assertEquals(false, test.isParser()); + assertFalse(test.isParser()); } //----------------------------------------------------------------------- @Test - public void test_appendLiteral_print() { + void test_appendLiteral_print() { iBuilder.appendLiteral("Hello"); MoneyFormatter test = iBuilder.toFormatter(); assertEquals("Hello", test.print(GBP_2_34)); @@ -304,7 +304,7 @@ public void test_appendLiteral_print() { } @Test - public void test_appendLiteral_print_empty() { + void test_appendLiteral_print_empty() { iBuilder.appendLiteral(""); MoneyFormatter test = iBuilder.toFormatter(); assertEquals("", test.print(GBP_2_34)); @@ -312,7 +312,7 @@ public void test_appendLiteral_print_empty() { } @Test - public void test_appendLiteral_print_null() { + void test_appendLiteral_print_null() { iBuilder.appendLiteral((CharSequence) null); MoneyFormatter test = iBuilder.toFormatter(); assertEquals("", test.print(GBP_2_34)); @@ -320,43 +320,42 @@ public void test_appendLiteral_print_null() { } @Test - public void test_appendLiteral_parse_ok() { + void test_appendLiteral_parse_ok() { iBuilder.appendLiteral("Hello"); MoneyFormatter test = iBuilder.toFormatter(); MoneyParseContext parsed = test.parse("HelloWorld", 0); - assertEquals(false, parsed.isError()); + assertFalse(parsed.isError()); assertEquals(5, parsed.getIndex()); assertEquals(-1, parsed.getErrorIndex()); - assertEquals(null, parsed.getAmount()); - assertEquals(null, parsed.getCurrency()); + assertNull(parsed.getAmount()); + assertNull(parsed.getCurrency()); } @Test - public void test_appendLiteral_parse_tooShort() { + void test_appendLiteral_parse_tooShort() { iBuilder.appendLiteral("Hello"); MoneyFormatter test = iBuilder.toFormatter(); MoneyParseContext parsed = test.parse("Hell", 0); - assertEquals(true, parsed.isError()); + assertTrue(parsed.isError()); assertEquals(0, parsed.getIndex()); assertEquals(0, parsed.getErrorIndex()); - assertEquals(null, parsed.getAmount()); - assertEquals(null, parsed.getCurrency()); + assertNull(parsed.getAmount()); + assertNull(parsed.getCurrency()); } @Test - public void test_appendLiteral_parse_noMatch() { + void test_appendLiteral_parse_noMatch() { iBuilder.appendLiteral("Hello"); MoneyFormatter test = iBuilder.toFormatter(); MoneyParseContext parsed = test.parse("Helol", 0); - assertEquals(true, parsed.isError()); + assertTrue(parsed.isError()); assertEquals(0, parsed.getIndex()); assertEquals(0, parsed.getErrorIndex()); - assertEquals(null, parsed.getAmount()); - assertEquals(null, parsed.getCurrency()); + assertNull(parsed.getAmount()); + assertNull(parsed.getCurrency()); } //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_appendAmount() { return new Object[][] { {GBP_2_34, "2.34"}, @@ -370,9 +369,9 @@ public static Object[][] data_appendAmount() { }; } - @Test - @UseDataProvider("data_appendAmount") - public void test_appendAmount(BigMoneyProvider money, String expected) { + @ParameterizedTest + @MethodSource("data_appendAmount") + void test_appendAmount(BigMoneyProvider money, String expected) { iBuilder.appendAmount(); MoneyFormatter test = iBuilder.toFormatter(); assertEquals(expected, test.print(money)); @@ -380,7 +379,7 @@ public void test_appendAmount(BigMoneyProvider money, String expected) { } @Test - public void test_appendAmount_GBP_1234_56789_France() { + void test_appendAmount_GBP_1234_56789_France() { iBuilder.appendAmount(); MoneyFormatter test = iBuilder.toFormatter(Locale.FRANCE); assertEquals("1,234.567,89", test.print(GBP_1234_56789)); @@ -388,7 +387,7 @@ public void test_appendAmount_GBP_1234_56789_France() { } @Test - public void test_appendAmount_JPY_2345() { + void test_appendAmount_JPY_2345() { iBuilder.appendAmount(); MoneyFormatter test = iBuilder.toFormatter(); assertEquals("2,345", test.print(JPY_2345)); @@ -396,7 +395,7 @@ public void test_appendAmount_JPY_2345() { } @Test - public void test_appendAmount_3dp_BHD() { + void test_appendAmount_3dp_BHD() { iBuilder.appendAmount(); MoneyFormatter test = iBuilder.toFormatter(); Money money = Money.of(CurrencyUnit.of("BHD"), 6345345.735d); @@ -404,7 +403,6 @@ public void test_appendAmount_3dp_BHD() { } //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_appendAmountLocalized() { return new Object[][] { {GBP_2_34, "2" + FR_DECIMAL + "34"}, @@ -417,9 +415,9 @@ public static Object[][] data_appendAmountLocalized() { }; } - @Test - @UseDataProvider("data_appendAmountLocalized") - public void test_appendAmountLocalized(BigMoneyProvider money, String expected) { + @ParameterizedTest + @MethodSource("data_appendAmountLocalized") + void test_appendAmountLocalized(BigMoneyProvider money, String expected) { iBuilder.appendAmountLocalized(); MoneyFormatter test = iBuilder.toFormatter(Locale.FRANCE); assertEquals(expected, test.print(money)); @@ -427,7 +425,7 @@ public void test_appendAmountLocalized(BigMoneyProvider money, String expected) } @Test - public void test_appendAmountLocalized_GBP_1234_56789_US() { + void test_appendAmountLocalized_GBP_1234_56789_US() { iBuilder.appendAmountLocalized(); MoneyFormatter test = iBuilder.toFormatter(Locale.US); assertEquals("1,234.567,89", test.print(GBP_1234_56789)); @@ -435,7 +433,7 @@ public void test_appendAmountLocalized_GBP_1234_56789_US() { } @Test - public void test_appendAmountLocalized_JPY_2345() { + void test_appendAmountLocalized_JPY_2345() { iBuilder.appendAmountLocalized(); MoneyFormatter test = iBuilder.toFormatter(Locale.FRANCE); assertEquals("2" + FR_GROUP + "345", test.print(JPY_2345)); @@ -443,12 +441,13 @@ public void test_appendAmountLocalized_JPY_2345() { } //----------------------------------------------------------------------- - @Test(expected = NullPointerException.class) - public void test_appendAmount_MoneyAmountStyle_null() { - iBuilder.appendAmount((MoneyAmountStyle) null); + @Test + void test_appendAmount_MoneyAmountStyle_null() { + assertThrows(NullPointerException.class, () -> { + iBuilder.appendAmount((MoneyAmountStyle) null); + }); } - @DataProvider public static Object[][] data_appendAmount_MoneyAmountStyle() { MoneyAmountStyle noGrouping = MoneyAmountStyle.ASCII_DECIMAL_POINT_NO_GROUPING; MoneyAmountStyle group3Comma = MoneyAmountStyle.ASCII_DECIMAL_POINT_GROUP3_COMMA; @@ -617,9 +616,9 @@ public static Object[][] data_appendAmount_MoneyAmountStyle() { }; } - @Test - @UseDataProvider("data_appendAmount_MoneyAmountStyle") - public void test_appendAmount_MoneyAmountStyle_GBP( + @ParameterizedTest + @MethodSource("data_appendAmount_MoneyAmountStyle") + void test_appendAmount_MoneyAmountStyle_GBP( MoneyAmountStyle style, String amount, String expected) { @@ -635,9 +634,9 @@ public void test_appendAmount_MoneyAmountStyle_GBP( } } - @Test - @UseDataProvider("data_appendAmount_MoneyAmountStyle") - public void test_appendAmount_MoneyAmountStyle_JPY( + @ParameterizedTest + @MethodSource("data_appendAmount_MoneyAmountStyle") + void test_appendAmount_MoneyAmountStyle_JPY( MoneyAmountStyle style, String amount, String expected) { @@ -653,9 +652,9 @@ public void test_appendAmount_MoneyAmountStyle_JPY( } } - @Test - @UseDataProvider("data_appendAmount_MoneyAmountStyle") - public void test_appendAmount_MoneyAmountStyle_BHD( + @ParameterizedTest + @MethodSource("data_appendAmount_MoneyAmountStyle") + void test_appendAmount_MoneyAmountStyle_BHD( MoneyAmountStyle style, String amount, String expected) { @@ -672,7 +671,7 @@ public void test_appendAmount_MoneyAmountStyle_BHD( } @Test - public void test_appendAmount_MoneyAmountStyle_JPY_issue49() { + void test_appendAmount_MoneyAmountStyle_JPY_issue49() { Money money = Money.parse("JPY 12"); MoneyAmountStyle style = MoneyAmountStyle.LOCALIZED_GROUPING; MoneyFormatter formatter = new MoneyFormatterBuilder() @@ -683,7 +682,6 @@ public void test_appendAmount_MoneyAmountStyle_JPY_issue49() { } //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_appendAmountExtendedGrouping() { return new Object[][] { {GBP_2_34, "2.34"}, @@ -697,9 +695,9 @@ public static Object[][] data_appendAmountExtendedGrouping() { }; } - @Test - @UseDataProvider("data_appendAmountExtendedGrouping") - public void test_appendAmount_parseExtendedGroupingSize(BigMoneyProvider money, String expected) { + @ParameterizedTest + @MethodSource("data_appendAmountExtendedGrouping") + void test_appendAmount_parseExtendedGroupingSize(BigMoneyProvider money, String expected) { iBuilder.appendAmount(); MoneyFormatter test = new MoneyFormatterBuilder() .appendAmount(MoneyAmountStyle.ASCII_DECIMAL_POINT_GROUP3_COMMA.withExtendedGroupingSize(2)) @@ -710,7 +708,7 @@ public void test_appendAmount_parseExtendedGroupingSize(BigMoneyProvider money, //----------------------------------------------------------------------- @Test - public void test_appendAmount_parseExcessGrouping() { + void test_appendAmount_parseExcessGrouping() { BigMoney expected = BigMoney.parse("GBP 12123.4567"); MoneyFormatter f = new MoneyFormatterBuilder() .appendCurrencyCode() @@ -723,7 +721,7 @@ public void test_appendAmount_parseExcessGrouping() { //----------------------------------------------------------------------- @Test - public void test_append_MoneyPrinterMoneyParser_printer() { + void test_append_MoneyPrinterMoneyParser_printer() { MoneyPrinter printer = new MoneyPrinter() { @Override @Test @@ -733,14 +731,14 @@ public void print(MoneyPrintContext context, Appendable appendable, BigMoney mon }; iBuilder.append(printer, null); MoneyFormatter test = iBuilder.toFormatter(); - assertEquals(true, test.isPrinter()); - assertEquals(false, test.isParser()); + assertTrue(test.isPrinter()); + assertFalse(test.isParser()); assertEquals("HELLO", test.print(JPY_2345)); - assertEquals(true, test.toString().startsWith("org.joda.money.format.TestMoneyFormatterBuilder$")); + assertTrue(test.toString().startsWith("org.joda.money.format.TestMoneyFormatterBuilder$")); } @Test - public void test_append_MoneyPrinterMoneyParser_parser() { + void test_append_MoneyPrinterMoneyParser_parser() { MoneyParser parser = new MoneyParser() { @Override @Test @@ -751,24 +749,24 @@ public void parse(MoneyParseContext context) { }; iBuilder.append(null, parser); MoneyFormatter test = iBuilder.toFormatter(); - assertEquals(false, test.isPrinter()); - assertEquals(true, test.isParser()); + assertFalse(test.isPrinter()); + assertTrue(test.isParser()); assertEquals(JPY_2345, test.parseMoney("")); - assertEquals(true, test.toString().startsWith("org.joda.money.format.TestMoneyFormatterBuilder$")); + assertTrue(test.toString().startsWith("org.joda.money.format.TestMoneyFormatterBuilder$")); } @Test - public void test_append_MoneyPrinter_nullMoneyPrinter_nullMoneyParser() { + void test_append_MoneyPrinter_nullMoneyPrinter_nullMoneyParser() { iBuilder.append((MoneyPrinter) null, (MoneyParser) null); MoneyFormatter test = iBuilder.toFormatter(); - assertEquals(false, test.isPrinter()); - assertEquals(false, test.isParser()); + assertFalse(test.isPrinter()); + assertFalse(test.isParser()); assertEquals("", test.toString()); } //----------------------------------------------------------------------- @Test - public void test_append_MoneyFormatter() { + void test_append_MoneyFormatter() { MoneyFormatter f1 = new MoneyFormatterBuilder().appendAmount().toFormatter(); MoneyFormatter f2 = new MoneyFormatterBuilder().appendCurrencyCode().appendLiteral(" ").append(f1).toFormatter(); assertEquals("GBP 2,345.67", f2.print(GBP_2345_67)); @@ -776,7 +774,7 @@ public void test_append_MoneyFormatter() { //----------------------------------------------------------------------- @Test - public void test_appendSigned_PN() { + void test_appendSigned_PN() { MoneyFormatter pos = new MoneyFormatterBuilder() .appendCurrencyCode() .appendLiteral(" ") @@ -806,7 +804,7 @@ public void test_appendSigned_PN() { //----------------------------------------------------------------------- @Test - public void test_appendSigned_PZN() { + void test_appendSigned_PZN() { MoneyFormatter pos = new MoneyFormatterBuilder() .appendCurrencyCode() .appendLiteral(" ") @@ -835,7 +833,7 @@ public void test_appendSigned_PZN() { } @Test - public void test_appendSigned_PZN_edgeCases() { + void test_appendSigned_PZN_edgeCases() { MoneyFormatter pos = new MoneyFormatterBuilder() .appendAmount() .toFormatter(); @@ -861,13 +859,13 @@ public void test_appendSigned_PZN_edgeCases() { //----------------------------------------------------------------------- @Test - public void test_toFormatter_defaultLocale() { + void test_toFormatter_defaultLocale() { MoneyFormatter test = iBuilder.toFormatter(); assertEquals(TEST_GB_LOCALE, test.getLocale()); } @Test - public void test_toFormatter_Locale() { + void test_toFormatter_Locale() { MoneyFormatter test = iBuilder.toFormatter(TEST_FR_LOCALE); assertEquals(TEST_FR_LOCALE, test.getLocale()); } diff --git a/src/test/java/org/joda/money/format/TestMoneyFormatterException.java b/src/test/java/org/joda/money/format/TestMoneyFormatterException.java index e10bc4e..58d07b6 100644 --- a/src/test/java/org/joda/money/format/TestMoneyFormatterException.java +++ b/src/test/java/org/joda/money/format/TestMoneyFormatterException.java @@ -15,25 +15,28 @@ */ package org.joda.money.format; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertThrows; + import java.io.IOException; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Test MoneyFormatterException. */ -public class TestMoneyFormatterException { +class TestMoneyFormatterException { - @Test(expected = IOException.class) - public void test_MoneyFormatException_IOException_notRethrown() throws IOException { + @Test + void test_MoneyFormatException_IOException_notRethrown() { MoneyFormatException test = new MoneyFormatException("Error", new IOException("Inner")); - test.rethrowIOException(); // should throw + assertThrows(IOException.class, () -> test.rethrowIOException()); } @Test - public void test_MoneyFormatException_nonIOException_notRethrown() throws IOException { + void test_MoneyFormatException_nonIOException_notRethrown() throws IOException { MoneyFormatException test = new MoneyFormatException("Error", new IllegalStateException("Inner")); - test.rethrowIOException(); // should succeed + assertDoesNotThrow(() -> test.rethrowIOException()); } } diff --git a/src/test/java/org/joda/money/format/TestMoneyParseContext.java b/src/test/java/org/joda/money/format/TestMoneyParseContext.java index 24b2d6d..dca6be2 100644 --- a/src/test/java/org/joda/money/format/TestMoneyParseContext.java +++ b/src/test/java/org/joda/money/format/TestMoneyParseContext.java @@ -15,39 +15,42 @@ */ package org.joda.money.format; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.math.BigDecimal; import java.text.ParsePosition; import java.util.Locale; import org.joda.money.CurrencyUnit; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Test MoneyParseContext. */ -public class TestMoneyParseContext { +class TestMoneyParseContext { @Test - public void test_initialState() { + void test_initialState() { MoneyParseContext test = new MoneyParseContext(Locale.FRANCE, "GBP 123", 0); - assertEquals(null, test.getAmount()); - assertEquals(null, test.getCurrency()); + assertNull(test.getAmount()); + assertNull(test.getCurrency()); assertEquals(0, test.getIndex()); assertEquals(-1, test.getErrorIndex()); assertEquals("GBP 123", test.getText().toString()); assertEquals(7, test.getTextLength()); - assertEquals(false, test.isError()); - assertEquals(false, test.isFullyParsed()); - assertEquals(false, test.isComplete()); + assertFalse(test.isError()); + assertFalse(test.isFullyParsed()); + assertFalse(test.isComplete()); ParsePosition pp = new ParsePosition(0); pp.setErrorIndex(-1); assertEquals(pp, test.toParsePosition()); } @Test - public void test_setIndex() { + void test_setIndex() { MoneyParseContext test = new MoneyParseContext(Locale.FRANCE, "GBP 123", 0); assertEquals(0, test.getIndex()); test.setIndex(2); @@ -55,7 +58,7 @@ public void test_setIndex() { } @Test - public void test_setErrorIndex() { + void test_setErrorIndex() { MoneyParseContext test = new MoneyParseContext(Locale.FRANCE, "GBP 123", 0); assertEquals(-1, test.getErrorIndex()); test.setErrorIndex(3); @@ -63,7 +66,7 @@ public void test_setErrorIndex() { } @Test - public void test_setError() { + void test_setError() { MoneyParseContext test = new MoneyParseContext(Locale.FRANCE, "GBP 123", 0); assertEquals(0, test.getIndex()); assertEquals(-1, test.getErrorIndex()); @@ -73,7 +76,7 @@ public void test_setError() { } @Test - public void test_setError_withIndex() { + void test_setError_withIndex() { MoneyParseContext test = new MoneyParseContext(Locale.FRANCE, "GBP 123", 0); assertEquals(0, test.getIndex()); assertEquals(-1, test.getErrorIndex()); @@ -85,51 +88,59 @@ public void test_setError_withIndex() { //----------------------------------------------------------------------- @Test - public void test_isComplete_noCurrency() { + void test_isComplete_noCurrency() { MoneyParseContext test = new MoneyParseContext(Locale.FRANCE, "GBP 123", 0); test.setAmount(BigDecimal.TEN); - assertEquals(false, test.isComplete()); + assertFalse(test.isComplete()); } @Test - public void test_isComplete_noAmount() { + void test_isComplete_noAmount() { MoneyParseContext test = new MoneyParseContext(Locale.FRANCE, "GBP 123", 0); test.setCurrency(CurrencyUnit.GBP); - assertEquals(false, test.isComplete()); + assertFalse(test.isComplete()); } - @Test(expected = MoneyFormatException.class) - public void test_toBigMoney_noCurrency() { + @Test + void test_toBigMoney_noCurrency() { MoneyParseContext test = new MoneyParseContext(Locale.FRANCE, "GBP 123", 0); test.setAmount(BigDecimal.TEN); - test.toBigMoney(); + assertThrows(MoneyFormatException.class, () -> { + test.toBigMoney(); + }); } - @Test(expected = MoneyFormatException.class) - public void test_toBigMoney_noAmount() { + @Test + void test_toBigMoney_noAmount() { MoneyParseContext test = new MoneyParseContext(Locale.FRANCE, "GBP 123", 0); test.setCurrency(CurrencyUnit.GBP); - test.toBigMoney(); + assertThrows(MoneyFormatException.class, () -> { + test.toBigMoney(); + }); } //----------------------------------------------------------------------- @Test - public void test_getTextSubstring_ok() { + void test_getTextSubstring_ok() { MoneyParseContext test = new MoneyParseContext(Locale.FRANCE, "GBP 123", 0); assertEquals("GB", test.getTextSubstring(0, 2)); assertEquals("23", test.getTextSubstring(5, 7)); } - @Test(expected = IndexOutOfBoundsException.class) - public void test_getTextSubstring_beforeStart() { + @Test + void test_getTextSubstring_beforeStart() { MoneyParseContext test = new MoneyParseContext(Locale.FRANCE, "GBP 123", 0); - test.getTextSubstring(-1, 2); + assertThrows(IndexOutOfBoundsException.class, () -> { + test.getTextSubstring(-1, 2); + }); } - @Test(expected = IndexOutOfBoundsException.class) - public void test_getTextSubstring_afterEnd() { + @Test + void test_getTextSubstring_afterEnd() { MoneyParseContext test = new MoneyParseContext(Locale.FRANCE, "GBP 123", 0); - test.getTextSubstring(0, 8); + assertThrows(IndexOutOfBoundsException.class, () -> { + test.getTextSubstring(0, 8); + }); } }