From 0ae24d56ea7d3f6ad640f72a971fd5d6ec0ad504 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Sun, 18 Aug 2024 10:14:50 +0100 Subject: [PATCH] Migrate to AssertJ (#136) * Migrate to AssertJ * Migrate to AssertJ --- pom.xml | 7 + .../java/org/joda/money/TestBigMoney.java | 1479 ++++++++--------- .../money/TestCurrencyMismatchException.java | 35 +- .../java/org/joda/money/TestCurrencyUnit.java | 426 ++--- .../joda/money/TestCurrencyUnitExtension.java | 19 +- .../money/TestIllegalCurrencyException.java | 11 +- src/test/java/org/joda/money/TestMoney.java | 1401 ++++++++-------- .../joda/money/TestMoneyUtils_BigMoney.java | 106 +- .../org/joda/money/TestMoneyUtils_Money.java | 115 +- .../org/joda/money/TestStringConvert.java | 14 +- .../money/format/TestMoneyAmountStyle.java | 615 ++++--- .../joda/money/format/TestMoneyFormatter.java | 302 ++-- .../format/TestMoneyFormatterBuilder.java | 347 ++-- .../format/TestMoneyFormatterException.java | 10 +- .../money/format/TestMoneyParseContext.java | 78 +- 15 files changed, 2297 insertions(+), 2668 deletions(-) diff --git a/pom.xml b/pom.xml index e2e317d..99864ea 100644 --- a/pom.xml +++ b/pom.xml @@ -525,6 +525,12 @@ ${junit.version} test + + org.assertj + assertj-core + ${assertj.version} + test + @@ -785,6 +791,7 @@ + 3.26.3 2.2.3 5.11.0 diff --git a/src/test/java/org/joda/money/TestBigMoney.java b/src/test/java/org/joda/money/TestBigMoney.java index 400efb7..4a89899 100644 --- a/src/test/java/org/joda/money/TestBigMoney.java +++ b/src/test/java/org/joda/money/TestBigMoney.java @@ -15,12 +15,9 @@ */ package org.joda.money; -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 static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -96,23 +93,21 @@ private static BigDecimal bd(String str) { @Test 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()); + assertThat(test.getCurrencyUnit()).isEqualTo(GBP); + assertThat(test.getAmount()).isEqualTo(BIGDEC_2_345); + assertThat(test.getScale()).isEqualTo(3); } @Test void test_factory_of_Currency_BigDecimal_nullCurrency() { - assertThrows(NullPointerException.class, () -> { - BigMoney.of((CurrencyUnit) null, BIGDEC_2_345); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> BigMoney.of((CurrencyUnit) null, BIGDEC_2_345)); } @Test void test_factory_of_Currency_BigDecimal_nullBigDecimal() { - assertThrows(NullPointerException.class, () -> { - BigMoney.of(GBP, (BigDecimal) null); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> BigMoney.of(GBP, (BigDecimal) null)); } @Test @@ -135,9 +130,8 @@ public int scale() { } } BigDecimal sub = new BadDecimal(); - assertThrows(IllegalArgumentException.class, () -> { - BigMoney.of(GBP, sub); - }); + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> BigMoney.of(GBP, sub)); } @Test @@ -168,10 +162,10 @@ public int scale() { } BigDecimal sub = new BadDecimal(); BigMoney test = BigMoney.of(GBP, sub); - assertEquals(GBP, test.getCurrencyUnit()); - assertEquals(bd("12.3"), test.getAmount()); - assertEquals(1, test.getScale()); - assertEquals(BigDecimal.class, test.getAmount().getClass()); + assertThat(test.getCurrencyUnit()).isEqualTo(GBP); + assertThat(test.getAmount()).isEqualTo(bd("12.3")); + assertThat(test.getScale()).isEqualTo(1); + assertThat(test.getAmount().getClass()).isEqualTo(BigDecimal.class); } //----------------------------------------------------------------------- @@ -180,57 +174,56 @@ public int scale() { @Test void test_factory_of_Currency_double() { BigMoney test = BigMoney.of(GBP, 2.345d); - assertEquals(GBP, test.getCurrencyUnit()); - assertEquals(BIGDEC_2_345, test.getAmount()); - assertEquals(3, test.getScale()); + assertThat(test.getCurrencyUnit()).isEqualTo(GBP); + assertThat(test.getAmount()).isEqualTo(BIGDEC_2_345); + assertThat(test.getScale()).isEqualTo(3); } @Test 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()); - assertEquals(2, test.getScale()); + assertThat(test.getCurrencyUnit()).isEqualTo(GBP); + assertThat(test.getAmount()).isEqualTo(BigDecimal.valueOf(123L, 2)); + assertThat(test.getScale()).isEqualTo(2); } @Test 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()); - assertEquals(1, test.getScale()); + assertThat(test.getCurrencyUnit()).isEqualTo(GBP); + assertThat(test.getAmount()).isEqualTo(BigDecimal.valueOf(12L, 1)); + assertThat(test.getScale()).isEqualTo(1); } @Test 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)); - assertEquals(BigMoney.of(GBP, BigDecimal.valueOf(0L, 0)), BigMoney.of(GBP, 0.00d)); - assertEquals(BigMoney.of(GBP, BigDecimal.valueOf(0L, 0)), BigMoney.of(GBP, -0.0d)); + assertThat(BigMoney.of(GBP, 0d)).isEqualTo(BigMoney.of(GBP, BigDecimal.valueOf(0L, 0))); + assertThat(BigMoney.of(GBP, -0d)).isEqualTo(BigMoney.of(GBP, BigDecimal.valueOf(0L, 0))); + assertThat(BigMoney.of(GBP, 0.0d)).isEqualTo(BigMoney.of(GBP, BigDecimal.valueOf(0L, 0))); + assertThat(BigMoney.of(GBP, 0.00d)).isEqualTo(BigMoney.of(GBP, BigDecimal.valueOf(0L, 0))); + assertThat(BigMoney.of(GBP, -0.0d)).isEqualTo(BigMoney.of(GBP, BigDecimal.valueOf(0L, 0))); } @Test void test_factory_of_Currency_double_medium() { BigMoney test = BigMoney.of(GBP, 2000d); - assertEquals(GBP, test.getCurrencyUnit()); - assertEquals(BigDecimal.valueOf(2000L, 0), test.getAmount()); - assertEquals(0, test.getScale()); + assertThat(test.getCurrencyUnit()).isEqualTo(GBP); + assertThat(test.getAmount()).isEqualTo(BigDecimal.valueOf(2000L, 0)); + assertThat(test.getScale()).isEqualTo(0); } @Test 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()); + assertThat(test.getCurrencyUnit()).isEqualTo(GBP); + assertThat(test.getAmount()).isEqualTo(BigDecimal.valueOf(200000000L, 0)); + assertThat(test.getScale()).isEqualTo(0); } @Test void test_factory_of_Currency_double_nullCurrency() { - assertThrows(NullPointerException.class, () -> { - BigMoney.of((CurrencyUnit) null, 2.345d); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> BigMoney.of((CurrencyUnit) null, 2.345d)); } //----------------------------------------------------------------------- @@ -239,36 +232,33 @@ void test_factory_of_Currency_double_nullCurrency() { @Test 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()); + assertThat(test.getCurrencyUnit()).isEqualTo(GBP); + assertThat(test.getAmount()).isEqualTo(BigDecimal.valueOf(23400, 4)); } @Test 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()); + assertThat(test.getCurrencyUnit()).isEqualTo(GBP); + assertThat(test.getAmount()).isEqualTo(BigDecimal.valueOf(23400L, 0)); } @Test void test_factory_ofScale_Currency_BigDecimal_invalidScale() { - assertThrows(ArithmeticException.class, () -> { - BigMoney.ofScale(GBP, BIGDEC_2_345, 2); - }); + assertThatExceptionOfType(ArithmeticException.class) + .isThrownBy(() -> BigMoney.ofScale(GBP, BIGDEC_2_345, 2)); } @Test void test_factory_ofScale_Currency_BigDecimal_nullCurrency() { - assertThrows(NullPointerException.class, () -> { - BigMoney.ofScale((CurrencyUnit) null, BIGDEC_2_34, 2); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> BigMoney.ofScale((CurrencyUnit) null, BIGDEC_2_34, 2)); } @Test void test_factory_ofScale_Currency_BigDecimal_nullBigDecimal() { - assertThrows(NullPointerException.class, () -> { - BigMoney.ofScale(GBP, (BigDecimal) null, 2); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> BigMoney.ofScale(GBP, (BigDecimal) null, 2)); } //----------------------------------------------------------------------- @@ -277,50 +267,46 @@ void test_factory_ofScale_Currency_BigDecimal_nullBigDecimal() { @Test 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()); + assertThat(test.getCurrencyUnit()).isEqualTo(GBP); + assertThat(test.getAmount()).isEqualTo(BigDecimal.valueOf(23, 1)); } @Test 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()); + assertThat(test.getCurrencyUnit()).isEqualTo(JPY); + assertThat(test.getAmount()).isEqualTo(BigDecimal.valueOf(3, 0)); } @Test 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()); + assertThat(test.getCurrencyUnit()).isEqualTo(GBP); + assertThat(test.getAmount()).isEqualTo(BigDecimal.valueOf(23400L, 0)); } @Test void test_factory_ofScale_Currency_BigDecimal_int_RoundingMode_UNNECESSARY() { - assertThrows(ArithmeticException.class, () -> { - BigMoney.ofScale(JPY, BIGDEC_2_34, 1, RoundingMode.UNNECESSARY); - }); + assertThatExceptionOfType(ArithmeticException.class) + .isThrownBy(() -> BigMoney.ofScale(JPY, BIGDEC_2_34, 1, RoundingMode.UNNECESSARY)); } @Test void test_factory_ofScale_Currency_BigDecimal_int_RoundingMode_nullCurrency() { - assertThrows(NullPointerException.class, () -> { - BigMoney.ofScale((CurrencyUnit) null, BIGDEC_2_34, 2, RoundingMode.DOWN); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> BigMoney.ofScale((CurrencyUnit) null, BIGDEC_2_34, 2, RoundingMode.DOWN)); } @Test void test_factory_ofScale_Currency_BigDecimal_int_RoundingMode_nullBigDecimal() { - assertThrows(NullPointerException.class, () -> { - BigMoney.ofScale(GBP, (BigDecimal) null, 2, RoundingMode.DOWN); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> BigMoney.ofScale(GBP, (BigDecimal) null, 2, RoundingMode.DOWN)); } @Test void test_factory_ofScale_Currency_BigDecimal_int_RoundingMode_nullRoundingMode() { - assertThrows(NullPointerException.class, () -> { - BigMoney.ofScale(GBP, BIGDEC_2_34, 2, (RoundingMode) null); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> BigMoney.ofScale(GBP, BIGDEC_2_34, 2, (RoundingMode) null)); } //----------------------------------------------------------------------- @@ -329,22 +315,21 @@ void test_factory_ofScale_Currency_BigDecimal_int_RoundingMode_nullRoundingMode( @Test 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()); + assertThat(test.getCurrencyUnit()).isEqualTo(GBP); + assertThat(test.getAmount()).isEqualTo(BigDecimal.valueOf(234, 4)); } @Test 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()); + assertThat(test.getCurrencyUnit()).isEqualTo(GBP); + assertThat(test.getAmount()).isEqualTo(BigDecimal.valueOf(2340000, 0)); } @Test void test_factory_ofScale_Currency_long_int_nullCurrency() { - assertThrows(NullPointerException.class, () -> { - BigMoney.ofScale((CurrencyUnit) null, 234, 2); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> BigMoney.ofScale((CurrencyUnit) null, 234, 2)); } //----------------------------------------------------------------------- @@ -353,16 +338,15 @@ void test_factory_ofScale_Currency_long_int_nullCurrency() { @Test 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()); + assertThat(test.getCurrencyUnit()).isEqualTo(GBP); + assertThat(test.getAmount()).isEqualTo(bd("234")); + assertThat(test.getScale()).isEqualTo(0); } @Test void test_factory_ofMajor_Currency_long_nullCurrency() { - assertThrows(NullPointerException.class, () -> { - BigMoney.ofMajor((CurrencyUnit) null, 234); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> BigMoney.ofMajor((CurrencyUnit) null, 234)); } //----------------------------------------------------------------------- @@ -371,16 +355,15 @@ void test_factory_ofMajor_Currency_long_nullCurrency() { @Test 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()); + assertThat(test.getCurrencyUnit()).isEqualTo(GBP); + assertThat(test.getAmount()).isEqualTo(bd("2.34")); + assertThat(test.getScale()).isEqualTo(2); } @Test void test_factory_ofMinor_Currency_long_nullCurrency() { - assertThrows(NullPointerException.class, () -> { - BigMoney.ofMinor((CurrencyUnit) null, 234); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> BigMoney.ofMinor((CurrencyUnit) null, 234)); } //----------------------------------------------------------------------- @@ -389,16 +372,15 @@ void test_factory_ofMinor_Currency_long_nullCurrency() { @Test void test_factory_zero_Currency() { BigMoney test = BigMoney.zero(GBP); - assertEquals(GBP, test.getCurrencyUnit()); - assertEquals(BigDecimal.ZERO, test.getAmount()); - assertEquals(0, test.getScale()); + assertThat(test.getCurrencyUnit()).isEqualTo(GBP); + assertThat(test.getAmount()).isEqualTo(BigDecimal.ZERO); + assertThat(test.getScale()).isEqualTo(0); } @Test void test_factory_zero_Currency_nullCurrency() { - assertThrows(NullPointerException.class, () -> { - BigMoney.zero((CurrencyUnit) null); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> BigMoney.zero((CurrencyUnit) null)); } //----------------------------------------------------------------------- @@ -407,22 +389,21 @@ void test_factory_zero_Currency_nullCurrency() { @Test void test_factory_zero_Currency_int() { BigMoney test = BigMoney.zero(GBP, 3); - assertEquals(GBP, test.getCurrencyUnit()); - assertEquals(BigDecimal.valueOf(0, 3), test.getAmount()); + assertThat(test.getCurrencyUnit()).isEqualTo(GBP); + assertThat(test.getAmount()).isEqualTo(BigDecimal.valueOf(0, 3)); } @Test void test_factory_zero_Currency_int_negativeScale() { BigMoney test = BigMoney.zero(GBP, -3); - assertEquals(GBP, test.getCurrencyUnit()); - assertEquals(BigDecimal.valueOf(0, 0), test.getAmount()); + assertThat(test.getCurrencyUnit()).isEqualTo(GBP); + assertThat(test.getAmount()).isEqualTo(BigDecimal.valueOf(0, 0)); } @Test void test_factory_zero_Currency_int_nullCurrency() { - assertThrows(NullPointerException.class, () -> { - BigMoney.zero((CurrencyUnit) null, 3); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> BigMoney.zero((CurrencyUnit) null, 3)); } //----------------------------------------------------------------------- @@ -431,23 +412,21 @@ void test_factory_zero_Currency_int_nullCurrency() { @Test 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()); + assertThat(test.getCurrencyUnit()).isEqualTo(GBP); + assertThat(test.getAmountMinorInt()).isEqualTo(10423); + assertThat(test.getScale()).isEqualTo(2); } @Test void test_factory_from_BigMoneyProvider_nullBigMoneyProvider() { - assertThrows(NullPointerException.class, () -> { - BigMoney.of((BigMoneyProvider) null); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> BigMoney.of((BigMoneyProvider) null)); } @Test void test_factory_from_BigMoneyProvider_badProvider() { - assertThrows(NullPointerException.class, () -> { - BigMoney.of(BAD_PROVIDER); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> BigMoney.of(BAD_PROVIDER)); } //----------------------------------------------------------------------- @@ -456,114 +435,104 @@ void test_factory_from_BigMoneyProvider_badProvider() { @Test void test_factory_total_varargs_1BigMoney() { BigMoney test = BigMoney.total(GBP_1_23); - assertEquals(GBP, test.getCurrencyUnit()); - assertEquals(123, test.getAmountMinorInt()); + assertThat(test.getCurrencyUnit()).isEqualTo(GBP); + assertThat(test.getAmountMinorInt()).isEqualTo(123); } @Test void test_factory_total_array_1BigMoney() { BigMoneyProvider[] array = new BigMoneyProvider[] {GBP_1_23}; BigMoney test = BigMoney.total(array); - assertEquals(GBP, test.getCurrencyUnit()); - assertEquals(123, test.getAmountMinorInt()); + assertThat(test.getCurrencyUnit()).isEqualTo(GBP); + assertThat(test.getAmountMinorInt()).isEqualTo(123); } @Test 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()); + assertThat(test.getCurrencyUnit()).isEqualTo(GBP); + assertThat(test.getAmountMinorInt()).isEqualTo(592); } @Test 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()); - assertEquals(592, test.getAmountMinorInt()); + assertThat(test.getCurrencyUnit()).isEqualTo(GBP); + assertThat(test.getAmountMinorInt()).isEqualTo(592); } @Test 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()); + assertThat(test.getCurrencyUnit()).isEqualTo(GBP); + assertThat(test.getAmountMinorInt()).isEqualTo(592); } @Test void test_factory_total_varargs_empty() { - assertThrows(IllegalArgumentException.class, () -> { - BigMoney.total(); - }); + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> BigMoney.total()); } @Test void test_factory_total_array_empty() { BigMoneyProvider[] array = new BigMoneyProvider[0]; - assertThrows(IllegalArgumentException.class, () -> { - BigMoney.total(array); - }); + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> BigMoney.total(array)); } @Test void test_factory_total_varargs_currenciesDiffer() { - assertThrows(CurrencyMismatchException.class, () -> { - BigMoney.total(GBP_2_33, JPY_423); - }); + assertThatExceptionOfType(CurrencyMismatchException.class) + .isThrownBy(() -> BigMoney.total(GBP_2_33, JPY_423)); } @Test void test_factory_total_array_currenciesDiffer() { BigMoneyProvider[] array = new BigMoneyProvider[] {GBP_2_33, JPY_423}; - assertThrows(CurrencyMismatchException.class, () -> { - BigMoney.total(array); - }); + assertThatExceptionOfType(CurrencyMismatchException.class) + .isThrownBy(() -> BigMoney.total(array)); } @Test void test_factory_total_varargs_nullFirst() { - assertThrows(NullPointerException.class, () -> { - BigMoney.total((BigMoney) null, GBP_2_33, GBP_2_36); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> BigMoney.total((BigMoney) null, GBP_2_33, GBP_2_36)); } @Test void test_factory_total_array_nullFirst() { BigMoneyProvider[] array = new BigMoneyProvider[] {null, GBP_2_33, GBP_2_36}; - assertThrows(NullPointerException.class, () -> { - BigMoney.total(array); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> BigMoney.total(array)); } @Test void test_factory_total_varargs_nullNotFirst() { - assertThrows(NullPointerException.class, () -> { - BigMoney.total(GBP_2_33, null, GBP_2_36); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> BigMoney.total(GBP_2_33, null, GBP_2_36)); } @Test void test_factory_total_array_nullNotFirst() { BigMoneyProvider[] array = new BigMoneyProvider[] {GBP_2_33, null, GBP_2_36}; - assertThrows(NullPointerException.class, () -> { - BigMoney.total(array); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> BigMoney.total(array)); } @Test void test_factory_total_varargs_badProvider() { - assertThrows(NullPointerException.class, () -> { - BigMoney.total(BAD_PROVIDER); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> BigMoney.total(BAD_PROVIDER)); } @Test void test_factory_total_array_badProvider() { BigMoneyProvider[] array = new BigMoneyProvider[] {BAD_PROVIDER}; - assertThrows(NullPointerException.class, () -> { - BigMoney.total(array); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> BigMoney.total(array)); } //----------------------------------------------------------------------- @@ -573,56 +542,51 @@ void test_factory_total_array_badProvider() { 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()); - assertEquals(BigDecimal.valueOf(5921, 3), test.getAmount()); + assertThat(test.getCurrencyUnit()).isEqualTo(GBP); + assertThat(test.getAmount()).isEqualTo(BigDecimal.valueOf(5921, 3)); } @Test 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()); + assertThat(test.getCurrencyUnit()).isEqualTo(GBP); + assertThat(test.getAmount()).isEqualTo(BigDecimal.valueOf(356, 2)); } @Test void test_factory_total_Iterable_empty() { Iterable iterable = Collections.emptyList(); - assertThrows(IllegalArgumentException.class, () -> { - BigMoney.total(iterable); - }); + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> BigMoney.total(iterable)); } @Test void test_factory_total_Iterable_currenciesDiffer() { Iterable iterable = Arrays.asList(GBP_2_33, JPY_423); - assertThrows(CurrencyMismatchException.class, () -> { - BigMoney.total(iterable); - }); + assertThatExceptionOfType(CurrencyMismatchException.class) + .isThrownBy(() -> BigMoney.total(iterable)); } @Test void test_factory_total_Iterable_nullFirst() { Iterable iterable = Arrays.asList(null, GBP_2_33, GBP_2_36); - assertThrows(NullPointerException.class, () -> { - BigMoney.total(iterable); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> BigMoney.total(iterable)); } @Test void test_factory_total_Iterable_nullNotFirst() { Iterable iterable = Arrays.asList(GBP_2_33, null, GBP_2_36); - assertThrows(NullPointerException.class, () -> { - BigMoney.total(iterable); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> BigMoney.total(iterable)); } @Test void test_factory_total_Iterable_badProvider() { Iterable iterable = Arrays.asList(BAD_PROVIDER); - assertThrows(NullPointerException.class, () -> { - BigMoney.total(iterable); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> BigMoney.total(iterable)); } //----------------------------------------------------------------------- @@ -631,144 +595,134 @@ void test_factory_total_Iterable_badProvider() { @Test void test_factory_total_CurrencyUnitVarargs_1() { BigMoney test = BigMoney.total(GBP, GBP_1_23); - assertEquals(GBP, test.getCurrencyUnit()); - assertEquals(123, test.getAmountMinorInt()); + assertThat(test.getCurrencyUnit()).isEqualTo(GBP); + assertThat(test.getAmountMinorInt()).isEqualTo(123); } @Test void test_factory_total_CurrencyUnitArray_1() { BigMoney[] array = new BigMoney[] {GBP_1_23}; BigMoney test = BigMoney.total(GBP, array); - assertEquals(GBP, test.getCurrencyUnit()); - assertEquals(123, test.getAmountMinorInt()); + assertThat(test.getCurrencyUnit()).isEqualTo(GBP); + assertThat(test.getAmountMinorInt()).isEqualTo(123); } @Test 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()); + assertThat(test.getCurrencyUnit()).isEqualTo(GBP); + assertThat(test.getAmountMinorInt()).isEqualTo(592); } @Test 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()); - assertEquals(592, test.getAmountMinorInt()); + assertThat(test.getCurrencyUnit()).isEqualTo(GBP); + assertThat(test.getAmountMinorInt()).isEqualTo(592); } @Test 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()); + assertThat(test.getCurrencyUnit()).isEqualTo(GBP); + assertThat(test.getAmountMinorInt()).isEqualTo(592); } @Test 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()); - assertEquals(592, test.getAmountMinorInt()); + assertThat(test.getCurrencyUnit()).isEqualTo(GBP); + assertThat(test.getAmountMinorInt()).isEqualTo(592); } @Test 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()); - assertEquals(592, test.getAmountMinorInt()); + assertThat(test.getCurrencyUnit()).isEqualTo(GBP); + assertThat(test.getAmountMinorInt()).isEqualTo(592); } @Test void test_factory_total_CurrencyUnitVarargs_empty() { BigMoney test = BigMoney.total(GBP); - assertEquals(GBP, test.getCurrencyUnit()); - assertEquals(0, test.getAmountMinorInt()); + assertThat(test.getCurrencyUnit()).isEqualTo(GBP); + assertThat(test.getAmountMinorInt()).isEqualTo(0); } @Test 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()); + assertThat(test.getCurrencyUnit()).isEqualTo(GBP); + assertThat(test.getAmountMinorInt()).isEqualTo(0); } @Test void test_factory_total_CurrencyUnitVarargs_currenciesDiffer() { - assertThrows(CurrencyMismatchException.class, () -> { - BigMoney.total(GBP, JPY_423); - }); + assertThatExceptionOfType(CurrencyMismatchException.class) + .isThrownBy(() -> BigMoney.total(GBP, JPY_423)); } @Test void test_factory_total_CurrencyUnitArray_currenciesDiffer() { BigMoney[] array = new BigMoney[] {JPY_423}; - assertThrows(CurrencyMismatchException.class, () -> { - BigMoney.total(GBP, array); - }); + assertThatExceptionOfType(CurrencyMismatchException.class) + .isThrownBy(() -> BigMoney.total(GBP, array)); } @Test void test_factory_total_CurrencyUnitVarargs_currenciesDifferInArray() { - assertThrows(CurrencyMismatchException.class, () -> { - BigMoney.total(GBP, GBP_2_33, JPY_423); - }); + assertThatExceptionOfType(CurrencyMismatchException.class) + .isThrownBy(() -> BigMoney.total(GBP, GBP_2_33, JPY_423)); } @Test void test_factory_total_CurrencyUnitArray_currenciesDifferInArray() { BigMoney[] array = new BigMoney[] {GBP_2_33, JPY_423}; - assertThrows(CurrencyMismatchException.class, () -> { - BigMoney.total(GBP, array); - }); + assertThatExceptionOfType(CurrencyMismatchException.class) + .isThrownBy(() -> BigMoney.total(GBP, array)); } @Test void test_factory_total_CurrencyUnitVarargs_nullFirst() { - assertThrows(NullPointerException.class, () -> { - BigMoney.total(GBP, null, GBP_2_33, GBP_2_36); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> BigMoney.total(GBP, null, GBP_2_33, GBP_2_36)); } @Test void test_factory_total_CurrencyUnitArray_nullFirst() { BigMoney[] array = new BigMoney[] {null, GBP_2_33, GBP_2_36}; - assertThrows(NullPointerException.class, () -> { - BigMoney.total(GBP, array); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> BigMoney.total(GBP, array)); } @Test void test_factory_total_CurrencyUnitVarargs_nullNotFirst() { - assertThrows(NullPointerException.class, () -> { - BigMoney.total(GBP, GBP_2_33, null, GBP_2_36); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> BigMoney.total(GBP, GBP_2_33, null, GBP_2_36)); } @Test void test_factory_total_CurrencyUnitArray_nullNotFirst() { BigMoney[] array = new BigMoney[] {GBP_2_33, null, GBP_2_36}; - assertThrows(NullPointerException.class, () -> { - BigMoney.total(GBP, array); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> BigMoney.total(GBP, array)); } @Test void test_factory_total_CurrencyUnitVarargs_badProvider() { - assertThrows(NullPointerException.class, () -> { - BigMoney.total(GBP, BAD_PROVIDER); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> BigMoney.total(GBP, BAD_PROVIDER)); } @Test void test_factory_total_CurrencyUnitArray_badProvider() { BigMoneyProvider[] array = new BigMoneyProvider[] {BAD_PROVIDER}; - assertThrows(NullPointerException.class, () -> { - BigMoney.total(GBP, array); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> BigMoney.total(GBP, array)); } //----------------------------------------------------------------------- @@ -778,64 +732,59 @@ void test_factory_total_CurrencyUnitArray_badProvider() { 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()); - assertEquals(BigDecimal.valueOf(5921, 3), test.getAmount()); + assertThat(test.getCurrencyUnit()).isEqualTo(GBP); + assertThat(test.getAmount()).isEqualTo(BigDecimal.valueOf(5921, 3)); } @Test 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()); - assertEquals(BigDecimal.valueOf(356, 2), test.getAmount()); + assertThat(test.getCurrencyUnit()).isEqualTo(GBP); + assertThat(test.getAmount()).isEqualTo(BigDecimal.valueOf(356, 2)); } @Test void test_factory_total_CurrencyUnitIterable_empty() { Iterable iterable = Collections.emptyList(); BigMoney test = BigMoney.total(GBP, iterable); - assertEquals(GBP, test.getCurrencyUnit()); - assertEquals(0, test.getAmountMinorInt()); + assertThat(test.getCurrencyUnit()).isEqualTo(GBP); + assertThat(test.getAmountMinorInt()).isEqualTo(0); } @Test void test_factory_total_CurrencyUnitIterable_currenciesDiffer() { Iterable iterable = Arrays.asList(JPY_423); - assertThrows(CurrencyMismatchException.class, () -> { - BigMoney.total(GBP, iterable); - }); + assertThatExceptionOfType(CurrencyMismatchException.class) + .isThrownBy(() -> BigMoney.total(GBP, iterable)); } @Test void test_factory_total_CurrencyUnitIterable_currenciesDifferInIterable() { Iterable iterable = Arrays.asList(GBP_2_33, JPY_423); - assertThrows(CurrencyMismatchException.class, () -> { - BigMoney.total(GBP, iterable); - }); + assertThatExceptionOfType(CurrencyMismatchException.class) + .isThrownBy(() -> BigMoney.total(GBP, iterable)); } @Test void test_factory_total_CurrencyUnitIterable_nullFirst() { Iterable iterable = Arrays.asList(null, GBP_2_33, GBP_2_36); - assertThrows(NullPointerException.class, () -> { - BigMoney.total(GBP, iterable); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> BigMoney.total(GBP, iterable)); } @Test void test_factory_total_CurrencyUnitIterable_nullNotFirst() { Iterable iterable = Arrays.asList(GBP_2_33, null, GBP_2_36); - assertThrows(NullPointerException.class, () -> { - BigMoney.total(GBP, iterable); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> BigMoney.total(GBP, iterable)); } @Test void test_factory_total_CurrencyUnitIterable_badProvider() { Iterable iterable = Arrays.asList(BAD_PROVIDER); - assertThrows(NullPointerException.class, () -> { - BigMoney.total(GBP, iterable); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> BigMoney.total(GBP, iterable)); } //----------------------------------------------------------------------- @@ -868,37 +817,33 @@ public static Object[][] data_parse() { @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()); + assertThat(test.getCurrencyUnit()).isEqualTo(currency); + assertThat(test.getAmount()).isEqualTo(bd(amountStr)); + assertThat(test.getScale()).isEqualTo(scale); } @Test void test_factory_parse_String_tooShort() { - assertThrows(IllegalArgumentException.class, () -> { - BigMoney.parse("GBP"); - }); + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> BigMoney.parse("GBP")); } @Test void test_factory_parse_String_exponent() { - assertThrows(IllegalArgumentException.class, () -> { - BigMoney.parse("GBP 234E2"); - }); + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> BigMoney.parse("GBP 234E2")); } @Test void test_factory_parse_String_badCurrency() { - assertThrows(IllegalArgumentException.class, () -> { - BigMoney.parse("GBX 2.34"); - }); + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> BigMoney.parse("GBX 2.34")); } @Test void test_factory_parse_String_nullString() { - assertThrows(NullPointerException.class, () -> { - BigMoney.parse((String) null); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> BigMoney.parse((String) null)); } //----------------------------------------------------------------------- @@ -907,14 +852,14 @@ void test_factory_parse_String_nullString() { @Test void test_constructor_null1() throws Exception { Constructor con = BigMoney.class.getDeclaredConstructor(CurrencyUnit.class, BigDecimal.class); - assertFalse(Modifier.isPublic(con.getModifiers())); - assertFalse(Modifier.isProtected(con.getModifiers())); + assertThat(Modifier.isPublic(con.getModifiers())).isFalse(); + assertThat(Modifier.isProtected(con.getModifiers())).isFalse(); try { con.setAccessible(true); con.newInstance(new Object[] {null, BIGDEC_2_34}); - fail(); + fail(""); } catch (InvocationTargetException ex) { - assertEquals(AssertionError.class, ex.getCause().getClass()); + assertThat(ex.getCause().getClass()).isEqualTo(AssertionError.class); } } @@ -924,9 +869,9 @@ void test_constructor_null2() throws Exception { try { con.setAccessible(true); con.newInstance(new Object[] {GBP, null}); - fail(); + fail(""); } catch (InvocationTargetException ex) { - assertEquals(AssertionError.class, ex.getCause().getClass()); + assertThat(ex.getCause().getClass()).isEqualTo(AssertionError.class); } } @@ -935,39 +880,39 @@ void test_constructor_null2() throws Exception { 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()); - assertTrue(a.equals(a)); - assertTrue(b.equals(b)); - assertTrue(a.equals(b)); - assertTrue(b.equals(a)); - assertTrue(a.hashCode() == b.hashCode()); + assertThat(a.toString()).isEqualTo("GBP 100"); + assertThat(b.toString()).isEqualTo("GBP 100"); + assertThat(a).isEqualTo(a); + assertThat(b).isEqualTo(b); + assertThat(b).isEqualTo(a); + assertThat(a).isEqualTo(b); + assertThat(b.hashCode()).isEqualTo(a.hashCode()); } @Test 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()); - assertTrue(a.equals(a)); - assertTrue(b.equals(b)); - assertFalse(a.equals(b)); - assertFalse(b.equals(a)); - assertFalse(a.hashCode() == b.hashCode()); + assertThat(a.toString()).isEqualTo("GBP 0.1"); + assertThat(b.toString()).isEqualTo("GBP 0.10"); + assertThat(a).isEqualTo(a); + assertThat(b).isEqualTo(b); + assertThat(b).isNotEqualTo(a); + assertThat(a).isNotEqualTo(b); + assertThat(a.hashCode() == b.hashCode()).isFalse(); } @Test 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()); - assertTrue(a.equals(a)); - assertTrue(b.equals(b)); - assertTrue(a.equals(b)); - assertTrue(b.equals(a)); - assertTrue(a.hashCode() == b.hashCode()); + assertThat(a.toString()).isEqualTo("GBP 100"); + assertThat(b.toString()).isEqualTo("GBP 100"); + assertThat(a).isEqualTo(a); + assertThat(b).isEqualTo(b); + assertThat(b).isEqualTo(a); + assertThat(a).isEqualTo(b); + assertThat(b.hashCode()).isEqualTo(a.hashCode()); } //----------------------------------------------------------------------- @@ -982,7 +927,7 @@ void test_serialization() throws Exception { oos.close(); ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); BigMoney input = (BigMoney) ois.readObject(); - assertEquals(a, input); + assertThat(input).isEqualTo(a); } } @@ -995,9 +940,8 @@ void test_serialization_invalidNumericCode() throws IOException { oos.writeObject(m); oos.close(); ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); - assertThrows(InvalidObjectException.class, () -> { - ois.readObject(); - }); + assertThatExceptionOfType(InvalidObjectException.class) + .isThrownBy(() -> ois.readObject()); } } @@ -1010,9 +954,8 @@ void test_serialization_invalidDecimalPlaces() throws IOException { oos.writeObject(m); oos.close(); ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); - assertThrows(InvalidObjectException.class, () -> { - ois.readObject(); - }); + assertThatExceptionOfType(InvalidObjectException.class) + .isThrownBy(() -> ois.readObject()); } } @@ -1021,12 +964,12 @@ void test_serialization_invalidDecimalPlaces() throws IOException { //----------------------------------------------------------------------- @Test void test_getCurrencyUnit_GBP() { - assertEquals(GBP, GBP_2_34.getCurrencyUnit()); + assertThat(GBP_2_34.getCurrencyUnit()).isEqualTo(GBP); } @Test void test_getCurrencyUnit_EUR() { - assertEquals(EUR, BigMoney.parse("EUR -5.78").getCurrencyUnit()); + assertThat(BigMoney.parse("EUR -5.78").getCurrencyUnit()).isEqualTo(EUR); } //----------------------------------------------------------------------- @@ -1035,26 +978,25 @@ void test_getCurrencyUnit_EUR() { @Test void test_withCurrencyUnit_Currency() { BigMoney test = GBP_2_34.withCurrencyUnit(USD); - assertEquals("USD 2.34", test.toString()); + assertThat(test).hasToString("USD 2.34"); } @Test void test_withCurrencyUnit_Currency_same() { BigMoney test = GBP_2_34.withCurrencyUnit(GBP); - assertSame(GBP_2_34, test); + assertThat(test).isSameAs(GBP_2_34); } @Test void test_withCurrencyUnit_Currency_differentCurrencyScale() { BigMoney test = GBP_2_34.withCurrencyUnit(JPY); - assertEquals("JPY 2.34", test.toString()); + assertThat(test).hasToString("JPY 2.34"); } @Test void test_withCurrencyUnit_Currency_nullCurrency() { - assertThrows(NullPointerException.class, () -> { - GBP_2_34.withCurrencyUnit((CurrencyUnit) null); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> GBP_2_34.withCurrencyUnit((CurrencyUnit) null)); } //----------------------------------------------------------------------- @@ -1062,12 +1004,12 @@ void test_withCurrencyUnit_Currency_nullCurrency() { //----------------------------------------------------------------------- @Test void test_getScale_GBP() { - assertEquals(2, GBP_2_34.getScale()); + assertThat(GBP_2_34.getScale()).isEqualTo(2); } @Test void test_getScale_JPY() { - assertEquals(0, JPY_423.getScale()); + assertThat(JPY_423.getScale()).isEqualTo(0); } //----------------------------------------------------------------------- @@ -1075,18 +1017,18 @@ void test_getScale_JPY() { //----------------------------------------------------------------------- @Test 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()); + assertThat(BigMoney.parse("GBP 2").isCurrencyScale()).isFalse(); + assertThat(BigMoney.parse("GBP 2.3").isCurrencyScale()).isFalse(); + assertThat(BigMoney.parse("GBP 2.34").isCurrencyScale()).isTrue(); + assertThat(BigMoney.parse("GBP 2.345").isCurrencyScale()).isFalse(); } @Test 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()); + assertThat(BigMoney.parse("JPY 2").isCurrencyScale()).isTrue(); + assertThat(BigMoney.parse("JPY 2.3").isCurrencyScale()).isFalse(); + assertThat(BigMoney.parse("JPY 2.34").isCurrencyScale()).isFalse(); + assertThat(BigMoney.parse("JPY 2.345").isCurrencyScale()).isFalse(); } //----------------------------------------------------------------------- @@ -1095,21 +1037,20 @@ void test_isCurrencyScale_JPY() { @Test void test_withScale_int_same() { BigMoney test = GBP_2_34.withScale(2); - assertSame(GBP_2_34, test); + assertThat(test).isSameAs(GBP_2_34); } @Test void test_withScale_int_more() { BigMoney test = GBP_2_34.withScale(3); - assertEquals(bd("2.340"), test.getAmount()); - assertEquals(3, test.getScale()); + assertThat(test.getAmount()).isEqualTo(bd("2.340")); + assertThat(test.getScale()).isEqualTo(3); } @Test void test_withScale_int_less() { - assertThrows(ArithmeticException.class, () -> { - BigMoney.parse("GBP 2.345").withScale(2); - }); + assertThatExceptionOfType(ArithmeticException.class) + .isThrownBy(() -> BigMoney.parse("GBP 2.345").withScale(2)); } //----------------------------------------------------------------------- @@ -1118,15 +1059,15 @@ void test_withScale_int_less() { @Test void test_withScale_intRoundingMode_less() { BigMoney test = GBP_2_34.withScale(1, RoundingMode.UP); - assertEquals(bd("2.4"), test.getAmount()); - assertEquals(1, test.getScale()); + assertThat(test.getAmount()).isEqualTo(bd("2.4")); + assertThat(test.getScale()).isEqualTo(1); } @Test void test_withScale_intRoundingMode_more() { BigMoney test = GBP_2_34.withScale(3, RoundingMode.UP); - assertEquals(bd("2.340"), test.getAmount()); - assertEquals(3, test.getScale()); + assertThat(test.getAmount()).isEqualTo(bd("2.340")); + assertThat(test.getScale()).isEqualTo(3); } //----------------------------------------------------------------------- @@ -1135,21 +1076,20 @@ void test_withScale_intRoundingMode_more() { @Test void test_withCurrencyScale_int_same() { BigMoney test = GBP_2_34.withCurrencyScale(); - assertSame(GBP_2_34, test); + assertThat(test).isSameAs(GBP_2_34); } @Test void test_withCurrencyScale_int_more() { BigMoney test = BigMoney.parse("GBP 2.3").withCurrencyScale(); - assertEquals(bd("2.30"), test.getAmount()); - assertEquals(2, test.getScale()); + assertThat(test.getAmount()).isEqualTo(bd("2.30")); + assertThat(test.getScale()).isEqualTo(2); } @Test void test_withCurrencyScale_int_less() { - assertThrows(ArithmeticException.class, () -> { - BigMoney.parse("GBP 2.345").withCurrencyScale(); - }); + assertThatExceptionOfType(ArithmeticException.class) + .isThrownBy(() -> BigMoney.parse("GBP 2.345").withCurrencyScale()); } //----------------------------------------------------------------------- @@ -1158,22 +1098,22 @@ void test_withCurrencyScale_int_less() { @Test 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()); + assertThat(test.getAmount()).isEqualTo(bd("2.35")); + assertThat(test.getScale()).isEqualTo(2); } @Test 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()); + assertThat(test.getAmount()).isEqualTo(bd("2.30")); + assertThat(test.getScale()).isEqualTo(2); } @Test void test_withCurrencyScale_intRoundingMode_lessJPY() { BigMoney test = BigMoney.parse("JPY 2.345").withCurrencyScale(RoundingMode.UP); - assertEquals(bd("3"), test.getAmount()); - assertEquals(0, test.getScale()); + assertThat(test.getAmount()).isEqualTo(bd("3")); + assertThat(test.getScale()).isEqualTo(0); } //----------------------------------------------------------------------- @@ -1181,12 +1121,12 @@ void test_withCurrencyScale_intRoundingMode_lessJPY() { //----------------------------------------------------------------------- @Test void test_getAmount_positive() { - assertEquals(BIGDEC_2_34, GBP_2_34.getAmount()); + assertThat(GBP_2_34.getAmount()).isEqualTo(BIGDEC_2_34); } @Test void test_getAmount_negative() { - assertEquals(BIGDEC_M5_78, GBP_M5_78.getAmount()); + assertThat(GBP_M5_78.getAmount()).isEqualTo(BIGDEC_M5_78); } //----------------------------------------------------------------------- @@ -1194,12 +1134,12 @@ void test_getAmount_negative() { //----------------------------------------------------------------------- @Test void test_getAmountMajor_positive() { - assertEquals(BigDecimal.valueOf(2), GBP_2_34.getAmountMajor()); + assertThat(GBP_2_34.getAmountMajor()).isEqualTo(BigDecimal.valueOf(2)); } @Test void test_getAmountMajor_negative() { - assertEquals(BigDecimal.valueOf(-5), GBP_M5_78.getAmountMajor()); + assertThat(GBP_M5_78.getAmountMajor()).isEqualTo(BigDecimal.valueOf(-5)); } //----------------------------------------------------------------------- @@ -1207,26 +1147,24 @@ void test_getAmountMajor_negative() { //----------------------------------------------------------------------- @Test void test_getAmountMajorLong_positive() { - assertEquals(2L, GBP_2_34.getAmountMajorLong()); + assertThat(GBP_2_34.getAmountMajorLong()).isEqualTo(2L); } @Test void test_getAmountMajorLong_negative() { - assertEquals(-5L, GBP_M5_78.getAmountMajorLong()); + assertThat(GBP_M5_78.getAmountMajorLong()).isEqualTo(-5L); } @Test void test_getAmountMajorLong_tooBigPositive() { - assertThrows(ArithmeticException.class, () -> { - GBP_LONG_MAX_MAJOR_PLUS1.getAmountMajorLong(); - }); + assertThatExceptionOfType(ArithmeticException.class) + .isThrownBy(() -> GBP_LONG_MAX_MAJOR_PLUS1.getAmountMajorLong()); } @Test void test_getAmountMajorLong_tooBigNegative() { - assertThrows(ArithmeticException.class, () -> { - GBP_LONG_MIN_MAJOR_MINUS1.getAmountMajorLong(); - }); + assertThatExceptionOfType(ArithmeticException.class) + .isThrownBy(() -> GBP_LONG_MIN_MAJOR_MINUS1.getAmountMajorLong()); } //----------------------------------------------------------------------- @@ -1234,26 +1172,24 @@ void test_getAmountMajorLong_tooBigNegative() { //----------------------------------------------------------------------- @Test void test_getAmountMajorInt_positive() { - assertEquals(2, GBP_2_34.getAmountMajorInt()); + assertThat(GBP_2_34.getAmountMajorInt()).isEqualTo(2); } @Test void test_getAmountMajorInt_negative() { - assertEquals(-5, GBP_M5_78.getAmountMajorInt()); + assertThat(GBP_M5_78.getAmountMajorInt()).isEqualTo(-5); } @Test void test_getAmountMajorInt_tooBigPositive() { - assertThrows(ArithmeticException.class, () -> { - GBP_INT_MAX_MAJOR_PLUS1.getAmountMajorInt(); - }); + assertThatExceptionOfType(ArithmeticException.class) + .isThrownBy(() -> GBP_INT_MAX_MAJOR_PLUS1.getAmountMajorInt()); } @Test void test_getAmountMajorInt_tooBigNegative() { - assertThrows(ArithmeticException.class, () -> { - GBP_INT_MIN_MAJOR_MINUS1.getAmountMajorInt(); - }); + assertThatExceptionOfType(ArithmeticException.class) + .isThrownBy(() -> GBP_INT_MIN_MAJOR_MINUS1.getAmountMajorInt()); } //----------------------------------------------------------------------- @@ -1261,12 +1197,12 @@ void test_getAmountMajorInt_tooBigNegative() { //----------------------------------------------------------------------- @Test void test_getAmountMinor_positive() { - assertEquals(BigDecimal.valueOf(234), GBP_2_34.getAmountMinor()); + assertThat(GBP_2_34.getAmountMinor()).isEqualTo(BigDecimal.valueOf(234)); } @Test void test_getAmountMinor_negative() { - assertEquals(BigDecimal.valueOf(-578), GBP_M5_78.getAmountMinor()); + assertThat(GBP_M5_78.getAmountMinor()).isEqualTo(BigDecimal.valueOf(-578)); } //----------------------------------------------------------------------- @@ -1274,26 +1210,24 @@ void test_getAmountMinor_negative() { //----------------------------------------------------------------------- @Test void test_getAmountMinorLong_positive() { - assertEquals(234L, GBP_2_34.getAmountMinorLong()); + assertThat(GBP_2_34.getAmountMinorLong()).isEqualTo(234L); } @Test void test_getAmountMinorLong_negative() { - assertEquals(-578L, GBP_M5_78.getAmountMinorLong()); + assertThat(GBP_M5_78.getAmountMinorLong()).isEqualTo(-578L); } @Test void test_getAmountMinorLong_tooBigPositive() { - assertThrows(ArithmeticException.class, () -> { - GBP_LONG_MAX_PLUS1.getAmountMinorLong(); - }); + assertThatExceptionOfType(ArithmeticException.class) + .isThrownBy(() -> GBP_LONG_MAX_PLUS1.getAmountMinorLong()); } @Test void test_getAmountMinorLong_tooBigNegative() { - assertThrows(ArithmeticException.class, () -> { - GBP_LONG_MIN_MINUS1.getAmountMinorLong(); - }); + assertThatExceptionOfType(ArithmeticException.class) + .isThrownBy(() -> GBP_LONG_MIN_MINUS1.getAmountMinorLong()); } //----------------------------------------------------------------------- @@ -1301,26 +1235,24 @@ void test_getAmountMinorLong_tooBigNegative() { //----------------------------------------------------------------------- @Test void test_getAmountMinorInt_positive() { - assertEquals(234, GBP_2_34.getAmountMinorInt()); + assertThat(GBP_2_34.getAmountMinorInt()).isEqualTo(234); } @Test void test_getAmountMinorInt_negative() { - assertEquals(-578, GBP_M5_78.getAmountMinorInt()); + assertThat(GBP_M5_78.getAmountMinorInt()).isEqualTo(-578); } @Test void test_getAmountMinorInt_tooBigPositive() { - assertThrows(ArithmeticException.class, () -> { - GBP_INT_MAX_PLUS1.getAmountMinorInt(); - }); + assertThatExceptionOfType(ArithmeticException.class) + .isThrownBy(() -> GBP_INT_MAX_PLUS1.getAmountMinorInt()); } @Test void test_getAmountMinorInt_tooBigNegative() { - assertThrows(ArithmeticException.class, () -> { - GBP_INT_MIN_MINUS1.getAmountMinorInt(); - }); + assertThatExceptionOfType(ArithmeticException.class) + .isThrownBy(() -> GBP_INT_MIN_MINUS1.getAmountMinorInt()); } //----------------------------------------------------------------------- @@ -1328,12 +1260,12 @@ void test_getAmountMinorInt_tooBigNegative() { //----------------------------------------------------------------------- @Test void test_getMinorPart_positive() { - assertEquals(34, GBP_2_34.getMinorPart()); + assertThat(GBP_2_34.getMinorPart()).isEqualTo(34); } @Test void test_getMinorPart_negative() { - assertEquals(-78, GBP_M5_78.getMinorPart()); + assertThat(GBP_M5_78.getMinorPart()).isEqualTo(-78); } //----------------------------------------------------------------------- @@ -1341,9 +1273,9 @@ void test_getMinorPart_negative() { //----------------------------------------------------------------------- @Test void test_isZero() { - assertTrue(GBP_0_00.isZero()); - assertFalse(GBP_2_34.isZero()); - assertFalse(GBP_M5_78.isZero()); + assertThat(GBP_0_00.isZero()).isTrue(); + assertThat(GBP_2_34.isZero()).isFalse(); + assertThat(GBP_M5_78.isZero()).isFalse(); } //----------------------------------------------------------------------- @@ -1351,9 +1283,9 @@ void test_isZero() { //----------------------------------------------------------------------- @Test void test_isPositive() { - assertFalse(GBP_0_00.isPositive()); - assertTrue(GBP_2_34.isPositive()); - assertFalse(GBP_M5_78.isPositive()); + assertThat(GBP_0_00.isPositive()).isFalse(); + assertThat(GBP_2_34.isPositive()).isTrue(); + assertThat(GBP_M5_78.isPositive()).isFalse(); } //----------------------------------------------------------------------- @@ -1361,9 +1293,9 @@ void test_isPositive() { //----------------------------------------------------------------------- @Test void test_isPositiveOrZero() { - assertTrue(GBP_0_00.isPositiveOrZero()); - assertTrue(GBP_2_34.isPositiveOrZero()); - assertFalse(GBP_M5_78.isPositiveOrZero()); + assertThat(GBP_0_00.isPositiveOrZero()).isTrue(); + assertThat(GBP_2_34.isPositiveOrZero()).isTrue(); + assertThat(GBP_M5_78.isPositiveOrZero()).isFalse(); } //----------------------------------------------------------------------- @@ -1371,9 +1303,9 @@ void test_isPositiveOrZero() { //----------------------------------------------------------------------- @Test void test_isNegative() { - assertFalse(GBP_0_00.isNegative()); - assertFalse(GBP_2_34.isNegative()); - assertTrue(GBP_M5_78.isNegative()); + assertThat(GBP_0_00.isNegative()).isFalse(); + assertThat(GBP_2_34.isNegative()).isFalse(); + assertThat(GBP_M5_78.isNegative()).isTrue(); } //----------------------------------------------------------------------- @@ -1381,9 +1313,9 @@ void test_isNegative() { //----------------------------------------------------------------------- @Test void test_isNegativeOrZero() { - assertTrue(GBP_0_00.isNegativeOrZero()); - assertFalse(GBP_2_34.isNegativeOrZero()); - assertTrue(GBP_M5_78.isNegativeOrZero()); + assertThat(GBP_0_00.isNegativeOrZero()).isTrue(); + assertThat(GBP_2_34.isNegativeOrZero()).isFalse(); + assertThat(GBP_M5_78.isNegativeOrZero()).isTrue(); } //----------------------------------------------------------------------- @@ -1392,21 +1324,20 @@ void test_isNegativeOrZero() { @Test void test_withAmount_BigDecimal() { BigMoney test = GBP_2_34.withAmount(BIGDEC_2_345); - assertEquals(bd("2.345"), test.getAmount()); - assertEquals(3, test.getScale()); + assertThat(test.getAmount()).isEqualTo(bd("2.345")); + assertThat(test.getScale()).isEqualTo(3); } @Test void test_withAmount_BigDecimal_same() { BigMoney test = GBP_2_34.withAmount(BIGDEC_2_34); - assertSame(GBP_2_34, test); + assertThat(test).isSameAs(GBP_2_34); } @Test void test_withAmount_BigDecimal_nullBigDecimal() { - assertThrows(NullPointerException.class, () -> { - GBP_2_34.withAmount((BigDecimal) null); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> GBP_2_34.withAmount((BigDecimal) null)); } //----------------------------------------------------------------------- @@ -1415,14 +1346,14 @@ void test_withAmount_BigDecimal_nullBigDecimal() { @Test void test_withAmount_double() { BigMoney test = GBP_2_34.withAmount(2.345d); - assertEquals(bd("2.345"), test.getAmount()); - assertEquals(3, test.getScale()); + assertThat(test.getAmount()).isEqualTo(bd("2.345")); + assertThat(test.getScale()).isEqualTo(3); } @Test void test_withAmount_double_same() { BigMoney test = GBP_2_34.withAmount(2.34d); - assertSame(GBP_2_34, test); + assertThat(test).isSameAs(GBP_2_34); } //----------------------------------------------------------------------- @@ -1432,21 +1363,21 @@ void test_withAmount_double_same() { 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()); + assertThat(test).hasToString("GBP 5.90"); } @Test 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()); + assertThat(test).hasToString("GBP 5.90"); } @Test 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()); + assertThat(test).hasToString("GBP 5.90"); } @Test @@ -1458,37 +1389,34 @@ public BigMoney toBigMoney() { } }); BigMoney test = GBP_2_34.plus(iterable); - assertEquals("GBP 5.90", test.toString()); + assertThat(test).hasToString("GBP 5.90"); } @Test void test_plus_Iterable_zero() { Iterable iterable = Arrays.asList(GBP_0_00); BigMoney test = GBP_2_34.plus(iterable); - assertEquals(GBP_2_34, test); + assertThat(test).isEqualTo(GBP_2_34); } @Test void test_plus_Iterable_currencyMismatch() { Iterable iterable = Arrays.asList(GBP_2_33, JPY_423); - assertThrows(CurrencyMismatchException.class, () -> { - GBP_M5_78.plus(iterable); - }); + assertThatExceptionOfType(CurrencyMismatchException.class) + .isThrownBy(() -> GBP_M5_78.plus(iterable)); } @Test void test_plus_Iterable_nullEntry() { Iterable iterable = Arrays.asList(GBP_2_33, null); - assertThrows(NullPointerException.class, () -> { - GBP_M5_78.plus(iterable); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> GBP_M5_78.plus(iterable)); } @Test void test_plus_Iterable_nullIterable() { - assertThrows(NullPointerException.class, () -> { - GBP_M5_78.plus((Iterable) null); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> GBP_M5_78.plus((Iterable) null)); } @Test @@ -1499,9 +1427,8 @@ public BigMoney toBigMoney() { return null; } }); - assertThrows(NullPointerException.class, () -> { - GBP_M5_78.plus(iterable); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> GBP_M5_78.plus(iterable)); } //----------------------------------------------------------------------- @@ -1510,49 +1437,47 @@ public BigMoney toBigMoney() { @Test void test_plus_BigMoneyProvider_zero() { BigMoney test = GBP_2_34.plus(GBP_0_00); - assertSame(GBP_2_34, test); + assertThat(test).isSameAs(GBP_2_34); } @Test void test_plus_BigMoneyProvider_positive() { BigMoney test = GBP_2_34.plus(GBP_1_23); - assertEquals("GBP 3.57", test.toString()); - assertEquals(2, test.getScale()); + assertThat(test).hasToString("GBP 3.57"); + assertThat(test.getScale()).isEqualTo(2); } @Test void test_plus_BigMoneyProvider_negative() { BigMoney test = GBP_2_34.plus(GBP_M1_23); - assertEquals("GBP 1.11", test.toString()); - assertEquals(2, test.getScale()); + assertThat(test).hasToString("GBP 1.11"); + assertThat(test.getScale()).isEqualTo(2); } @Test 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()); + assertThat(test).hasToString("GBP 3.451"); + assertThat(test.getScale()).isEqualTo(3); } @Test 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()); + assertThat(test).hasToString("GBP 2.35"); + assertThat(test.getScale()).isEqualTo(2); } @Test void test_plus_BigMoneyProvider_currencyMismatch() { - assertThrows(CurrencyMismatchException.class, () -> { - GBP_M5_78.plus(USD_1_23); - }); + assertThatExceptionOfType(CurrencyMismatchException.class) + .isThrownBy(() -> GBP_M5_78.plus(USD_1_23)); } @Test void test_plus_BigMoneyProvider_nullBigMoneyProvider() { - assertThrows(NullPointerException.class, () -> { - GBP_M5_78.plus((BigMoneyProvider) null); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> GBP_M5_78.plus((BigMoneyProvider) null)); } @Test @@ -1563,9 +1488,8 @@ public BigMoney toBigMoney() { return null; } }; - assertThrows(NullPointerException.class, () -> { - GBP_M5_78.plus(provider); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> GBP_M5_78.plus(provider)); } //----------------------------------------------------------------------- @@ -1574,35 +1498,34 @@ public BigMoney toBigMoney() { @Test void test_plus_BigDecimal_zero() { BigMoney test = GBP_2_34.plus(BigDecimal.ZERO); - assertSame(GBP_2_34, test); + assertThat(test).isSameAs(GBP_2_34); } @Test void test_plus_BigDecimal_positive() { BigMoney test = GBP_2_34.plus(bd("1.23")); - assertEquals("GBP 3.57", test.toString()); - assertEquals(2, test.getScale()); + assertThat(test).hasToString("GBP 3.57"); + assertThat(test.getScale()).isEqualTo(2); } @Test void test_plus_BigDecimal_negative() { BigMoney test = GBP_2_34.plus(bd("-1.23")); - assertEquals("GBP 1.11", test.toString()); - assertEquals(2, test.getScale()); + assertThat(test).hasToString("GBP 1.11"); + assertThat(test.getScale()).isEqualTo(2); } @Test void test_plus_BigDecimal_scale() { BigMoney test = GBP_2_34.plus(bd("1.235")); - assertEquals("GBP 3.575", test.toString()); - assertEquals(3, test.getScale()); + assertThat(test).hasToString("GBP 3.575"); + assertThat(test.getScale()).isEqualTo(3); } @Test void test_plus_BigDecimal_nullBigDecimal() { - assertThrows(NullPointerException.class, () -> { - GBP_M5_78.plus((BigDecimal) null); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> GBP_M5_78.plus((BigDecimal) null)); } //----------------------------------------------------------------------- @@ -1611,28 +1534,28 @@ void test_plus_BigDecimal_nullBigDecimal() { @Test void test_plus_double_zero() { BigMoney test = GBP_2_34.plus(0d); - assertSame(GBP_2_34, test); + assertThat(test).isSameAs(GBP_2_34); } @Test void test_plus_double_positive() { BigMoney test = GBP_2_34.plus(1.23d); - assertEquals("GBP 3.57", test.toString()); - assertEquals(2, test.getScale()); + assertThat(test).hasToString("GBP 3.57"); + assertThat(test.getScale()).isEqualTo(2); } @Test void test_plus_double_negative() { BigMoney test = GBP_2_34.plus(-1.23d); - assertEquals("GBP 1.11", test.toString()); - assertEquals(2, test.getScale()); + assertThat(test).hasToString("GBP 1.11"); + assertThat(test.getScale()).isEqualTo(2); } @Test void test_plus_double_scale() { BigMoney test = GBP_2_34.plus(1.234d); - assertEquals("GBP 3.574", test.toString()); - assertEquals(3, test.getScale()); + assertThat(test).hasToString("GBP 3.574"); + assertThat(test.getScale()).isEqualTo(3); } //----------------------------------------------------------------------- @@ -1641,21 +1564,21 @@ void test_plus_double_scale() { @Test void test_plusMajor_zero() { BigMoney test = GBP_2_34.plusMajor(0); - assertSame(GBP_2_34, test); + assertThat(test).isSameAs(GBP_2_34); } @Test void test_plusMajor_positive() { BigMoney test = GBP_2_34.plusMajor(123); - assertEquals("GBP 125.34", test.toString()); - assertEquals(2, test.getScale()); + assertThat(test).hasToString("GBP 125.34"); + assertThat(test.getScale()).isEqualTo(2); } @Test void test_plusMajor_negative() { BigMoney test = GBP_2_34.plusMajor(-123); - assertEquals("GBP -120.66", test.toString()); - assertEquals(2, test.getScale()); + assertThat(test).hasToString("GBP -120.66"); + assertThat(test.getScale()).isEqualTo(2); } //----------------------------------------------------------------------- @@ -1664,28 +1587,28 @@ void test_plusMajor_negative() { @Test void test_plusMinor_zero() { BigMoney test = GBP_2_34.plusMinor(0); - assertSame(GBP_2_34, test); + assertThat(test).isSameAs(GBP_2_34); } @Test void test_plusMinor_positive() { BigMoney test = GBP_2_34.plusMinor(123); - assertEquals("GBP 3.57", test.toString()); - assertEquals(2, test.getScale()); + assertThat(test).hasToString("GBP 3.57"); + assertThat(test.getScale()).isEqualTo(2); } @Test void test_plusMinor_negative() { BigMoney test = GBP_2_34.plusMinor(-123); - assertEquals("GBP 1.11", test.toString()); - assertEquals(2, test.getScale()); + assertThat(test).hasToString("GBP 1.11"); + assertThat(test.getScale()).isEqualTo(2); } @Test void test_plusMinor_scale() { BigMoney test = BigMoney.parse("GBP 12").plusMinor(123); - assertEquals("GBP 13.23", test.toString()); - assertEquals(2, test.getScale()); + assertThat(test).hasToString("GBP 13.23"); + assertThat(test.getScale()).isEqualTo(2); } //----------------------------------------------------------------------- @@ -1694,46 +1617,43 @@ void test_plusMinor_scale() { @Test void test_plusRetainScale_BigMoneyProviderRoundingMode_zero() { BigMoney test = GBP_2_34.plusRetainScale(BigMoney.zero(GBP), RoundingMode.UNNECESSARY); - assertSame(GBP_2_34, test); + assertThat(test).isSameAs(GBP_2_34); } @Test void test_plusRetainScale_BigMoneyProviderRoundingMode_positive() { BigMoney test = GBP_2_34.plusRetainScale(BigMoney.parse("GBP 1.23"), RoundingMode.UNNECESSARY); - assertEquals("GBP 3.57", test.toString()); + assertThat(test).hasToString("GBP 3.57"); } @Test void test_plusRetainScale_BigMoneyProviderRoundingMode_negative() { BigMoney test = GBP_2_34.plusRetainScale(BigMoney.parse("GBP -1.23"), RoundingMode.UNNECESSARY); - assertEquals("GBP 1.11", test.toString()); + assertThat(test).hasToString("GBP 1.11"); } @Test void test_plusRetainScale_BigMoneyProviderRoundingMode_roundDown() { BigMoney test = GBP_2_34.plusRetainScale(BigMoney.parse("GBP 1.235"), RoundingMode.DOWN); - assertEquals("GBP 3.57", test.toString()); + assertThat(test).hasToString("GBP 3.57"); } @Test void test_plusRetainScale_BigMoneyProviderRoundingMode_roundUnecessary() { - assertThrows(ArithmeticException.class, () -> { - GBP_2_34.plusRetainScale(BigMoney.parse("GBP 1.235"), RoundingMode.UNNECESSARY); - }); + assertThatExceptionOfType(ArithmeticException.class) + .isThrownBy(() -> GBP_2_34.plusRetainScale(BigMoney.parse("GBP 1.235"), RoundingMode.UNNECESSARY)); } @Test void test_plusRetainScale_BigMoneyProviderRoundingMode_nullBigDecimal() { - assertThrows(NullPointerException.class, () -> { - GBP_M5_78.plusRetainScale((BigDecimal) null, RoundingMode.UNNECESSARY); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> GBP_M5_78.plusRetainScale((BigDecimal) null, RoundingMode.UNNECESSARY)); } @Test void test_plusRetainScale_BigMoneyProviderRoundingMode_nullRoundingMode() { - assertThrows(NullPointerException.class, () -> { - GBP_M5_78.plusRetainScale(BigMoney.parse("GBP 1.23"), (RoundingMode) null); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> GBP_M5_78.plusRetainScale(BigMoney.parse("GBP 1.23"), (RoundingMode) null)); } //----------------------------------------------------------------------- @@ -1742,46 +1662,43 @@ void test_plusRetainScale_BigMoneyProviderRoundingMode_nullRoundingMode() { @Test void test_plusRetainScale_BigDecimalRoundingMode_zero() { BigMoney test = GBP_2_34.plusRetainScale(BigDecimal.ZERO, RoundingMode.UNNECESSARY); - assertSame(GBP_2_34, test); + assertThat(test).isSameAs(GBP_2_34); } @Test void test_plusRetainScale_BigDecimalRoundingMode_positive() { BigMoney test = GBP_2_34.plusRetainScale(bd("1.23"), RoundingMode.UNNECESSARY); - assertEquals("GBP 3.57", test.toString()); + assertThat(test).hasToString("GBP 3.57"); } @Test void test_plusRetainScale_BigDecimalRoundingMode_negative() { BigMoney test = GBP_2_34.plusRetainScale(bd("-1.23"), RoundingMode.UNNECESSARY); - assertEquals("GBP 1.11", test.toString()); + assertThat(test).hasToString("GBP 1.11"); } @Test void test_plusRetainScale_BigDecimalRoundingMode_roundDown() { BigMoney test = GBP_2_34.plusRetainScale(bd("1.235"), RoundingMode.DOWN); - assertEquals("GBP 3.57", test.toString()); + assertThat(test).hasToString("GBP 3.57"); } @Test void test_plusRetainScale_BigDecimalRoundingMode_roundUnecessary() { - assertThrows(ArithmeticException.class, () -> { - GBP_2_34.plusRetainScale(bd("1.235"), RoundingMode.UNNECESSARY); - }); + assertThatExceptionOfType(ArithmeticException.class) + .isThrownBy(() -> GBP_2_34.plusRetainScale(bd("1.235"), RoundingMode.UNNECESSARY)); } @Test void test_plusRetainScale_BigDecimalRoundingMode_nullBigDecimal() { - assertThrows(NullPointerException.class, () -> { - GBP_M5_78.plusRetainScale((BigDecimal) null, RoundingMode.UNNECESSARY); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> GBP_M5_78.plusRetainScale((BigDecimal) null, RoundingMode.UNNECESSARY)); } @Test void test_plusRetainScale_BigDecimalRoundingMode_nullRoundingMode() { - assertThrows(NullPointerException.class, () -> { - GBP_M5_78.plusRetainScale(BIGDEC_2_34, (RoundingMode) null); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> GBP_M5_78.plusRetainScale(BIGDEC_2_34, (RoundingMode) null)); } //----------------------------------------------------------------------- @@ -1790,39 +1707,37 @@ void test_plusRetainScale_BigDecimalRoundingMode_nullRoundingMode() { @Test void test_plusRetainScale_doubleRoundingMode_zero() { BigMoney test = GBP_2_34.plusRetainScale(0d, RoundingMode.UNNECESSARY); - assertSame(GBP_2_34, test); + assertThat(test).isSameAs(GBP_2_34); } @Test void test_plusRetainScale_doubleRoundingMode_positive() { BigMoney test = GBP_2_34.plusRetainScale(1.23d, RoundingMode.UNNECESSARY); - assertEquals("GBP 3.57", test.toString()); + assertThat(test).hasToString("GBP 3.57"); } @Test void test_plusRetainScale_doubleRoundingMode_negative() { BigMoney test = GBP_2_34.plusRetainScale(-1.23d, RoundingMode.UNNECESSARY); - assertEquals("GBP 1.11", test.toString()); + assertThat(test).hasToString("GBP 1.11"); } @Test void test_plusRetainScale_doubleRoundingMode_roundDown() { BigMoney test = GBP_2_34.plusRetainScale(1.235d, RoundingMode.DOWN); - assertEquals("GBP 3.57", test.toString()); + assertThat(test).hasToString("GBP 3.57"); } @Test void test_plusRetainScale_doubleRoundingMode_roundUnecessary() { - assertThrows(ArithmeticException.class, () -> { - GBP_2_34.plusRetainScale(1.235d, RoundingMode.UNNECESSARY); - }); + assertThatExceptionOfType(ArithmeticException.class) + .isThrownBy(() -> GBP_2_34.plusRetainScale(1.235d, RoundingMode.UNNECESSARY)); } @Test void test_plusRetainScale_doubleRoundingMode_nullRoundingMode() { - assertThrows(NullPointerException.class, () -> { - GBP_M5_78.plusRetainScale(2.34d, (RoundingMode) null); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> GBP_M5_78.plusRetainScale(2.34d, (RoundingMode) null)); } //----------------------------------------------------------------------- @@ -1832,21 +1747,21 @@ void test_plusRetainScale_doubleRoundingMode_nullRoundingMode() { 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()); + assertThat(test).hasToString("GBP -1.22"); } @Test 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()); + assertThat(test).hasToString("GBP -1.22"); } @Test 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()); + assertThat(test).hasToString("GBP -1.22"); } @Test @@ -1858,37 +1773,34 @@ public BigMoney toBigMoney() { } }); BigMoney test = GBP_2_34.minus(iterable); - assertEquals("GBP -1.22", test.toString()); + assertThat(test).hasToString("GBP -1.22"); } @Test void test_minus_Iterable_zero() { Iterable iterable = Arrays.asList(GBP_0_00); BigMoney test = GBP_2_34.minus(iterable); - assertEquals(GBP_2_34, test); + assertThat(test).isEqualTo(GBP_2_34); } @Test void test_minus_Iterable_currencyMismatch() { Iterable iterable = Arrays.asList(GBP_2_33, JPY_423); - assertThrows(CurrencyMismatchException.class, () -> { - GBP_M5_78.minus(iterable); - }); + assertThatExceptionOfType(CurrencyMismatchException.class) + .isThrownBy(() -> GBP_M5_78.minus(iterable)); } @Test void test_minus_Iterable_nullEntry() { Iterable iterable = Arrays.asList(GBP_2_33, null); - assertThrows(NullPointerException.class, () -> { - GBP_M5_78.minus(iterable); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> GBP_M5_78.minus(iterable)); } @Test void test_minus_Iterable_nullIterable() { - assertThrows(NullPointerException.class, () -> { - GBP_M5_78.minus((Iterable) null); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> GBP_M5_78.minus((Iterable) null)); } @Test @@ -1899,9 +1811,8 @@ public BigMoney toBigMoney() { return null; } }); - assertThrows(NullPointerException.class, () -> { - GBP_M5_78.minus(iterable); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> GBP_M5_78.minus(iterable)); } //----------------------------------------------------------------------- @@ -1910,49 +1821,47 @@ public BigMoney toBigMoney() { @Test void test_minus_BigMoneyProvider_zero() { BigMoney test = GBP_2_34.minus(GBP_0_00); - assertSame(GBP_2_34, test); + assertThat(test).isSameAs(GBP_2_34); } @Test void test_minus_BigMoneyProvider_positive() { BigMoney test = GBP_2_34.minus(GBP_1_23); - assertEquals("GBP 1.11", test.toString()); - assertEquals(2, test.getScale()); + assertThat(test).hasToString("GBP 1.11"); + assertThat(test.getScale()).isEqualTo(2); } @Test void test_minus_BigMoneyProvider_negative() { BigMoney test = GBP_2_34.minus(GBP_M1_23); - assertEquals("GBP 3.57", test.toString()); - assertEquals(2, test.getScale()); + assertThat(test).hasToString("GBP 3.57"); + assertThat(test.getScale()).isEqualTo(2); } @Test 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()); + assertThat(test).hasToString("GBP 1.229"); + assertThat(test.getScale()).isEqualTo(3); } @Test 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()); + assertThat(test).hasToString("GBP 2.33"); + assertThat(test.getScale()).isEqualTo(2); } @Test void test_minus_BigMoneyProvider_currencyMismatch() { - assertThrows(CurrencyMismatchException.class, () -> { - GBP_M5_78.minus(USD_1_23); - }); + assertThatExceptionOfType(CurrencyMismatchException.class) + .isThrownBy(() -> GBP_M5_78.minus(USD_1_23)); } @Test void test_minus_BigMoneyProvider_nullBigMoneyProvider() { - assertThrows(NullPointerException.class, () -> { - GBP_M5_78.minus((BigMoneyProvider) null); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> GBP_M5_78.minus((BigMoneyProvider) null)); } @Test @@ -1963,9 +1872,8 @@ public BigMoney toBigMoney() { return null; } }; - assertThrows(NullPointerException.class, () -> { - GBP_M5_78.minus(provider); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> GBP_M5_78.minus(provider)); } //----------------------------------------------------------------------- @@ -1974,35 +1882,34 @@ public BigMoney toBigMoney() { @Test void test_minus_BigDecimal_zero() { BigMoney test = GBP_2_34.minus(BigDecimal.ZERO); - assertSame(GBP_2_34, test); + assertThat(test).isSameAs(GBP_2_34); } @Test void test_minus_BigDecimal_positive() { BigMoney test = GBP_2_34.minus(bd("1.23")); - assertEquals("GBP 1.11", test.toString()); - assertEquals(2, test.getScale()); + assertThat(test).hasToString("GBP 1.11"); + assertThat(test.getScale()).isEqualTo(2); } @Test void test_minus_BigDecimal_negative() { BigMoney test = GBP_2_34.minus(bd("-1.23")); - assertEquals("GBP 3.57", test.toString()); - assertEquals(2, test.getScale()); + assertThat(test).hasToString("GBP 3.57"); + assertThat(test.getScale()).isEqualTo(2); } @Test void test_minus_BigDecimal_scale() { BigMoney test = GBP_2_34.minus(bd("1.235")); - assertEquals("GBP 1.105", test.toString()); - assertEquals(3, test.getScale()); + assertThat(test).hasToString("GBP 1.105"); + assertThat(test.getScale()).isEqualTo(3); } @Test void test_minus_BigDecimal_nullBigDecimal() { - assertThrows(NullPointerException.class, () -> { - GBP_M5_78.minus((BigDecimal) null); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> GBP_M5_78.minus((BigDecimal) null)); } //----------------------------------------------------------------------- @@ -2011,28 +1918,28 @@ void test_minus_BigDecimal_nullBigDecimal() { @Test void test_minus_double_zero() { BigMoney test = GBP_2_34.minus(0d); - assertSame(GBP_2_34, test); + assertThat(test).isSameAs(GBP_2_34); } @Test void test_minus_double_positive() { BigMoney test = GBP_2_34.minus(1.23d); - assertEquals("GBP 1.11", test.toString()); - assertEquals(2, test.getScale()); + assertThat(test).hasToString("GBP 1.11"); + assertThat(test.getScale()).isEqualTo(2); } @Test void test_minus_double_negative() { BigMoney test = GBP_2_34.minus(-1.23d); - assertEquals("GBP 3.57", test.toString()); - assertEquals(2, test.getScale()); + assertThat(test).hasToString("GBP 3.57"); + assertThat(test.getScale()).isEqualTo(2); } @Test void test_minus_double_scale() { BigMoney test = GBP_2_34.minus(1.235d); - assertEquals("GBP 1.105", test.toString()); - assertEquals(3, test.getScale()); + assertThat(test).hasToString("GBP 1.105"); + assertThat(test.getScale()).isEqualTo(3); } //----------------------------------------------------------------------- @@ -2041,21 +1948,21 @@ void test_minus_double_scale() { @Test void test_minusMajor_zero() { BigMoney test = GBP_2_34.minusMajor(0); - assertSame(GBP_2_34, test); + assertThat(test).isSameAs(GBP_2_34); } @Test void test_minusMajor_positive() { BigMoney test = GBP_2_34.minusMajor(123); - assertEquals("GBP -120.66", test.toString()); - assertEquals(2, test.getScale()); + assertThat(test).hasToString("GBP -120.66"); + assertThat(test.getScale()).isEqualTo(2); } @Test void test_minusMajor_negative() { BigMoney test = GBP_2_34.minusMajor(-123); - assertEquals("GBP 125.34", test.toString()); - assertEquals(2, test.getScale()); + assertThat(test).hasToString("GBP 125.34"); + assertThat(test.getScale()).isEqualTo(2); } //----------------------------------------------------------------------- @@ -2064,28 +1971,28 @@ void test_minusMajor_negative() { @Test void test_minusMinor_zero() { BigMoney test = GBP_2_34.minusMinor(0); - assertSame(GBP_2_34, test); + assertThat(test).isSameAs(GBP_2_34); } @Test void test_minusMinor_positive() { BigMoney test = GBP_2_34.minusMinor(123); - assertEquals("GBP 1.11", test.toString()); - assertEquals(2, test.getScale()); + assertThat(test).hasToString("GBP 1.11"); + assertThat(test.getScale()).isEqualTo(2); } @Test void test_minusMinor_negative() { BigMoney test = GBP_2_34.minusMinor(-123); - assertEquals("GBP 3.57", test.toString()); - assertEquals(2, test.getScale()); + assertThat(test).hasToString("GBP 3.57"); + assertThat(test.getScale()).isEqualTo(2); } @Test void test_minusMinor_scale() { BigMoney test = BigMoney.parse("GBP 12").minusMinor(123); - assertEquals("GBP 10.77", test.toString()); - assertEquals(2, test.getScale()); + assertThat(test).hasToString("GBP 10.77"); + assertThat(test.getScale()).isEqualTo(2); } //----------------------------------------------------------------------- @@ -2094,46 +2001,43 @@ void test_minusMinor_scale() { @Test void test_minusRetainScale_BigMoneyProviderRoundingMode_zero() { BigMoney test = GBP_2_34.minusRetainScale(BigMoney.zero(GBP), RoundingMode.UNNECESSARY); - assertSame(GBP_2_34, test); + assertThat(test).isSameAs(GBP_2_34); } @Test void test_minusRetainScale_BigMoneyProviderRoundingMode_positive() { BigMoney test = GBP_2_34.minusRetainScale(BigMoney.parse("GBP 1.23"), RoundingMode.UNNECESSARY); - assertEquals("GBP 1.11", test.toString()); + assertThat(test).hasToString("GBP 1.11"); } @Test void test_minusRetainScale_BigMoneyProviderRoundingMode_negative() { BigMoney test = GBP_2_34.minusRetainScale(BigMoney.parse("GBP -1.23"), RoundingMode.UNNECESSARY); - assertEquals("GBP 3.57", test.toString()); + assertThat(test).hasToString("GBP 3.57"); } @Test void test_minusRetainScale_BigMoneyProviderRoundingMode_roundDown() { BigMoney test = GBP_2_34.minusRetainScale(BigMoney.parse("GBP 1.235"), RoundingMode.DOWN); - assertEquals("GBP 1.10", test.toString()); + assertThat(test).hasToString("GBP 1.10"); } @Test void test_minusRetainScale_BigMoneyProviderRoundingMode_roundUnecessary() { - assertThrows(ArithmeticException.class, () -> { - GBP_2_34.minusRetainScale(BigMoney.parse("GBP 1.235"), RoundingMode.UNNECESSARY); - }); + assertThatExceptionOfType(ArithmeticException.class) + .isThrownBy(() -> GBP_2_34.minusRetainScale(BigMoney.parse("GBP 1.235"), RoundingMode.UNNECESSARY)); } @Test void test_minusRetainScale_BigMoneyProviderRoundingMode_nullBigMoneyProvider() { - assertThrows(NullPointerException.class, () -> { - GBP_M5_78.minusRetainScale((BigMoneyProvider) null, RoundingMode.UNNECESSARY); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> GBP_M5_78.minusRetainScale((BigMoneyProvider) null, RoundingMode.UNNECESSARY)); } @Test void test_minusRetainScale_BigMoneyProviderRoundingMode_nullRoundingMode() { - assertThrows(NullPointerException.class, () -> { - GBP_M5_78.minusRetainScale(BigMoney.parse("GBP 123"), (RoundingMode) null); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> GBP_M5_78.minusRetainScale(BigMoney.parse("GBP 123"), (RoundingMode) null)); } //----------------------------------------------------------------------- @@ -2142,46 +2046,43 @@ void test_minusRetainScale_BigMoneyProviderRoundingMode_nullRoundingMode() { @Test void test_minusRetainScale_BigDecimalRoundingMode_zero() { BigMoney test = GBP_2_34.minusRetainScale(BigDecimal.ZERO, RoundingMode.UNNECESSARY); - assertSame(GBP_2_34, test); + assertThat(test).isSameAs(GBP_2_34); } @Test void test_minusRetainScale_BigDecimalRoundingMode_positive() { BigMoney test = GBP_2_34.minusRetainScale(bd("1.23"), RoundingMode.UNNECESSARY); - assertEquals("GBP 1.11", test.toString()); + assertThat(test).hasToString("GBP 1.11"); } @Test void test_minusRetainScale_BigDecimalRoundingMode_negative() { BigMoney test = GBP_2_34.minusRetainScale(bd("-1.23"), RoundingMode.UNNECESSARY); - assertEquals("GBP 3.57", test.toString()); + assertThat(test).hasToString("GBP 3.57"); } @Test void test_minusRetainScale_BigDecimalRoundingMode_roundDown() { BigMoney test = GBP_2_34.minusRetainScale(bd("1.235"), RoundingMode.DOWN); - assertEquals("GBP 1.10", test.toString()); + assertThat(test).hasToString("GBP 1.10"); } @Test void test_minusRetainScale_BigDecimalRoundingMode_roundUnecessary() { - assertThrows(ArithmeticException.class, () -> { - GBP_2_34.minusRetainScale(bd("1.235"), RoundingMode.UNNECESSARY); - }); + assertThatExceptionOfType(ArithmeticException.class) + .isThrownBy(() -> GBP_2_34.minusRetainScale(bd("1.235"), RoundingMode.UNNECESSARY)); } @Test void test_minusRetainScale_BigDecimalRoundingMode_nullBigDecimal() { - assertThrows(NullPointerException.class, () -> { - GBP_M5_78.minusRetainScale((BigDecimal) null, RoundingMode.UNNECESSARY); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> GBP_M5_78.minusRetainScale((BigDecimal) null, RoundingMode.UNNECESSARY)); } @Test void test_minusRetainScale_BigDecimalRoundingMode_nullRoundingMode() { - assertThrows(NullPointerException.class, () -> { - GBP_M5_78.minusRetainScale(BIGDEC_2_34, (RoundingMode) null); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> GBP_M5_78.minusRetainScale(BIGDEC_2_34, (RoundingMode) null)); } //----------------------------------------------------------------------- @@ -2190,39 +2091,37 @@ void test_minusRetainScale_BigDecimalRoundingMode_nullRoundingMode() { @Test void test_minusRetainScale_doubleRoundingMode_zero() { BigMoney test = GBP_2_34.minusRetainScale(0d, RoundingMode.UNNECESSARY); - assertSame(GBP_2_34, test); + assertThat(test).isSameAs(GBP_2_34); } @Test void test_minusRetainScale_doubleRoundingMode_positive() { BigMoney test = GBP_2_34.minusRetainScale(1.23d, RoundingMode.UNNECESSARY); - assertEquals("GBP 1.11", test.toString()); + assertThat(test).hasToString("GBP 1.11"); } @Test void test_minusRetainScale_doubleRoundingMode_negative() { BigMoney test = GBP_2_34.minusRetainScale(-1.23d, RoundingMode.UNNECESSARY); - assertEquals("GBP 3.57", test.toString()); + assertThat(test).hasToString("GBP 3.57"); } @Test void test_minusRetainScale_doubleRoundingMode_roundDown() { BigMoney test = GBP_2_34.minusRetainScale(1.235d, RoundingMode.DOWN); - assertEquals("GBP 1.10", test.toString()); + assertThat(test).hasToString("GBP 1.10"); } @Test void test_minusRetainScale_doubleRoundingMode_roundUnecessary() { - assertThrows(ArithmeticException.class, () -> { - GBP_2_34.minusRetainScale(1.235d, RoundingMode.UNNECESSARY); - }); + assertThatExceptionOfType(ArithmeticException.class) + .isThrownBy(() -> GBP_2_34.minusRetainScale(1.235d, RoundingMode.UNNECESSARY)); } @Test void test_minusRetainScale_doubleRoundingMode_nullRoundingMode() { - assertThrows(NullPointerException.class, () -> { - GBP_M5_78.minusRetainScale(2.34d, (RoundingMode) null); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> GBP_M5_78.minusRetainScale(2.34d, (RoundingMode) null)); } //----------------------------------------------------------------------- @@ -2231,28 +2130,27 @@ void test_minusRetainScale_doubleRoundingMode_nullRoundingMode() { @Test void test_multipliedBy_BigDecimal_one() { BigMoney test = GBP_2_34.multipliedBy(BigDecimal.ONE); - assertSame(GBP_2_34, test); + assertThat(test).isSameAs(GBP_2_34); } @Test void test_multipliedBy_BigDecimal_positive() { BigMoney test = GBP_2_33.multipliedBy(bd("2.5")); - assertEquals("GBP 5.825", test.toString()); - assertEquals(3, test.getScale()); + assertThat(test).hasToString("GBP 5.825"); + assertThat(test.getScale()).isEqualTo(3); } @Test void test_multipliedBy_BigDecimal_negative() { BigMoney test = GBP_2_33.multipliedBy(bd("-2.5")); - assertEquals("GBP -5.825", test.toString()); - assertEquals(3, test.getScale()); + assertThat(test).hasToString("GBP -5.825"); + assertThat(test.getScale()).isEqualTo(3); } @Test void test_multipliedBy_BigDecimal_nullBigDecimal() { - assertThrows(NullPointerException.class, () -> { - GBP_5_78.multipliedBy((BigDecimal) null); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> GBP_5_78.multipliedBy((BigDecimal) null)); } //----------------------------------------------------------------------- @@ -2261,21 +2159,21 @@ void test_multipliedBy_BigDecimal_nullBigDecimal() { @Test void test_multipliedBy_doubleRoundingMode_one() { BigMoney test = GBP_2_34.multipliedBy(1d); - assertSame(GBP_2_34, test); + assertThat(test).isSameAs(GBP_2_34); } @Test void test_multipliedBy_doubleRoundingMode_positive() { BigMoney test = GBP_2_33.multipliedBy(2.5d); - assertEquals("GBP 5.825", test.toString()); - assertEquals(3, test.getScale()); + assertThat(test).hasToString("GBP 5.825"); + assertThat(test.getScale()).isEqualTo(3); } @Test void test_multipliedBy_doubleRoundingMode_negative() { BigMoney test = GBP_2_33.multipliedBy(-2.5d); - assertEquals("GBP -5.825", test.toString()); - assertEquals(3, test.getScale()); + assertThat(test).hasToString("GBP -5.825"); + assertThat(test.getScale()).isEqualTo(3); } //----------------------------------------------------------------------- @@ -2284,21 +2182,21 @@ void test_multipliedBy_doubleRoundingMode_negative() { @Test void test_multipliedBy_long_one() { BigMoney test = GBP_2_34.multipliedBy(1); - assertSame(GBP_2_34, test); + assertThat(test).isSameAs(GBP_2_34); } @Test void test_multipliedBy_long_positive() { BigMoney test = GBP_2_34.multipliedBy(3); - assertEquals("GBP 7.02", test.toString()); - assertEquals(2, test.getScale()); + assertThat(test).hasToString("GBP 7.02"); + assertThat(test.getScale()).isEqualTo(2); } @Test void test_multipliedBy_long_negative() { BigMoney test = GBP_2_34.multipliedBy(-3); - assertEquals("GBP -7.02", test.toString()); - assertEquals(2, test.getScale()); + assertThat(test).hasToString("GBP -7.02"); + assertThat(test.getScale()).isEqualTo(2); } //----------------------------------------------------------------------- @@ -2307,39 +2205,37 @@ void test_multipliedBy_long_negative() { @Test void test_multiplyRetainScale_BigDecimalRoundingMode_one() { BigMoney test = GBP_2_34.multiplyRetainScale(BigDecimal.ONE, RoundingMode.DOWN); - assertSame(GBP_2_34, test); + assertThat(test).isSameAs(GBP_2_34); } @Test void test_multiplyRetainScale_BigDecimalRoundingMode_positive() { BigMoney test = GBP_2_33.multiplyRetainScale(bd("2.5"), RoundingMode.DOWN); - assertEquals("GBP 5.82", test.toString()); + assertThat(test).hasToString("GBP 5.82"); } @Test void test_multiplyRetainScale_BigDecimalRoundingMode_positive_halfUp() { BigMoney test = GBP_2_33.multiplyRetainScale(bd("2.5"), RoundingMode.HALF_UP); - assertEquals("GBP 5.83", test.toString()); + assertThat(test).hasToString("GBP 5.83"); } @Test void test_multiplyRetainScale_BigDecimalRoundingMode_negative() { BigMoney test = GBP_2_33.multiplyRetainScale(bd("-2.5"), RoundingMode.FLOOR); - assertEquals("GBP -5.83", test.toString()); + assertThat(test).hasToString("GBP -5.83"); } @Test void test_multiplyRetainScale_BigDecimalRoundingMode_nullBigDecimal() { - assertThrows(NullPointerException.class, () -> { - GBP_5_78.multiplyRetainScale((BigDecimal) null, RoundingMode.DOWN); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> GBP_5_78.multiplyRetainScale((BigDecimal) null, RoundingMode.DOWN)); } @Test void test_multiplyRetainScale_BigDecimalRoundingMode_nullRoundingMode() { - assertThrows(NullPointerException.class, () -> { - GBP_5_78.multiplyRetainScale(bd("2.5"), (RoundingMode) null); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> GBP_5_78.multiplyRetainScale(bd("2.5"), (RoundingMode) null)); } //----------------------------------------------------------------------- @@ -2348,32 +2244,31 @@ void test_multiplyRetainScale_BigDecimalRoundingMode_nullRoundingMode() { @Test void test_multiplyRetainScale_doubleRoundingMode_one() { BigMoney test = GBP_2_34.multiplyRetainScale(1d, RoundingMode.DOWN); - assertSame(GBP_2_34, test); + assertThat(test).isSameAs(GBP_2_34); } @Test void test_multiplyRetainScale_doubleRoundingMode_positive() { BigMoney test = GBP_2_33.multiplyRetainScale(2.5d, RoundingMode.DOWN); - assertEquals("GBP 5.82", test.toString()); + assertThat(test).hasToString("GBP 5.82"); } @Test void test_multiplyRetainScale_doubleRoundingMode_positive_halfUp() { BigMoney test = GBP_2_33.multiplyRetainScale(2.5d, RoundingMode.HALF_UP); - assertEquals("GBP 5.83", test.toString()); + assertThat(test).hasToString("GBP 5.83"); } @Test void test_multiplyRetainScale_doubleRoundingMode_negative() { BigMoney test = GBP_2_33.multiplyRetainScale(-2.5d, RoundingMode.FLOOR); - assertEquals("GBP -5.83", test.toString()); + assertThat(test).hasToString("GBP -5.83"); } @Test void test_multiplyRetainScale_doubleRoundingMode_nullRoundingMode() { - assertThrows(NullPointerException.class, () -> { - GBP_5_78.multiplyRetainScale(2.5d, (RoundingMode) null); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> GBP_5_78.multiplyRetainScale(2.5d, (RoundingMode) null)); } //----------------------------------------------------------------------- @@ -2382,39 +2277,37 @@ void test_multiplyRetainScale_doubleRoundingMode_nullRoundingMode() { @Test void test_dividedBy_BigDecimalRoundingMode_one() { BigMoney test = GBP_2_34.dividedBy(BigDecimal.ONE, RoundingMode.DOWN); - assertSame(GBP_2_34, test); + assertThat(test).isSameAs(GBP_2_34); } @Test void test_dividedBy_BigDecimalRoundingMode_positive() { BigMoney test = GBP_2_34.dividedBy(bd("2.5"), RoundingMode.DOWN); - assertEquals("GBP 0.93", test.toString()); + assertThat(test).hasToString("GBP 0.93"); } @Test void test_dividedBy_BigDecimalRoundingMode_positive_halfUp() { BigMoney test = GBP_2_34.dividedBy(bd("2.5"), RoundingMode.HALF_UP); - assertEquals("GBP 0.94", test.toString()); + assertThat(test).hasToString("GBP 0.94"); } @Test void test_dividedBy_BigDecimalRoundingMode_negative() { BigMoney test = GBP_2_34.dividedBy(bd("-2.5"), RoundingMode.FLOOR); - assertEquals("GBP -0.94", test.toString()); + assertThat(test).hasToString("GBP -0.94"); } @Test void test_dividedBy_BigDecimalRoundingMode_nullBigDecimal() { - assertThrows(NullPointerException.class, () -> { - GBP_5_78.dividedBy((BigDecimal) null, RoundingMode.DOWN); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> GBP_5_78.dividedBy((BigDecimal) null, RoundingMode.DOWN)); } @Test void test_dividedBy_BigDecimalRoundingMode_nullRoundingMode() { - assertThrows(NullPointerException.class, () -> { - GBP_5_78.dividedBy(bd("2.5"), (RoundingMode) null); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> GBP_5_78.dividedBy(bd("2.5"), (RoundingMode) null)); } //----------------------------------------------------------------------- @@ -2423,32 +2316,31 @@ void test_dividedBy_BigDecimalRoundingMode_nullRoundingMode() { @Test void test_dividedBy_doubleRoundingMode_one() { BigMoney test = GBP_2_34.dividedBy(1d, RoundingMode.DOWN); - assertSame(GBP_2_34, test); + assertThat(test).isSameAs(GBP_2_34); } @Test void test_dividedBy_doubleRoundingMode_positive() { BigMoney test = GBP_2_34.dividedBy(2.5d, RoundingMode.DOWN); - assertEquals("GBP 0.93", test.toString()); + assertThat(test).hasToString("GBP 0.93"); } @Test void test_dividedBy_doubleRoundingMode_positive_halfUp() { BigMoney test = GBP_2_34.dividedBy(2.5d, RoundingMode.HALF_UP); - assertEquals("GBP 0.94", test.toString()); + assertThat(test).hasToString("GBP 0.94"); } @Test void test_dividedBy_doubleRoundingMode_negative() { BigMoney test = GBP_2_34.dividedBy(-2.5d, RoundingMode.FLOOR); - assertEquals("GBP -0.94", test.toString()); + assertThat(test).hasToString("GBP -0.94"); } @Test void test_dividedBy_doubleRoundingMode_nullRoundingMode() { - assertThrows(NullPointerException.class, () -> { - GBP_5_78.dividedBy(2.5d, (RoundingMode) null); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> GBP_5_78.dividedBy(2.5d, (RoundingMode) null)); } //----------------------------------------------------------------------- @@ -2457,31 +2349,31 @@ void test_dividedBy_doubleRoundingMode_nullRoundingMode() { @Test void test_dividedBy_long_one() { BigMoney test = GBP_2_34.dividedBy(1, RoundingMode.DOWN); - assertSame(GBP_2_34, test); + assertThat(test).isSameAs(GBP_2_34); } @Test void test_dividedBy_long_positive() { BigMoney test = GBP_2_34.dividedBy(3, RoundingMode.DOWN); - assertEquals("GBP 0.78", test.toString()); + assertThat(test).hasToString("GBP 0.78"); } @Test void test_dividedBy_long_positive_roundDown() { BigMoney test = GBP_2_35.dividedBy(3, RoundingMode.DOWN); - assertEquals("GBP 0.78", test.toString()); + assertThat(test).hasToString("GBP 0.78"); } @Test void test_dividedBy_long_positive_roundUp() { BigMoney test = GBP_2_35.dividedBy(3, RoundingMode.UP); - assertEquals("GBP 0.79", test.toString()); + assertThat(test).hasToString("GBP 0.79"); } @Test void test_dividedBy_long_negative() { BigMoney test = GBP_2_34.dividedBy(-3, RoundingMode.DOWN); - assertEquals("GBP -0.78", test.toString()); + assertThat(test).hasToString("GBP -0.78"); } //----------------------------------------------------------------------- @@ -2490,19 +2382,19 @@ void test_dividedBy_long_negative() { @Test void test_negated_zero() { BigMoney test = GBP_0_00.negated(); - assertSame(GBP_0_00, test); + assertThat(test).isSameAs(GBP_0_00); } @Test void test_negated_positive() { BigMoney test = GBP_2_34.negated(); - assertEquals("GBP -2.34", test.toString()); + assertThat(test).hasToString("GBP -2.34"); } @Test void test_negated_negative() { BigMoney test = BigMoney.parse("GBP -2.34").negated(); - assertEquals("GBP 2.34", test.toString()); + assertThat(test).hasToString("GBP 2.34"); } //----------------------------------------------------------------------- @@ -2511,13 +2403,13 @@ void test_negated_negative() { @Test void test_abs_positive() { BigMoney test = GBP_2_34.abs(); - assertSame(GBP_2_34, test); + assertThat(test).isSameAs(GBP_2_34); } @Test void test_abs_negative() { BigMoney test = BigMoney.parse("GBP -2.34").abs(); - assertEquals("GBP 2.34", test.toString()); + assertThat(test).hasToString("GBP 2.34"); } //----------------------------------------------------------------------- @@ -2526,55 +2418,55 @@ void test_abs_negative() { @Test void test_round_2down() { BigMoney test = GBP_2_34.rounded(2, RoundingMode.DOWN); - assertSame(GBP_2_34, test); + assertThat(test).isSameAs(GBP_2_34); } @Test void test_round_2up() { BigMoney test = GBP_2_34.rounded(2, RoundingMode.DOWN); - assertSame(GBP_2_34, test); + assertThat(test).isSameAs(GBP_2_34); } @Test void test_round_1down() { BigMoney test = GBP_2_34.rounded(1, RoundingMode.DOWN); - assertEquals("GBP 2.30", test.toString()); + assertThat(test).hasToString("GBP 2.30"); } @Test void test_round_1up() { BigMoney test = GBP_2_34.rounded(1, RoundingMode.UP); - assertEquals("GBP 2.40", test.toString()); + assertThat(test).hasToString("GBP 2.40"); } @Test void test_round_0down() { BigMoney test = GBP_2_34.rounded(0, RoundingMode.DOWN); - assertEquals("GBP 2.00", test.toString()); + assertThat(test).hasToString("GBP 2.00"); } @Test void test_round_0up() { BigMoney test = GBP_2_34.rounded(0, RoundingMode.UP); - assertEquals("GBP 3.00", test.toString()); + assertThat(test).hasToString("GBP 3.00"); } @Test void test_round_M1down() { BigMoney test = BigMoney.parse("GBP 432.34").rounded(-1, RoundingMode.DOWN); - assertEquals("GBP 430.00", test.toString()); + assertThat(test).hasToString("GBP 430.00"); } @Test void test_round_M1up() { BigMoney test = BigMoney.parse("GBP 432.34").rounded(-1, RoundingMode.UP); - assertEquals("GBP 440.00", test.toString()); + assertThat(test).hasToString("GBP 440.00"); } @Test void test_round_3() { BigMoney test = GBP_2_34.rounded(3, RoundingMode.DOWN); - assertSame(GBP_2_34, test); + assertThat(test).isSameAs(GBP_2_34); } //----------------------------------------------------------------------- @@ -2583,41 +2475,37 @@ void test_round_3() { @Test void test_convertedTo_CurrencyUnit_BigDecimal_positive() { BigMoney test = GBP_2_33.convertedTo(EUR, bd("2.5")); - assertEquals("EUR 5.825", test.toString()); + assertThat(test).hasToString("EUR 5.825"); } @Test void test_convertedTo_CurrencyUnit_BigDecimal_sameCurrencyCorrectFactor() { BigMoney test = GBP_2_33.convertedTo(GBP, bd("1.00000")); - assertEquals(GBP_2_33, test); + assertThat(test).isEqualTo(GBP_2_33); } @Test void test_convertedTo_CurrencyUnit_BigDecimal_negative() { - assertThrows(IllegalArgumentException.class, () -> { - GBP_2_33.convertedTo(EUR, bd("-2.5")); - }); + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> GBP_2_33.convertedTo(EUR, bd("-2.5"))); } @Test void test_convertedTo_CurrencyUnit_BigDecimal_sameCurrencyWrongFactor() { - assertThrows(IllegalArgumentException.class, () -> { - GBP_2_33.convertedTo(GBP, bd("2.5")); - }); + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> GBP_2_33.convertedTo(GBP, bd("2.5"))); } @Test void test_convertedTo_CurrencyUnit_BigDecimal_nullCurrency() { - assertThrows(NullPointerException.class, () -> { - GBP_5_78.convertedTo((CurrencyUnit) null, bd("2")); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> GBP_5_78.convertedTo((CurrencyUnit) null, bd("2"))); } @Test void test_convertedTo_CurrencyUnit_BigDecimal_nullBigDecimal() { - assertThrows(NullPointerException.class, () -> { - GBP_5_78.convertedTo(EUR, (BigDecimal) null); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> GBP_5_78.convertedTo(EUR, (BigDecimal) null)); } //----------------------------------------------------------------------- @@ -2626,48 +2514,43 @@ void test_convertedTo_CurrencyUnit_BigDecimal_nullBigDecimal() { @Test 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()); + assertThat(test).hasToString("EUR 5.5"); } @Test 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()); + assertThat(test).hasToString("EUR 5.53"); } @Test void test_convertRetainScale_CurrencyUnit_BigDecimal_RoundingMode_negative() { - assertThrows(IllegalArgumentException.class, () -> { - GBP_2_33.convertRetainScale(EUR, bd("-2.5"), RoundingMode.DOWN); - }); + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> GBP_2_33.convertRetainScale(EUR, 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); - }); + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> GBP_2_33.convertRetainScale(GBP, bd("2.5"), RoundingMode.DOWN)); } @Test void test_convertRetainScale_CurrencyUnit_BigDecimal_RoundingMode_nullCurrency() { - assertThrows(NullPointerException.class, () -> { - GBP_5_78.convertRetainScale((CurrencyUnit) null, bd("2"), RoundingMode.DOWN); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> GBP_5_78.convertRetainScale((CurrencyUnit) null, bd("2"), RoundingMode.DOWN)); } @Test void test_convertRetainScale_CurrencyUnit_BigDecimal_RoundingMode_nullBigDecimal() { - assertThrows(NullPointerException.class, () -> { - GBP_5_78.convertRetainScale(EUR, (BigDecimal) null, RoundingMode.DOWN); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> GBP_5_78.convertRetainScale(EUR, (BigDecimal) null, RoundingMode.DOWN)); } @Test void test_convertRetainScale_CurrencyUnit_BigDecimal_RoundingMode_nullRoundingMode() { - assertThrows(NullPointerException.class, () -> { - GBP_5_78.convertRetainScale(EUR, bd("2"), (RoundingMode) null); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> GBP_5_78.convertRetainScale(EUR, bd("2"), (RoundingMode) null)); } //----------------------------------------------------------------------- @@ -2675,7 +2558,7 @@ void test_convertRetainScale_CurrencyUnit_BigDecimal_RoundingMode_nullRoundingMo //----------------------------------------------------------------------- @Test void test_toBigMoney() { - assertSame(GBP_2_34, GBP_2_34.toBigMoney()); + assertThat(GBP_2_34.toBigMoney()).isSameAs(GBP_2_34); } //----------------------------------------------------------------------- @@ -2683,7 +2566,7 @@ void test_toBigMoney() { //----------------------------------------------------------------------- @Test void test_toMoney() { - assertEquals(Money.of(GBP, BIGDEC_2_34), GBP_2_34.toMoney()); + assertThat(GBP_2_34.toMoney()).isEqualTo(Money.of(GBP, BIGDEC_2_34)); } //----------------------------------------------------------------------- @@ -2691,13 +2574,13 @@ void test_toMoney() { //----------------------------------------------------------------------- @Test void test_toMoney_RoundingMode() { - assertEquals(Money.parse("GBP 2.34"), GBP_2_34.toMoney(RoundingMode.HALF_EVEN)); + assertThat(GBP_2_34.toMoney(RoundingMode.HALF_EVEN)).isEqualTo(Money.parse("GBP 2.34")); } @Test void test_toMoney_RoundingMode_round() { BigMoney money = BigMoney.parse("GBP 2.355"); - assertEquals(Money.parse("GBP 2.36"), money.toMoney(RoundingMode.HALF_EVEN)); + assertThat(money.toMoney(RoundingMode.HALF_EVEN)).isEqualTo(Money.parse("GBP 2.36")); } //----------------------------------------------------------------------- @@ -2705,29 +2588,28 @@ void test_toMoney_RoundingMode_round() { //----------------------------------------------------------------------- @Test void test_isSameCurrency_BigMoney_same() { - assertTrue(GBP_2_34.isSameCurrency(GBP_2_35)); + assertThat(GBP_2_34.isSameCurrency(GBP_2_35)).isTrue(); } @Test void test_isSameCurrency_BigMoney_different() { - assertFalse(GBP_2_34.isSameCurrency(USD_2_34)); + assertThat(GBP_2_34.isSameCurrency(USD_2_34)).isFalse(); } @Test void test_isSameCurrency_Money_same() { - assertTrue(GBP_2_34.isSameCurrency(Money.parse("GBP 2"))); + assertThat(GBP_2_34.isSameCurrency(Money.parse("GBP 2"))).isTrue(); } @Test void test_isSameCurrency_Money_different() { - assertFalse(GBP_2_34.isSameCurrency(Money.parse("USD 2"))); + assertThat(GBP_2_34.isSameCurrency(Money.parse("USD 2"))).isFalse(); } @Test void test_isSameCurrency_Money_nullMoney() { - assertThrows(NullPointerException.class, () -> { - GBP_2_34.isSameCurrency((BigMoney) null); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> GBP_2_34.isSameCurrency((BigMoney) null)); } //----------------------------------------------------------------------- @@ -2738,18 +2620,18 @@ void test_compareTo_BigMoney() { BigMoney a = GBP_2_34; BigMoney b = GBP_2_35; BigMoney c = GBP_2_36; - assertEquals(0, a.compareTo(a)); - assertEquals(0, b.compareTo(b)); - assertEquals(0, c.compareTo(c)); + assertThat(a.compareTo(a)).isEqualTo(0); + assertThat(b.compareTo(b)).isEqualTo(0); + assertThat(c.compareTo(c)).isEqualTo(0); - assertEquals(-1, a.compareTo(b)); - assertEquals(1, b.compareTo(a)); + assertThat(a.compareTo(b)).isEqualTo(-1); + assertThat(b.compareTo(a)).isEqualTo(1); - assertEquals(-1, a.compareTo(c)); - assertEquals(1, c.compareTo(a)); + assertThat(a.compareTo(c)).isEqualTo(-1); + assertThat(c.compareTo(a)).isEqualTo(1); - assertEquals(-1, b.compareTo(c)); - assertEquals(1, c.compareTo(b)); + assertThat(b.compareTo(c)).isEqualTo(-1); + assertThat(c.compareTo(b)).isEqualTo(1); } @Test @@ -2758,27 +2640,25 @@ void test_compareTo_Money() { Money a = Money.ofMinor(GBP, 234); Money b = Money.ofMinor(GBP, 235); Money c = Money.ofMinor(GBP, 236); - assertEquals(1, t.compareTo(a)); - assertEquals(0, t.compareTo(b)); - assertEquals(-1, t.compareTo(c)); + assertThat(t.compareTo(a)).isEqualTo(1); + assertThat(t.compareTo(b)).isEqualTo(0); + assertThat(t.compareTo(c)).isEqualTo(-1); } @Test void test_compareTo_currenciesDiffer() { BigMoney a = GBP_2_34; BigMoney b = USD_2_35; - assertThrows(CurrencyMismatchException.class, () -> { - a.compareTo(b); - }); + assertThatExceptionOfType(CurrencyMismatchException.class) + .isThrownBy(() -> a.compareTo(b)); } @Test @SuppressWarnings({"unchecked", "rawtypes"}) void test_compareTo_wrongType() { Comparable a = GBP_2_34; - assertThrows(ClassCastException.class, () -> { - a.compareTo("NotRightType"); - }); + assertThatExceptionOfType(ClassCastException.class) + .isThrownBy(() -> a.compareTo("NotRightType")); } //----------------------------------------------------------------------- @@ -2789,34 +2669,33 @@ void test_isEqual() { BigMoney a = GBP_2_34; BigMoney b = GBP_2_35; BigMoney c = GBP_2_36; - assertTrue(a.isEqual(a)); - assertTrue(b.isEqual(b)); - assertTrue(c.isEqual(c)); + assertThat(a.isEqual(a)).isTrue(); + assertThat(b.isEqual(b)).isTrue(); + assertThat(c.isEqual(c)).isTrue(); - assertFalse(a.isEqual(b)); - assertFalse(b.isEqual(a)); + assertThat(a.isEqual(b)).isFalse(); + assertThat(b.isEqual(a)).isFalse(); - assertFalse(a.isEqual(c)); - assertFalse(c.isEqual(a)); + assertThat(a.isEqual(c)).isFalse(); + assertThat(c.isEqual(a)).isFalse(); - assertFalse(b.isEqual(c)); - assertFalse(c.isEqual(b)); + assertThat(b.isEqual(c)).isFalse(); + assertThat(c.isEqual(b)).isFalse(); } @Test void test_isEqual_Money() { BigMoney a = GBP_2_34; Money b = Money.ofMinor(GBP, 234); - assertTrue(a.isEqual(b)); + assertThat(a.isEqual(b)).isTrue(); } @Test void test_isEqual_currenciesDiffer() { BigMoney a = GBP_2_34; BigMoney b = USD_2_35; - assertThrows(CurrencyMismatchException.class, () -> { - a.isEqual(b); - }); + assertThatExceptionOfType(CurrencyMismatchException.class) + .isThrownBy(() -> a.isEqual(b)); } //----------------------------------------------------------------------- @@ -2827,26 +2706,25 @@ void test_isGreaterThan() { BigMoney a = GBP_2_34; BigMoney b = GBP_2_35; BigMoney c = GBP_2_36; - assertFalse(a.isGreaterThan(a)); - assertFalse(a.isGreaterThan(b)); - assertFalse(a.isGreaterThan(c)); + assertThat(a.isGreaterThan(a)).isFalse(); + assertThat(a.isGreaterThan(b)).isFalse(); + assertThat(a.isGreaterThan(c)).isFalse(); - assertTrue(b.isGreaterThan(a)); - assertFalse(b.isGreaterThan(b)); - assertFalse(b.isGreaterThan(c)); + assertThat(b.isGreaterThan(a)).isTrue(); + assertThat(b.isGreaterThan(b)).isFalse(); + assertThat(b.isGreaterThan(c)).isFalse(); - assertTrue(c.isGreaterThan(a)); - assertTrue(c.isGreaterThan(b)); - assertFalse(c.isGreaterThan(c)); + assertThat(c.isGreaterThan(a)).isTrue(); + assertThat(c.isGreaterThan(b)).isTrue(); + assertThat(c.isGreaterThan(c)).isFalse(); } @Test void test_isGreaterThan_currenciesDiffer() { BigMoney a = GBP_2_34; BigMoney b = USD_2_35; - assertThrows(CurrencyMismatchException.class, () -> { - a.isGreaterThan(b); - }); + assertThatExceptionOfType(CurrencyMismatchException.class) + .isThrownBy(() -> a.isGreaterThan(b)); } //----------------------------------------------------------------------- @@ -2857,26 +2735,25 @@ void test_isGreaterThanOrEqual() { BigMoney a = GBP_2_34; BigMoney b = GBP_2_35; BigMoney c = GBP_2_36; - assertTrue(a.isGreaterThanOrEqual(a)); - assertFalse(a.isGreaterThanOrEqual(b)); - assertFalse(a.isGreaterThanOrEqual(c)); + assertThat(a.isGreaterThanOrEqual(a)).isTrue(); + assertThat(a.isGreaterThanOrEqual(b)).isFalse(); + assertThat(a.isGreaterThanOrEqual(c)).isFalse(); - assertTrue(b.isGreaterThanOrEqual(a)); - assertTrue(b.isGreaterThanOrEqual(b)); - assertFalse(b.isGreaterThanOrEqual(c)); + assertThat(b.isGreaterThanOrEqual(a)).isTrue(); + assertThat(b.isGreaterThanOrEqual(b)).isTrue(); + assertThat(b.isGreaterThanOrEqual(c)).isFalse(); - assertTrue(c.isGreaterThanOrEqual(a)); - assertTrue(c.isGreaterThanOrEqual(b)); - assertTrue(c.isGreaterThanOrEqual(c)); + assertThat(c.isGreaterThanOrEqual(a)).isTrue(); + assertThat(c.isGreaterThanOrEqual(b)).isTrue(); + assertThat(c.isGreaterThanOrEqual(c)).isTrue(); } @Test void test_isGreaterThanOrEqual_currenciesDiffer() { BigMoney a = GBP_2_34; BigMoney b = USD_2_35; - assertThrows(CurrencyMismatchException.class, () -> { - a.isGreaterThanOrEqual(b); - }); + assertThatExceptionOfType(CurrencyMismatchException.class) + .isThrownBy(() -> a.isGreaterThanOrEqual(b)); } //----------------------------------------------------------------------- @@ -2887,26 +2764,25 @@ void test_isLessThan() { BigMoney a = GBP_2_34; BigMoney b = GBP_2_35; BigMoney c = GBP_2_36; - assertFalse(a.isLessThan(a)); - assertTrue(a.isLessThan(b)); - assertTrue(a.isLessThan(c)); + assertThat(a.isLessThan(a)).isFalse(); + assertThat(a.isLessThan(b)).isTrue(); + assertThat(a.isLessThan(c)).isTrue(); - assertFalse(b.isLessThan(a)); - assertFalse(b.isLessThan(b)); - assertTrue(b.isLessThan(c)); + assertThat(b.isLessThan(a)).isFalse(); + assertThat(b.isLessThan(b)).isFalse(); + assertThat(b.isLessThan(c)).isTrue(); - assertFalse(c.isLessThan(a)); - assertFalse(c.isLessThan(b)); - assertFalse(c.isLessThan(c)); + assertThat(c.isLessThan(a)).isFalse(); + assertThat(c.isLessThan(b)).isFalse(); + assertThat(c.isLessThan(c)).isFalse(); } @Test void test_isLessThan_currenciesDiffer() { BigMoney a = GBP_2_34; BigMoney b = USD_2_35; - assertThrows(CurrencyMismatchException.class, () -> { - a.isLessThan(b); - }); + assertThatExceptionOfType(CurrencyMismatchException.class) + .isThrownBy(() -> a.isLessThan(b)); } //----------------------------------------------------------------------- @@ -2917,26 +2793,25 @@ void test_isLessThanOrEqual() { BigMoney a = GBP_2_34; BigMoney b = GBP_2_35; BigMoney c = GBP_2_36; - assertTrue(a.isLessThanOrEqual(a)); - assertTrue(a.isLessThanOrEqual(b)); - assertTrue(a.isLessThanOrEqual(c)); + assertThat(a.isLessThanOrEqual(a)).isTrue(); + assertThat(a.isLessThanOrEqual(b)).isTrue(); + assertThat(a.isLessThanOrEqual(c)).isTrue(); - assertFalse(b.isLessThanOrEqual(a)); - assertTrue(b.isLessThanOrEqual(b)); - assertTrue(b.isLessThanOrEqual(c)); + assertThat(b.isLessThanOrEqual(a)).isFalse(); + assertThat(b.isLessThanOrEqual(b)).isTrue(); + assertThat(b.isLessThanOrEqual(c)).isTrue(); - assertFalse(c.isLessThanOrEqual(a)); - assertFalse(c.isLessThanOrEqual(b)); - assertTrue(c.isLessThanOrEqual(c)); + assertThat(c.isLessThanOrEqual(a)).isFalse(); + assertThat(c.isLessThanOrEqual(b)).isFalse(); + assertThat(c.isLessThanOrEqual(c)).isTrue(); } @Test void test_isLessThanOrEqual_currenciesDiffer() { BigMoney a = GBP_2_34; BigMoney b = USD_2_35; - assertThrows(CurrencyMismatchException.class, () -> { - a.isLessThanOrEqual(b); - }); + assertThatExceptionOfType(CurrencyMismatchException.class) + .isThrownBy(() -> a.isLessThanOrEqual(b)); } //----------------------------------------------------------------------- @@ -2947,23 +2822,23 @@ void test_equals_hashCode_positive() { BigMoney a = GBP_2_34; BigMoney b = GBP_2_34; BigMoney c = GBP_2_35; - assertTrue(a.equals(a)); - assertTrue(b.equals(b)); - assertTrue(c.equals(c)); + assertThat(a).isEqualTo(a); + assertThat(b).isEqualTo(b); + assertThat(c).isEqualTo(c); - assertTrue(a.equals(b)); - assertTrue(b.equals(a)); - assertTrue(a.hashCode() == b.hashCode()); + assertThat(b).isEqualTo(a); + assertThat(a).isEqualTo(b); + assertThat(b.hashCode()).isEqualTo(a.hashCode()); - assertFalse(a.equals(c)); - assertFalse(b.equals(c)); + assertThat(c).isNotEqualTo(a); + assertThat(c).isNotEqualTo(b); } @Test void test_equals_false() { BigMoney a = GBP_2_34; - assertFalse(a.equals(null)); - assertFalse(a.equals(new Object())); + assertThat(a).isNotEqualTo(null); + assertThat(new Object()).isNotEqualTo(a); } //----------------------------------------------------------------------- @@ -2972,13 +2847,13 @@ void test_equals_false() { @Test void test_toString_positive() { BigMoney test = BigMoney.of(GBP, BIGDEC_2_34); - assertEquals("GBP 2.34", test.toString()); + assertThat(test).hasToString("GBP 2.34"); } @Test void test_toString_negative() { BigMoney test = BigMoney.of(EUR, BIGDEC_M5_78); - assertEquals("EUR -5.78", test.toString()); + assertThat(test).hasToString("EUR -5.78"); } } diff --git a/src/test/java/org/joda/money/TestCurrencyMismatchException.java b/src/test/java/org/joda/money/TestCurrencyMismatchException.java index 42c9852..ed5dd07 100644 --- a/src/test/java/org/joda/money/TestCurrencyMismatchException.java +++ b/src/test/java/org/joda/money/TestCurrencyMismatchException.java @@ -15,8 +15,7 @@ */ package org.joda.money; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; +import static org.assertj.core.api.Assertions.assertThat; import org.junit.jupiter.api.Test; @@ -34,37 +33,37 @@ class TestCurrencyMismatchException { @Test void test_new_GBPEUR() { CurrencyMismatchException test = new CurrencyMismatchException(GBP, EUR); - assertEquals("Currencies differ: GBP/EUR", test.getMessage()); - assertNull(test.getCause()); - assertEquals(GBP, test.getFirstCurrency()); - assertEquals(EUR, test.getSecondCurrency()); + assertThat(test.getMessage()).isEqualTo("Currencies differ: GBP/EUR"); + assertThat(test.getCause()).isNull(); + assertThat(test.getFirstCurrency()).isEqualTo(GBP); + assertThat(test.getSecondCurrency()).isEqualTo(EUR); } @Test void test_new_nullEUR() { CurrencyMismatchException test = new CurrencyMismatchException(null, EUR); - assertEquals("Currencies differ: null/EUR", test.getMessage()); - assertNull(test.getCause()); - assertNull(test.getFirstCurrency()); - assertEquals(EUR, test.getSecondCurrency()); + assertThat(test.getMessage()).isEqualTo("Currencies differ: null/EUR"); + assertThat(test.getCause()).isNull(); + assertThat(test.getFirstCurrency()).isNull(); + assertThat(test.getSecondCurrency()).isEqualTo(EUR); } @Test void test_new_GBPnull() { CurrencyMismatchException test = new CurrencyMismatchException(GBP, null); - assertEquals("Currencies differ: GBP/null", test.getMessage()); - assertNull(test.getCause()); - assertEquals(GBP, test.getFirstCurrency()); - assertNull(test.getSecondCurrency()); + assertThat(test.getMessage()).isEqualTo("Currencies differ: GBP/null"); + assertThat(test.getCause()).isNull(); + assertThat(test.getFirstCurrency()).isEqualTo(GBP); + assertThat(test.getSecondCurrency()).isNull(); } @Test void test_new_nullnull() { CurrencyMismatchException test = new CurrencyMismatchException(null, null); - assertEquals("Currencies differ: null/null", test.getMessage()); - assertNull(test.getCause()); - assertNull(test.getFirstCurrency()); - assertNull(test.getSecondCurrency()); + assertThat(test.getMessage()).isEqualTo("Currencies differ: null/null"); + assertThat(test.getCause()).isNull(); + assertThat(test.getFirstCurrency()).isNull(); + assertThat(test.getSecondCurrency()).isNull(); } } diff --git a/src/test/java/org/joda/money/TestCurrencyUnit.java b/src/test/java/org/joda/money/TestCurrencyUnit.java index bad8075..67196e8 100644 --- a/src/test/java/org/joda/money/TestCurrencyUnit.java +++ b/src/test/java/org/joda/money/TestCurrencyUnit.java @@ -15,10 +15,8 @@ */ package org.joda.money; -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 static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -56,7 +54,7 @@ void test_registeredCurrencies() { break; } } - assertTrue(found); + assertThat(found).isTrue(); } @Test @@ -64,94 +62,82 @@ void test_registeredCurrencies_sorted() { List curList1 = CurrencyUnit.registeredCurrencies(); List curList2 = CurrencyUnit.registeredCurrencies(); Collections.sort(curList2); - assertEquals(curList2, curList1); + assertThat(curList1).isEqualTo(curList2); Collections.shuffle(curList2); Collections.sort(curList2); - assertEquals(curList2, curList1); + assertThat(curList1).isEqualTo(curList2); } @Test void test_registeredCurrency_nullCode() { - assertThrows(NullPointerException.class, () -> { - CurrencyUnit.registerCurrency(null, 991, 2, Arrays.asList("TS")); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> CurrencyUnit.registerCurrency(null, 991, 2, Arrays.asList("TS"))); } @Test void test_registeredCurrency_invalidStringCode_empty() { - assertThrows(IllegalArgumentException.class, () -> { - CurrencyUnit.registerCurrency("", 991, 2, Arrays.asList("TS")); - }); + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> CurrencyUnit.registerCurrency("", 991, 2, Arrays.asList("TS"))); } @Test void test_registeredCurrency_invalidStringCode_1letter() { - assertThrows(IllegalArgumentException.class, () -> { - CurrencyUnit.registerCurrency("A", 991, 2, Arrays.asList("TS")); - }); + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> CurrencyUnit.registerCurrency("A", 991, 2, Arrays.asList("TS"))); } @Test void test_registeredCurrency_invalidStringCode_2letters() { - assertThrows(IllegalArgumentException.class, () -> { - CurrencyUnit.registerCurrency("AB", 991, 2, Arrays.asList("TS")); - }); + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> CurrencyUnit.registerCurrency("AB", 991, 2, Arrays.asList("TS"))); } @Test void test_registeredCurrency_invalidStringCode_4letters() { - assertThrows(IllegalArgumentException.class, () -> { - CurrencyUnit.registerCurrency("ABCD", 991, 2, Arrays.asList("TS")); - }); + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> CurrencyUnit.registerCurrency("ABCD", 991, 2, Arrays.asList("TS"))); } @Test void test_registeredCurrency_invalidStringCode_lowerCase() { - assertThrows(IllegalArgumentException.class, () -> { - CurrencyUnit.registerCurrency("xxA", 991, 2, Arrays.asList("xx")); - }); + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> CurrencyUnit.registerCurrency("xxA", 991, 2, Arrays.asList("xx"))); } @Test void test_registeredCurrency_invalidStringCode_number() { - assertThrows(IllegalArgumentException.class, () -> { - CurrencyUnit.registerCurrency("123", 991, 2, Arrays.asList("TS")); - }); + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> CurrencyUnit.registerCurrency("123", 991, 2, Arrays.asList("TS"))); } @Test void test_registeredCurrency_invalidStringCode_dash() { - assertThrows(IllegalArgumentException.class, () -> { - CurrencyUnit.registerCurrency("A-", 991, 2, Arrays.asList("TS")); - }); + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> CurrencyUnit.registerCurrency("A-", 991, 2, Arrays.asList("TS"))); } @Test void test_registeredCurrency_invalidNumericCode_small() { - assertThrows(IllegalArgumentException.class, () -> { - CurrencyUnit.registerCurrency("TST", -2, 2, Arrays.asList("TS")); - }); + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> CurrencyUnit.registerCurrency("TST", -2, 2, Arrays.asList("TS"))); } @Test void test_registeredCurrency_invalidNumericCode_big() { - assertThrows(IllegalArgumentException.class, () -> { - CurrencyUnit.registerCurrency("TST", 1000, 2, Arrays.asList("TS")); - }); + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> CurrencyUnit.registerCurrency("TST", 1000, 2, Arrays.asList("TS"))); } @Test void test_registeredCurrency_invalidDP_small() { - assertThrows(IllegalArgumentException.class, () -> { - CurrencyUnit.registerCurrency("TST", 991, -2, Arrays.asList("TS")); - }); + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> CurrencyUnit.registerCurrency("TST", 991, -2, Arrays.asList("TS"))); } @Test void test_registeredCurrency_invalidDP_big() { - assertThrows(IllegalArgumentException.class, () -> { - CurrencyUnit.registerCurrency("TST", 991, 31, Arrays.asList("TS")); - }); + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> CurrencyUnit.registerCurrency("TST", 991, 31, Arrays.asList("TS"))); } @Test @@ -159,35 +145,31 @@ void test_registeredCurrency_validDP_big() { CurrencyUnit.registerCurrency("XLG", -1, 30, new ArrayList()); CurrencyUnit currency = CurrencyUnit.of("XLG"); - assertEquals(30, currency.getDecimalPlaces()); + assertThat(currency.getDecimalPlaces()).isEqualTo(30); } @Test void test_registeredCurrency_nullCountry() { - assertThrows(NullPointerException.class, () -> { - CurrencyUnit.registerCurrency("TST", 991, 2, Arrays.asList((String) null)); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> CurrencyUnit.registerCurrency("TST", 991, 2, Arrays.asList((String) null))); } @Test void test_registeredCurrency_alreadyRegisteredCode() { - assertThrows(IllegalArgumentException.class, () -> { - CurrencyUnit.registerCurrency("GBP", 991, 2, Arrays.asList("GB")); - }); + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> CurrencyUnit.registerCurrency("GBP", 991, 2, Arrays.asList("GB"))); } @Test void test_registeredCurrency_alreadyRegisteredNumericCode() { - assertThrows(IllegalArgumentException.class, () -> { - CurrencyUnit.registerCurrency("TST", 826, 2, Arrays.asList("TS")); - }); + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> CurrencyUnit.registerCurrency("TST", 826, 2, Arrays.asList("TS"))); } @Test void test_registeredCurrency_alreadyRegisteredCountry() { - assertThrows(IllegalArgumentException.class, () -> { - CurrencyUnit.registerCurrency("GBX", 991, 2, Arrays.asList("GB")); - }); + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> CurrencyUnit.registerCurrency("GBX", 991, 2, Arrays.asList("GB"))); } @Test @@ -197,7 +179,7 @@ void test_registeredCurrencies_crossCheck() { try { Currency curr = Currency.getInstance(currencyUnit.getCode()); int dp = curr.getDefaultFractionDigits() < 0 ? 0 : curr.getDefaultFractionDigits(); - assertEquals(dp, currencyUnit.getDecimalPlaces(), curr.getCurrencyCode()); + assertThat(currencyUnit.getDecimalPlaces()).as(curr.getCurrencyCode()).isEqualTo(dp); } catch (IllegalArgumentException ignored) { } } @@ -209,9 +191,9 @@ void test_registeredCurrencies_crossCheck() { @Test void test_registeredCountries() { List countryList = CurrencyUnit.registeredCountries(); - assertTrue(countryList.contains("GB")); - assertTrue(countryList.contains("EU")); - assertTrue(countryList.contains("US")); + assertThat(countryList).contains("GB"); + assertThat(countryList).contains("EU"); + assertThat(countryList).contains("US"); } @Test @@ -219,10 +201,10 @@ void test_registeredCountries_sorted() { List curList1 = CurrencyUnit.registeredCountries(); List curList2 = CurrencyUnit.registeredCountries(); Collections.sort(curList2); - assertEquals(curList2, curList1); + assertThat(curList1).isEqualTo(curList2); Collections.shuffle(curList2); Collections.sort(curList2); - assertEquals(curList2, curList1); + assertThat(curList1).isEqualTo(curList2); } //----------------------------------------------------------------------- @@ -230,13 +212,13 @@ void test_registeredCountries_sorted() { //----------------------------------------------------------------------- @Test 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")); + assertThat(CurrencyUnit.of("USD")).isEqualTo(CurrencyUnit.USD); + assertThat(CurrencyUnit.of("EUR")).isEqualTo(CurrencyUnit.EUR); + assertThat(CurrencyUnit.of("JPY")).isEqualTo(CurrencyUnit.JPY); + assertThat(CurrencyUnit.of("GBP")).isEqualTo(CurrencyUnit.GBP); + assertThat(CurrencyUnit.of("CHF")).isEqualTo(CurrencyUnit.CHF); + assertThat(CurrencyUnit.of("AUD")).isEqualTo(CurrencyUnit.AUD); + assertThat(CurrencyUnit.of("CAD")).isEqualTo(CurrencyUnit.CAD); } //----------------------------------------------------------------------- @@ -244,9 +226,8 @@ void test_constants() { //----------------------------------------------------------------------- @Test void test_constructor_nullCode() { - assertThrows(AssertionError.class, () -> { - new CurrencyUnit(null, (short) 1, (short) 2); - }); + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> new CurrencyUnit(null, (short) 1, (short) 2)); } //----------------------------------------------------------------------- @@ -255,14 +236,13 @@ void test_constructor_nullCode() { @Test void test_factory_of_Currency() { CurrencyUnit test = CurrencyUnit.of(JDK_GBP); - assertEquals("GBP", test.getCode()); + assertThat(test.getCode()).isEqualTo("GBP"); } @Test void test_factory_of_Currency_nullCurrency() { - assertThrows(NullPointerException.class, () -> { - CurrencyUnit.of((Currency) null); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> CurrencyUnit.of((Currency) null)); } //----------------------------------------------------------------------- @@ -271,47 +251,38 @@ void test_factory_of_Currency_nullCurrency() { @Test void test_factory_of_String() { CurrencyUnit test = CurrencyUnit.of("GBP"); - assertEquals("GBP", test.getCode()); + assertThat(test.getCode()).isEqualTo("GBP"); } @Test void test_factory_of_String_nullString() { - assertThrows(NullPointerException.class, () -> { - CurrencyUnit.of((String) null); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> CurrencyUnit.of((String) null)); } @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; - } - }); + assertThatExceptionOfType(IllegalCurrencyException.class) + .isThrownBy(() -> CurrencyUnit.of("ABC")) + .withMessage("Unknown currency 'ABC'"); } @Test void test_factory_of_String_empty() { - assertThrows(IllegalCurrencyException.class, () -> { - CurrencyUnit.of(""); - }); + assertThatExceptionOfType(IllegalCurrencyException.class) + .isThrownBy(() -> CurrencyUnit.of("")); } @Test void test_factory_of_String_tooShort_unknown() { - assertThrows(IllegalCurrencyException.class, () -> { - CurrencyUnit.of("AB"); - }); + assertThatExceptionOfType(IllegalCurrencyException.class) + .isThrownBy(() -> CurrencyUnit.of("AB")); } @Test void test_factory_of_String_tooLong_unknown() { - assertThrows(IllegalCurrencyException.class, () -> { - CurrencyUnit.of("ABCD"); - }); + assertThatExceptionOfType(IllegalCurrencyException.class) + .isThrownBy(() -> CurrencyUnit.of("ABCD")); } //----------------------------------------------------------------------- @@ -320,81 +291,64 @@ void test_factory_of_String_tooLong_unknown() { @Test void test_factory_ofNumericCode_String() { CurrencyUnit test = CurrencyUnit.ofNumericCode("826"); - assertEquals("GBP", test.getCode()); + assertThat(test.getCode()).isEqualTo("GBP"); } @Test void test_factory_ofNumericCode_String_2char() { CurrencyUnit test = CurrencyUnit.ofNumericCode("051"); - assertEquals("AMD", test.getCode()); + assertThat(test.getCode()).isEqualTo("AMD"); } @Test void test_factory_ofNumericCode_String_2charNoPad() { CurrencyUnit test = CurrencyUnit.ofNumericCode("51"); - assertEquals("AMD", test.getCode()); + assertThat(test.getCode()).isEqualTo("AMD"); } @Test void test_factory_ofNumericCode_String_1char() { CurrencyUnit test = CurrencyUnit.ofNumericCode("008"); - assertEquals("ALL", test.getCode()); + assertThat(test.getCode()).isEqualTo("ALL"); } @Test void test_factory_ofNumericCode_String_1charNoPad() { CurrencyUnit test = CurrencyUnit.ofNumericCode("8"); - assertEquals("ALL", test.getCode()); + assertThat(test.getCode()).isEqualTo("ALL"); } @Test void test_factory_ofNumericCode_String_nullString() { - assertThrows(NullPointerException.class, () -> { - CurrencyUnit.ofNumericCode((String) null); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> CurrencyUnit.ofNumericCode((String) null)); } @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; - } - }); + assertThatExceptionOfType(IllegalCurrencyException.class) + .isThrownBy(() -> CurrencyUnit.ofNumericCode("111")) + .withMessage("Unknown currency '111'"); } @Test void test_factory_ofNumericCode_String_negative() { - assertThrows(IllegalCurrencyException.class, () -> { - CurrencyUnit.ofNumericCode("-1"); - }); + assertThatExceptionOfType(IllegalCurrencyException.class) + .isThrownBy(() -> CurrencyUnit.ofNumericCode("-1")); } @Test void test_factory_ofNumericCode_String_empty() { - assertThrows(IllegalCurrencyException.class, () -> { - try { - CurrencyUnit.ofNumericCode(""); - } catch (IllegalCurrencyException ex) { - assertEquals("Unknown currency ''", ex.getMessage()); - throw ex; - } - }); + assertThatExceptionOfType(IllegalCurrencyException.class) + .isThrownBy(() -> CurrencyUnit.ofNumericCode("")) + .withMessage("Unknown currency ''"); } @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; - } - }); + assertThatExceptionOfType(IllegalCurrencyException.class) + .isThrownBy(() -> CurrencyUnit.ofNumericCode("1234")) + .withMessage("Unknown currency '1234'"); } //----------------------------------------------------------------------- @@ -403,55 +357,40 @@ void test_factory_ofNumericCode_String_tooLong() { @Test void test_factory_ofNumericCode_int() { CurrencyUnit test = CurrencyUnit.ofNumericCode(826); - assertEquals("GBP", test.getCode()); + assertThat(test.getCode()).isEqualTo("GBP"); } @Test void test_factory_ofNumericCode_int_2char() { CurrencyUnit test = CurrencyUnit.ofNumericCode(51); - assertEquals("AMD", test.getCode()); + assertThat(test.getCode()).isEqualTo("AMD"); } @Test void test_factory_ofNumericCode_int_1char() { CurrencyUnit test = CurrencyUnit.ofNumericCode(8); - assertEquals("ALL", test.getCode()); + assertThat(test.getCode()).isEqualTo("ALL"); } @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; - } - }); + assertThatExceptionOfType(IllegalCurrencyException.class) + .isThrownBy(() -> CurrencyUnit.ofNumericCode(111)) + .withMessage("Unknown currency '111'"); } @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; - } - }); + assertThatExceptionOfType(IllegalCurrencyException.class) + .isThrownBy(() -> CurrencyUnit.ofNumericCode(-1)) + .withMessage("Unknown currency '-1'"); } @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; - } - }); + assertThatExceptionOfType(IllegalCurrencyException.class) + .isThrownBy(() -> CurrencyUnit.ofNumericCode(1234)) + .withMessage("Unknown currency '1234'"); } //----------------------------------------------------------------------- @@ -460,32 +399,26 @@ void test_factory_ofNumericCode_int_tooLong() { @Test void test_factory_of_LocaleUK() { CurrencyUnit test = CurrencyUnit.of(Locale.UK); - assertEquals("GBP", test.getCode()); + assertThat(test.getCode()).isEqualTo("GBP"); } @Test void test_factory_of_LocaleUS() { CurrencyUnit test = CurrencyUnit.of(Locale.US); - assertEquals("USD", test.getCode()); + assertThat(test.getCode()).isEqualTo("USD"); } @Test void test_factory_of_Locale_nullLocale() { - assertThrows(NullPointerException.class, () -> { - CurrencyUnit.of((Locale) null); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> CurrencyUnit.of((Locale) null)); } @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; - } - }); + assertThatExceptionOfType(IllegalCurrencyException.class) + .isThrownBy(() -> CurrencyUnit.of(new Locale("en", "XY"))) + .withMessage("No currency found for locale 'en_XY'"); } //----------------------------------------------------------------------- @@ -494,26 +427,20 @@ void test_factory_of_Locale_unknownCurrency() { @Test void test_factory_ofCountry_String() { CurrencyUnit test = CurrencyUnit.ofCountry("GB"); - assertEquals("GBP", test.getCode()); + assertThat(test.getCode()).isEqualTo("GBP"); } @Test void test_factory_ofCountry_String_nullString() { - assertThrows(NullPointerException.class, () -> { - CurrencyUnit.ofCountry((String) null); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> CurrencyUnit.ofCountry((String) null)); } @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; - } - }); + assertThatExceptionOfType(IllegalCurrencyException.class) + .isThrownBy(() -> CurrencyUnit.ofCountry("gb")) + .withMessage("No currency found for country 'gb'"); } //----------------------------------------------------------------------- @@ -528,7 +455,7 @@ void test_serialization() throws Exception { oos.close(); ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); CurrencyUnit input = (CurrencyUnit) ois.readObject(); - assertEquals(cu, input); + assertThat(input).isEqualTo(cu); } } @@ -540,16 +467,10 @@ void test_serialization_invalidNumericCode() throws IOException { oos.writeObject(cu); oos.close(); ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); - assertThrows(InvalidObjectException.class, () -> { - try { - ois.readObject(); - } catch (InvalidObjectException ex) { - // expected - assertTrue(ex.getMessage().contains("numeric code")); - assertTrue(ex.getMessage().contains("currency GBP")); - throw ex; - } - }); + assertThatExceptionOfType(InvalidObjectException.class) + .isThrownBy(() -> ois.readObject()) + .withMessageContaining("numeric code") + .withMessageContaining("currency GBP"); } } @@ -561,16 +482,10 @@ void test_serialization_invalidDecimalPlaces() throws IOException { oos.writeObject(cu); oos.close(); ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); - assertThrows(InvalidObjectException.class, () -> { - try { - ois.readObject(); - } catch (InvalidObjectException ex) { - // expected - assertTrue(ex.getMessage().contains("decimal places")); - assertTrue(ex.getMessage().contains("currency GBP")); - throw ex; - } - }); + assertThatExceptionOfType(InvalidObjectException.class) + .isThrownBy(() -> ois.readObject()) + .withMessageContaining("decimal places") + .withMessageContaining("currency GBP"); } } @@ -580,25 +495,25 @@ void test_serialization_invalidDecimalPlaces() throws IOException { @Test void test_getNumeric3Code_GBP() { CurrencyUnit test = CurrencyUnit.of("GBP"); - assertEquals("826", test.getNumeric3Code()); + assertThat(test.getNumeric3Code()).isEqualTo("826"); } @Test void test_getNumeric3Code_ALL() { CurrencyUnit test = CurrencyUnit.of("ALL"); - assertEquals("008", test.getNumeric3Code()); + assertThat(test.getNumeric3Code()).isEqualTo("008"); } @Test void test_getNumeric3Code_AMD() { CurrencyUnit test = CurrencyUnit.of("AMD"); - assertEquals("051", test.getNumeric3Code()); + assertThat(test.getNumeric3Code()).isEqualTo("051"); } @Test void test_getNumeric3Code_XFU() { CurrencyUnit test = CurrencyUnit.of("XFU"); - assertEquals("", test.getNumeric3Code()); + assertThat(test.getNumeric3Code()).isEmpty(); } //----------------------------------------------------------------------- @@ -607,7 +522,7 @@ void test_getNumeric3Code_XFU() { @Test void test_getNumericCode_GBP() { CurrencyUnit test = CurrencyUnit.of("GBP"); - assertEquals(826, test.getNumericCode()); + assertThat(test.getNumericCode()).isEqualTo(826); } //----------------------------------------------------------------------- @@ -616,10 +531,10 @@ void test_getNumericCode_GBP() { @Test void test_getCurrencyCodes_GBP() { Set test = CurrencyUnit.of("GBP").getCountryCodes(); - assertTrue(test.contains("GB")); - assertTrue(test.contains("IM")); - assertTrue(test.contains("JE")); - assertTrue(test.contains("GG")); + assertThat(test).contains("GB"); + assertThat(test).contains("IM"); + assertThat(test).contains("JE"); + assertThat(test).contains("GG"); } //----------------------------------------------------------------------- @@ -628,19 +543,19 @@ void test_getCurrencyCodes_GBP() { @Test void test_getDecimalPlaces_GBP() { CurrencyUnit test = CurrencyUnit.of("GBP"); - assertEquals(2, test.getDecimalPlaces()); + assertThat(test.getDecimalPlaces()).isEqualTo(2); } @Test void test_getDecimalPlaces_JPY() { CurrencyUnit test = CurrencyUnit.of("JPY"); - assertEquals(0, test.getDecimalPlaces()); + assertThat(test.getDecimalPlaces()).isEqualTo(0); } @Test void test_getDecimalPlaces_XXX() { CurrencyUnit test = CurrencyUnit.of("XXX"); - assertEquals(0, test.getDecimalPlaces()); + assertThat(test.getDecimalPlaces()).isEqualTo(0); } //----------------------------------------------------------------------- @@ -649,19 +564,19 @@ void test_getDecimalPlaces_XXX() { @Test void test_isPseudoCurrency_GBP() { CurrencyUnit test = CurrencyUnit.of("GBP"); - assertFalse(test.isPseudoCurrency()); + assertThat(test.isPseudoCurrency()).isFalse(); } @Test void test_isPseudoCurrency_JPY() { CurrencyUnit test = CurrencyUnit.of("JPY"); - assertFalse(test.isPseudoCurrency()); + assertThat(test.isPseudoCurrency()).isFalse(); } @Test void test_isPseudoCurrency_XXX() { CurrencyUnit test = CurrencyUnit.of("XXX"); - assertTrue(test.isPseudoCurrency()); + assertThat(test.isPseudoCurrency()).isTrue(); } //----------------------------------------------------------------------- @@ -673,7 +588,7 @@ void test_getSymbol_GBP() { try { Locale.setDefault(Locale.UK); CurrencyUnit test = CurrencyUnit.of("GBP"); - assertEquals("\u00A3", test.getSymbol()); + assertThat(test.getSymbol()).isEqualTo("\u00A3"); } finally { Locale.setDefault(loc); } @@ -685,7 +600,7 @@ void test_getSymbol_JPY() { try { Locale.setDefault(Locale.UK); CurrencyUnit test = CurrencyUnit.of("JPY"); - assertTrue(test.getSymbol().contains("JP")); + assertThat(test.getSymbol()).contains("JP"); } finally { Locale.setDefault(loc); } @@ -697,7 +612,7 @@ void test_getSymbol_TMT() { try { Locale.setDefault(Locale.UK); CurrencyUnit test = CurrencyUnit.of("TMT"); - assertEquals("TMT", test.getSymbol()); + assertThat(test.getSymbol()).isEqualTo("TMT"); } finally { Locale.setDefault(loc); } @@ -709,7 +624,7 @@ void test_getSymbol_XXX() { try { Locale.setDefault(Locale.UK); CurrencyUnit test = CurrencyUnit.of("XXX"); - assertEquals("XXX", test.getSymbol()); + assertThat(test.getSymbol()).isEqualTo("XXX"); } finally { Locale.setDefault(loc); } @@ -724,7 +639,7 @@ void test_getSymbol_Locale_GBP_UK() { try { Locale.setDefault(Locale.UK); CurrencyUnit test = CurrencyUnit.of("GBP"); - assertEquals("\u00A3", test.getSymbol(Locale.UK)); + assertThat(test.getSymbol(Locale.UK)).isEqualTo("\u00A3"); } finally { Locale.setDefault(loc); } @@ -736,7 +651,7 @@ void test_getSymbol_Locale_GBP_France() { try { Locale.setDefault(Locale.UK); CurrencyUnit test = CurrencyUnit.of("GBP"); - assertTrue(test.getSymbol(Locale.FRANCE).contains("GB")); + assertThat(test.getSymbol(Locale.FRANCE)).contains("GB"); } finally { Locale.setDefault(loc); } @@ -748,7 +663,7 @@ void test_getSymbol_Locale_USD_UK() { try { Locale.setDefault(Locale.UK); CurrencyUnit test = CurrencyUnit.of("USD"); - assertEquals("$", test.getSymbol(Locale.US)); + assertThat(test.getSymbol(Locale.US)).isEqualTo("$"); } finally { Locale.setDefault(loc); } @@ -760,7 +675,7 @@ void test_getSymbol_Locale_USD_France() { try { Locale.setDefault(Locale.UK); CurrencyUnit test = CurrencyUnit.of("USD"); - assertTrue(test.getSymbol(Locale.FRANCE).contains("US")); + assertThat(test.getSymbol(Locale.FRANCE)).contains("US"); } finally { Locale.setDefault(loc); } @@ -772,7 +687,7 @@ void test_getSymbol_Locale_JPY_Japan() { try { Locale.setDefault(Locale.UK); CurrencyUnit test = CurrencyUnit.of("JPY"); - assertEquals("\uFFE5", test.getSymbol(Locale.JAPAN)); + assertThat(test.getSymbol(Locale.JAPAN)).isEqualTo("\uFFE5"); } finally { Locale.setDefault(loc); } @@ -784,7 +699,7 @@ void test_getSymbol_TMT_UK() { try { Locale.setDefault(Locale.UK); CurrencyUnit test = CurrencyUnit.of("TMT"); - assertEquals("TMT", test.getSymbol(Locale.UK)); + assertThat(test.getSymbol(Locale.UK)).isEqualTo("TMT"); } finally { Locale.setDefault(loc); } @@ -796,7 +711,7 @@ void test_getSymbol_Locale_XXX() { try { Locale.setDefault(Locale.UK); CurrencyUnit test = CurrencyUnit.of("XXX"); - assertEquals("XXX", test.getSymbol(Locale.FRANCE)); + assertThat(test.getSymbol(Locale.FRANCE)).isEqualTo("XXX"); } finally { Locale.setDefault(loc); } @@ -808,7 +723,7 @@ void test_getSymbol_Locale_XXX() { @Test void test_toCurrency() { CurrencyUnit test = CurrencyUnit.of("GBP"); - assertEquals(JDK_GBP, test.toCurrency()); + assertThat(test.toCurrency()).isEqualTo(JDK_GBP); } //----------------------------------------------------------------------- @@ -819,25 +734,24 @@ void test_compareTo() { CurrencyUnit a = CurrencyUnit.of("EUR"); CurrencyUnit b = CurrencyUnit.of("GBP"); CurrencyUnit c = CurrencyUnit.of("JPY"); - assertEquals(0, a.compareTo(a)); - assertEquals(0, b.compareTo(b)); - assertEquals(0, c.compareTo(c)); + assertThat(a.compareTo(a)).isEqualTo(0); + assertThat(b.compareTo(b)).isEqualTo(0); + assertThat(c.compareTo(c)).isEqualTo(0); - assertTrue(a.compareTo(b) < 0); - assertTrue(b.compareTo(a) > 0); + assertThat(a.compareTo(b) < 0).isTrue(); + assertThat(b.compareTo(a) > 0).isTrue(); - assertTrue(a.compareTo(c) < 0); - assertTrue(c.compareTo(a) > 0); + assertThat(a.compareTo(c) < 0).isTrue(); + assertThat(c.compareTo(a) > 0).isTrue(); - assertTrue(b.compareTo(c) < 0); - assertTrue(c.compareTo(b) > 0); + assertThat(b.compareTo(c) < 0).isTrue(); + assertThat(c.compareTo(b) > 0).isTrue(); } @Test void test_compareTo_null() { - assertThrows(NullPointerException.class, () -> { - CurrencyUnit.of("EUR").compareTo(null); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> CurrencyUnit.of("EUR").compareTo(null)); } //----------------------------------------------------------------------- @@ -848,25 +762,25 @@ void test_equals_hashCode() { CurrencyUnit a = CurrencyUnit.of("GBP"); CurrencyUnit b = CurrencyUnit.of("GBP"); CurrencyUnit c = CurrencyUnit.of("EUR"); - assertTrue(a.equals(a)); - assertTrue(b.equals(b)); - assertTrue(c.equals(c)); + assertThat(a).isEqualTo(a); + assertThat(b).isEqualTo(b); + assertThat(c).isEqualTo(c); - assertTrue(a.equals(b)); - assertTrue(b.equals(a)); - assertTrue(a.hashCode() == b.hashCode()); + assertThat(b).isEqualTo(a); + assertThat(a).isEqualTo(b); + assertThat(b.hashCode()).isEqualTo(a.hashCode()); - assertFalse(a.equals(c)); - assertFalse(b.equals(c)); + assertThat(c).isNotEqualTo(a); + assertThat(c).isNotEqualTo(b); } @Test void test_equals_false() { CurrencyUnit a = CurrencyUnit.of("GBP"); - assertFalse(a.equals(null)); + assertThat(a).isNotEqualTo(null); Object obj = "String"; // avoid warning in Eclipse - assertFalse(a.equals(obj)); - assertFalse(a.equals(new Object())); + assertThat(obj).isNotEqualTo(a); + assertThat(new Object()).isNotEqualTo(a); } //----------------------------------------------------------------------- @@ -875,7 +789,7 @@ void test_equals_false() { @Test void test_toString() { CurrencyUnit test = CurrencyUnit.of("GBP"); - assertEquals("GBP", test.toString()); + assertThat(test).hasToString("GBP"); } } diff --git a/src/test/java/org/joda/money/TestCurrencyUnitExtension.java b/src/test/java/org/joda/money/TestCurrencyUnitExtension.java index 5109545..35e9526 100644 --- a/src/test/java/org/joda/money/TestCurrencyUnitExtension.java +++ b/src/test/java/org/joda/money/TestCurrencyUnitExtension.java @@ -15,9 +15,8 @@ */ package org.joda.money; -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 static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; import java.util.List; @@ -38,7 +37,7 @@ void test_CurrencyFromMoneyData() { break; } } - assertTrue(found); + assertThat(found).isTrue(); } @Test @@ -51,7 +50,7 @@ void test_CurrencyFromMoneyDataExtension() { break; } } - assertTrue(found); + assertThat(found).isTrue(); } @Test @@ -61,11 +60,11 @@ void test_LargerDecimalPrecisionCurrencyFromMoneyDataExtension() { for (CurrencyUnit currencyUnit : curList) { if (currencyUnit.getCode().equals("ETH")) { found = true; - assertEquals("ETH 1.234567890000000000000000000000", Money.of(currencyUnit, 1.23456789d).toString()); + assertThat(Money.of(currencyUnit, 1.23456789d).toString()).isEqualTo("ETH 1.234567890000000000000000000000"); break; } } - assertTrue(found); + assertThat(found).isTrue(); } @Test @@ -89,9 +88,9 @@ void test_CurrencyMissing() { @Test void test_CurrencyEURChanged() { CurrencyUnit currency = CurrencyUnit.ofCountry("HU"); - assertEquals(CurrencyUnit.EUR, currency); - assertTrue(CurrencyUnit.EUR.getCountryCodes().contains("HU")); - assertTrue(CurrencyUnit.of("HUF").getCountryCodes().isEmpty()); + assertThat(currency).isEqualTo(CurrencyUnit.EUR); + assertThat(CurrencyUnit.EUR.getCountryCodes()).contains("HU"); + assertThat(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 3771528..45b31a7 100644 --- a/src/test/java/org/joda/money/TestIllegalCurrencyException.java +++ b/src/test/java/org/joda/money/TestIllegalCurrencyException.java @@ -15,8 +15,7 @@ */ package org.joda.money; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; +import static org.assertj.core.api.Assertions.assertThat; import org.junit.jupiter.api.Test; @@ -31,15 +30,15 @@ class TestIllegalCurrencyException { @Test void test_String() { IllegalCurrencyException test = new IllegalCurrencyException("PROBLEM"); - assertEquals("PROBLEM", test.getMessage()); - assertNull(test.getCause()); + assertThat(test.getMessage()).isEqualTo("PROBLEM"); + assertThat(test.getCause()).isNull(); } @Test void test_String_nullString() { IllegalCurrencyException test = new IllegalCurrencyException(null); - assertNull(test.getMessage()); - assertNull(test.getCause()); + assertThat(test.getMessage()).isNull(); + assertThat(test.getCause()).isNull(); } } diff --git a/src/test/java/org/joda/money/TestMoney.java b/src/test/java/org/joda/money/TestMoney.java index 38ea19f..ef1e500 100644 --- a/src/test/java/org/joda/money/TestMoney.java +++ b/src/test/java/org/joda/money/TestMoney.java @@ -15,12 +15,10 @@ */ package org.joda.money; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType; 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; @@ -87,45 +85,41 @@ class TestMoney { @Test void test_factory_of_Currency_BigDecimal() { Money test = Money.of(GBP, BIGDEC_2_34); - assertEquals(GBP, test.getCurrencyUnit()); - assertEquals(234, test.getAmountMinorInt()); - assertEquals(2, test.getAmount().scale()); + assertThat(test.getCurrencyUnit()).isEqualTo(GBP); + assertThat(test.getAmountMinorInt()).isEqualTo(234); + assertThat(test.getAmount().scale()).isEqualTo(2); } @Test 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()); + assertThat(test.getCurrencyUnit()).isEqualTo(GBP); + assertThat(test.getAmountMinorInt()).isEqualTo(230); + assertThat(test.getAmount().scale()).isEqualTo(2); } @Test void test_factory_of_Currency_BigDecimal_invalidScaleGBP() { - assertThrows(ArithmeticException.class, () -> { - Money.of(GBP, BIGDEC_2_345); - }); + assertThatExceptionOfType(ArithmeticException.class) + .isThrownBy(() -> Money.of(GBP, BIGDEC_2_345)); } @Test void test_factory_of_Currency_BigDecimal_invalidScaleJPY() { - assertThrows(ArithmeticException.class, () -> { - Money.of(JPY, BIGDEC_2_3); - }); + assertThatExceptionOfType(ArithmeticException.class) + .isThrownBy(() -> Money.of(JPY, BIGDEC_2_3)); } @Test void test_factory_of_Currency_BigDecimal_nullCurrency() { - assertThrows(NullPointerException.class, () -> { - Money.of((CurrencyUnit) null, BIGDEC_2_34); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> Money.of((CurrencyUnit) null, BIGDEC_2_34)); } @Test void test_factory_of_Currency_BigDecimal_nullBigDecimal() { - assertThrows(NullPointerException.class, () -> { - Money.of(GBP, (BigDecimal) null); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> Money.of(GBP, (BigDecimal) null)); } //----------------------------------------------------------------------- @@ -134,53 +128,49 @@ void test_factory_of_Currency_BigDecimal_nullBigDecimal() { @Test 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()); - assertEquals(2, test.getAmount().scale()); + assertThat(test.getCurrencyUnit()).isEqualTo(GBP); + assertThat(test.getAmountMinorInt()).isEqualTo(234); + assertThat(test.getAmount().scale()).isEqualTo(2); } @Test 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()); - assertEquals(0, test.getAmount().scale()); + assertThat(test.getCurrencyUnit()).isEqualTo(JPY); + assertThat(test.getAmountMinorInt()).isEqualTo(2); + assertThat(test.getAmount().scale()).isEqualTo(0); } @Test 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()); + assertThat(test.getCurrencyUnit()).isEqualTo(JPY); + assertThat(test.getAmountMinorInt()).isEqualTo(3); + assertThat(test.getAmount().scale()).isEqualTo(0); } @Test void test_factory_of_Currency_BigDecimal_RoundingMode_UNNECESSARY() { - assertThrows(ArithmeticException.class, () -> { - Money.of(JPY, BIGDEC_2_34, RoundingMode.UNNECESSARY); - }); + assertThatExceptionOfType(ArithmeticException.class) + .isThrownBy(() -> Money.of(JPY, BIGDEC_2_34, RoundingMode.UNNECESSARY)); } @Test void test_factory_of_Currency_BigDecimal_RoundingMode_nullCurrency() { - assertThrows(NullPointerException.class, () -> { - Money.of((CurrencyUnit) null, BIGDEC_2_34, RoundingMode.DOWN); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> Money.of((CurrencyUnit) null, BIGDEC_2_34, RoundingMode.DOWN)); } @Test void test_factory_of_Currency_BigDecimal_RoundingMode_nullBigDecimal() { - assertThrows(NullPointerException.class, () -> { - Money.of(GBP, (BigDecimal) null, RoundingMode.DOWN); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> Money.of(GBP, (BigDecimal) null, RoundingMode.DOWN)); } @Test void test_factory_of_Currency_BigDecimal_RoundingMode_nullRoundingMode() { - assertThrows(NullPointerException.class, () -> { - Money.of(GBP, BIGDEC_2_34, (RoundingMode) null); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> Money.of(GBP, BIGDEC_2_34, (RoundingMode) null)); } //----------------------------------------------------------------------- @@ -189,70 +179,67 @@ void test_factory_of_Currency_BigDecimal_RoundingMode_nullRoundingMode() { @Test void test_factory_of_Currency_double() { Money test = Money.of(GBP, 2.34d); - assertEquals(GBP, test.getCurrencyUnit()); - assertEquals(234, test.getAmountMinorInt()); - assertEquals(2, test.getScale()); + assertThat(test.getCurrencyUnit()).isEqualTo(GBP); + assertThat(test.getAmountMinorInt()).isEqualTo(234); + assertThat(test.getScale()).isEqualTo(2); } @Test void test_factory_of_Currency_double_correctScale() { Money test = Money.of(GBP, 2.3d); - assertEquals(GBP, test.getCurrencyUnit()); - assertEquals(230, test.getAmountMinorInt()); - assertEquals(2, test.getScale()); + assertThat(test.getCurrencyUnit()).isEqualTo(GBP); + assertThat(test.getAmountMinorInt()).isEqualTo(230); + assertThat(test.getScale()).isEqualTo(2); } @Test 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()); - assertEquals(2, test.getScale()); + assertThat(test.getCurrencyUnit()).isEqualTo(GBP); + assertThat(test.getAmount()).isEqualTo(BigDecimal.valueOf(123L, 2)); + assertThat(test.getScale()).isEqualTo(2); } @Test 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()); - assertEquals(2, test.getScale()); + assertThat(test.getCurrencyUnit()).isEqualTo(GBP); + assertThat(test.getAmount()).isEqualTo(BigDecimal.valueOf(120L, 2)); + assertThat(test.getScale()).isEqualTo(2); } @Test void test_factory_of_Currency_double_medium() { Money test = Money.of(GBP, 2000d); - assertEquals(GBP, test.getCurrencyUnit()); - assertEquals(BigDecimal.valueOf(200000L, 2), test.getAmount()); - assertEquals(2, test.getScale()); + assertThat(test.getCurrencyUnit()).isEqualTo(GBP); + assertThat(test.getAmount()).isEqualTo(BigDecimal.valueOf(200000L, 2)); + assertThat(test.getScale()).isEqualTo(2); } @Test 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()); + assertThat(test.getCurrencyUnit()).isEqualTo(GBP); + assertThat(test.getAmount()).isEqualTo(BigDecimal.valueOf(20000000000L, 2)); + assertThat(test.getScale()).isEqualTo(2); } @Test void test_factory_of_Currency_double_invalidScaleGBP() { - assertThrows(ArithmeticException.class, () -> { - Money.of(GBP, 2.345d); - }); + assertThatExceptionOfType(ArithmeticException.class) + .isThrownBy(() -> Money.of(GBP, 2.345d)); } @Test void test_factory_of_Currency_double_invalidScaleJPY() { - assertThrows(ArithmeticException.class, () -> { - Money.of(JPY, 2.3d); - }); + assertThatExceptionOfType(ArithmeticException.class) + .isThrownBy(() -> Money.of(JPY, 2.3d)); } @Test void test_factory_of_Currency_double_nullCurrency() { - assertThrows(NullPointerException.class, () -> { - Money.of((CurrencyUnit) null, BIGDEC_2_34); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> Money.of((CurrencyUnit) null, BIGDEC_2_34)); } //----------------------------------------------------------------------- @@ -261,46 +248,43 @@ void test_factory_of_Currency_double_nullCurrency() { @Test 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()); - assertEquals(2, test.getAmount().scale()); + assertThat(test.getCurrencyUnit()).isEqualTo(GBP); + assertThat(test.getAmountMinorInt()).isEqualTo(234); + assertThat(test.getAmount().scale()).isEqualTo(2); } @Test 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()); - assertEquals(0, test.getAmount().scale()); + assertThat(test.getCurrencyUnit()).isEqualTo(JPY); + assertThat(test.getAmountMinorInt()).isEqualTo(2); + assertThat(test.getAmount().scale()).isEqualTo(0); } @Test 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()); + assertThat(test.getCurrencyUnit()).isEqualTo(JPY); + assertThat(test.getAmountMinorInt()).isEqualTo(3); + assertThat(test.getAmount().scale()).isEqualTo(0); } @Test void test_factory_of_Currency_double_RoundingMode_UNNECESSARY() { - assertThrows(ArithmeticException.class, () -> { - Money.of(JPY, 2.34d, RoundingMode.UNNECESSARY); - }); + assertThatExceptionOfType(ArithmeticException.class) + .isThrownBy(() -> Money.of(JPY, 2.34d, RoundingMode.UNNECESSARY)); } @Test void test_factory_of_Currency_double_RoundingMode_nullCurrency() { - assertThrows(NullPointerException.class, () -> { - Money.of((CurrencyUnit) null, 2.34d, RoundingMode.DOWN); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> Money.of((CurrencyUnit) null, 2.34d, RoundingMode.DOWN)); } @Test void test_factory_of_Currency_double_RoundingMode_nullRoundingMode() { - assertThrows(NullPointerException.class, () -> { - Money.of(GBP, 2.34d, (RoundingMode) null); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> Money.of(GBP, 2.34d, (RoundingMode) null)); } //----------------------------------------------------------------------- @@ -309,16 +293,15 @@ void test_factory_of_Currency_double_RoundingMode_nullRoundingMode() { @Test 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()); + assertThat(test.getCurrencyUnit()).isEqualTo(GBP); + assertThat(test.getAmountMinorInt()).isEqualTo(23400); + assertThat(test.getAmount().scale()).isEqualTo(2); } @Test void test_factory_ofMajor_Currency_long_nullCurrency() { - assertThrows(NullPointerException.class, () -> { - Money.ofMajor((CurrencyUnit) null, 234); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> Money.ofMajor((CurrencyUnit) null, 234)); } //----------------------------------------------------------------------- @@ -327,16 +310,15 @@ void test_factory_ofMajor_Currency_long_nullCurrency() { @Test 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()); + assertThat(test.getCurrencyUnit()).isEqualTo(GBP); + assertThat(test.getAmountMinorInt()).isEqualTo(234); + assertThat(test.getAmount().scale()).isEqualTo(2); } @Test void test_factory_ofMinor_Currency_long_nullCurrency() { - assertThrows(NullPointerException.class, () -> { - Money.ofMinor((CurrencyUnit) null, 234); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> Money.ofMinor((CurrencyUnit) null, 234)); } //----------------------------------------------------------------------- @@ -345,16 +327,15 @@ void test_factory_ofMinor_Currency_long_nullCurrency() { @Test void test_factory_zero_Currency() { Money test = Money.zero(GBP); - assertEquals(GBP, test.getCurrencyUnit()); - assertEquals(0, test.getAmountMinorInt()); - assertEquals(2, test.getAmount().scale()); + assertThat(test.getCurrencyUnit()).isEqualTo(GBP); + assertThat(test.getAmountMinorInt()).isEqualTo(0); + assertThat(test.getAmount().scale()).isEqualTo(2); } @Test void test_factory_zero_Currency_nullCurrency() { - assertThrows(NullPointerException.class, () -> { - Money.zero((CurrencyUnit) null); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> Money.zero((CurrencyUnit) null)); } //----------------------------------------------------------------------- @@ -363,31 +344,29 @@ void test_factory_zero_Currency_nullCurrency() { @Test void test_factory_from_BigMoneyProvider() { Money test = Money.of(BigMoney.parse("GBP 104.23")); - assertEquals(GBP, test.getCurrencyUnit()); - assertEquals(10423, test.getAmountMinorInt()); - assertEquals(2, test.getAmount().scale()); + assertThat(test.getCurrencyUnit()).isEqualTo(GBP); + assertThat(test.getAmountMinorInt()).isEqualTo(10423); + assertThat(test.getAmount().scale()).isEqualTo(2); } @Test 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()); + assertThat(test.getCurrencyUnit()).isEqualTo(GBP); + assertThat(test.getAmountMinorInt()).isEqualTo(10420); + assertThat(test.getAmount().scale()).isEqualTo(2); } @Test void test_factory_from_BigMoneyProvider_invalidCurrencyScale() { - assertThrows(ArithmeticException.class, () -> { - Money.of(BigMoney.parse("GBP 104.235")); - }); + assertThatExceptionOfType(ArithmeticException.class) + .isThrownBy(() -> Money.of(BigMoney.parse("GBP 104.235"))); } @Test void test_factory_from_BigMoneyProvider_nullBigMoneyProvider() { - assertThrows(NullPointerException.class, () -> { - Money.of((BigMoneyProvider) null); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> Money.of((BigMoneyProvider) null)); } //----------------------------------------------------------------------- @@ -396,23 +375,21 @@ void test_factory_from_BigMoneyProvider_nullBigMoneyProvider() { @Test 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()); + assertThat(test.getCurrencyUnit()).isEqualTo(GBP); + assertThat(test.getAmountMinorInt()).isEqualTo(10424); + assertThat(test.getAmount().scale()).isEqualTo(2); } @Test void test_factory_from_BigMoneyProvider_RoundingMode_nullBigMoneyProvider() { - assertThrows(NullPointerException.class, () -> { - Money.of((BigMoneyProvider) null, RoundingMode.DOWN); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> Money.of((BigMoneyProvider) null, RoundingMode.DOWN)); } @Test void test_factory_from_BigMoneyProvider_RoundingMode_nullRoundingMode() { - assertThrows(NullPointerException.class, () -> { - Money.of(BigMoney.parse("GBP 104.235"), (RoundingMode) null); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> Money.of(BigMoney.parse("GBP 104.235"), (RoundingMode) null)); } //----------------------------------------------------------------------- @@ -421,103 +398,99 @@ void test_factory_from_BigMoneyProvider_RoundingMode_nullRoundingMode() { @Test void test_factory_total_varargs_1() { Money test = Money.total(GBP_1_23); - assertEquals(GBP, test.getCurrencyUnit()); - assertEquals(123, test.getAmountMinorInt()); + assertThat(test.getCurrencyUnit()).isEqualTo(GBP); + assertThat(test.getAmountMinorInt()).isEqualTo(123); } @Test void test_factory_total_array_1() { Money[] array = new Money[] {GBP_1_23}; Money test = Money.total(array); - assertEquals(GBP, test.getCurrencyUnit()); - assertEquals(123, test.getAmountMinorInt()); + assertThat(test.getCurrencyUnit()).isEqualTo(GBP); + assertThat(test.getAmountMinorInt()).isEqualTo(123); } @Test 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()); + assertThat(test.getCurrencyUnit()).isEqualTo(GBP); + assertThat(test.getAmountMinorInt()).isEqualTo(592); } @Test 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()); + assertThat(test.getCurrencyUnit()).isEqualTo(GBP); + assertThat(test.getAmountMinorInt()).isEqualTo(592); } @Test void test_factory_total_varargs_empty() { - assertThrows(IllegalArgumentException.class, () -> { - Money.total(); - }); + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> Money.total()); } @Test void test_factory_total_array_empty() { - assertThrows(IllegalArgumentException.class, () -> { - Money[] array = new Money[0]; - Money.total(array); - }); + Money[] array = new Money[0]; + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> Money.total(array)); } @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; - } - }); + assertThatExceptionOfType(CurrencyMismatchException.class) + .isThrownBy(() -> { + 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_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; - } - }); + assertThatExceptionOfType(CurrencyMismatchException.class) + .isThrownBy(() -> { + 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_varargs_nullFirst() { - assertThrows(NullPointerException.class, () -> { - Money.total((Money) null, GBP_2_33, GBP_2_36); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> Money.total((Money) null, GBP_2_33, GBP_2_36)); } @Test void test_factory_total_array_nullFirst() { Money[] array = new Money[] {null, GBP_2_33, GBP_2_36}; - assertThrows(NullPointerException.class, () -> { - Money.total(array); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> Money.total(array)); } @Test void test_factory_total_varargs_nullNotFirst() { - assertThrows(NullPointerException.class, () -> { - Money.total(GBP_2_33, null, GBP_2_36); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> Money.total(GBP_2_33, null, GBP_2_36)); } @Test void test_factory_total_array_nullNotFirst() { Money[] array = new Money[] {GBP_2_33, null, GBP_2_36}; - assertThrows(NullPointerException.class, () -> { - Money.total(array); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> Money.total(array)); } //----------------------------------------------------------------------- @@ -527,46 +500,44 @@ void test_factory_total_array_nullNotFirst() { 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()); + assertThat(test.getCurrencyUnit()).isEqualTo(GBP); + assertThat(test.getAmountMinorInt()).isEqualTo(592); } @Test void test_factory_total_Iterable_empty() { Iterable iterable = Collections.emptyList(); - assertThrows(IllegalArgumentException.class, () -> { - Money.total(iterable); - }); + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> Money.total(iterable)); } @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; - } - }); + assertThatExceptionOfType(CurrencyMismatchException.class) + .isThrownBy(() -> { + 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_nullFirst() { Iterable iterable = Arrays.asList(null, GBP_2_33, GBP_2_36); - assertThrows(NullPointerException.class, () -> { - Money.total(iterable); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> Money.total(iterable)); } @Test void test_factory_total_Iterable_nullNotFirst() { Iterable iterable = Arrays.asList(GBP_2_33, null, GBP_2_36); - assertThrows(NullPointerException.class, () -> { - Money.total(iterable); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> Money.total(iterable)); } //----------------------------------------------------------------------- @@ -575,130 +546,130 @@ void test_factory_total_Iterable_nullNotFirst() { @Test void test_factory_total_CurrencyUnitVarargs_1() { Money test = Money.total(GBP, GBP_1_23); - assertEquals(GBP, test.getCurrencyUnit()); - assertEquals(123, test.getAmountMinorInt()); + assertThat(test.getCurrencyUnit()).isEqualTo(GBP); + assertThat(test.getAmountMinorInt()).isEqualTo(123); } @Test void test_factory_total_CurrencyUnitArray_1() { Money[] array = new Money[] {GBP_1_23}; Money test = Money.total(GBP, array); - assertEquals(GBP, test.getCurrencyUnit()); - assertEquals(123, test.getAmountMinorInt()); + assertThat(test.getCurrencyUnit()).isEqualTo(GBP); + assertThat(test.getAmountMinorInt()).isEqualTo(123); } @Test 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()); + assertThat(test.getCurrencyUnit()).isEqualTo(GBP); + assertThat(test.getAmountMinorInt()).isEqualTo(592); } @Test 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()); - assertEquals(592, test.getAmountMinorInt()); + assertThat(test.getCurrencyUnit()).isEqualTo(GBP); + assertThat(test.getAmountMinorInt()).isEqualTo(592); } @Test void test_factory_total_CurrencyUnitVarargs_empty() { Money test = Money.total(GBP); - assertEquals(GBP, test.getCurrencyUnit()); - assertEquals(0, test.getAmountMinorInt()); + assertThat(test.getCurrencyUnit()).isEqualTo(GBP); + assertThat(test.getAmountMinorInt()).isEqualTo(0); } @Test 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()); + assertThat(test.getCurrencyUnit()).isEqualTo(GBP); + assertThat(test.getAmountMinorInt()).isEqualTo(0); } @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; - } - }); + assertThatExceptionOfType(CurrencyMismatchException.class) + .isThrownBy(() -> { + try { + Money.total(GBP, JPY_423); + } 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; - } - }); + Money[] array = new Money[] {JPY_423}; + assertThatExceptionOfType(CurrencyMismatchException.class) + .isThrownBy(() -> { + try { + Money.total(GBP, array); + } 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; - } - }); + assertThatExceptionOfType(CurrencyMismatchException.class) + .isThrownBy(() -> { + 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_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; - } - }); + Money[] array = new Money[] {GBP_2_33, JPY_423}; + assertThatExceptionOfType(CurrencyMismatchException.class) + .isThrownBy(() -> { + try { + Money.total(GBP, array); + } catch (CurrencyMismatchException ex) { + assertEquals(GBP, ex.getFirstCurrency()); + assertEquals(JPY, ex.getSecondCurrency()); + throw ex; + } + }); } @Test void test_factory_total_CurrencyUnitVarargs_nullFirst() { - assertThrows(NullPointerException.class, () -> { - Money.total(GBP, null, GBP_2_33, GBP_2_36); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> Money.total(GBP, null, GBP_2_33, GBP_2_36)); } @Test void test_factory_total_CurrencyUnitArray_nullFirst() { Money[] array = new Money[] {null, GBP_2_33, GBP_2_36}; - assertThrows(NullPointerException.class, () -> { - Money.total(GBP, array); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> Money.total(GBP, array)); } @Test void test_factory_total_CurrencyUnitVarargs_nullNotFirst() { - assertThrows(NullPointerException.class, () -> { - Money.total(GBP, GBP_2_33, null, GBP_2_36); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> Money.total(GBP, GBP_2_33, null, GBP_2_36)); } @Test void test_factory_total_CurrencyUnitArray_nullNotFirst() { Money[] array = new Money[] {GBP_2_33, null, GBP_2_36}; - assertThrows(NullPointerException.class, () -> { - Money.total(GBP, array); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> Money.total(GBP, array)); } //----------------------------------------------------------------------- @@ -708,60 +679,60 @@ void test_factory_total_CurrencyUnitArray_nullNotFirst() { 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()); - assertEquals(592, test.getAmountMinorInt()); + assertThat(test.getCurrencyUnit()).isEqualTo(GBP); + assertThat(test.getAmountMinorInt()).isEqualTo(592); } @Test void test_factory_total_CurrencyUnitIterable_empty() { Iterable iterable = Collections.emptyList(); Money test = Money.total(GBP, iterable); - assertEquals(GBP, test.getCurrencyUnit()); - assertEquals(0, test.getAmountMinorInt()); + assertThat(test.getCurrencyUnit()).isEqualTo(GBP); + assertThat(test.getAmountMinorInt()).isEqualTo(0); } @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; - } - }); + Iterable iterable = Arrays.asList(JPY_423); + assertThatExceptionOfType(CurrencyMismatchException.class) + .isThrownBy(() -> { + try { + 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; - } - }); + Iterable iterable = Arrays.asList(GBP_2_33, JPY_423); + assertThatExceptionOfType(CurrencyMismatchException.class) + .isThrownBy(() -> { + try { + Money.total(GBP, iterable); + } catch (CurrencyMismatchException ex) { + assertEquals(GBP, ex.getFirstCurrency()); + assertEquals(JPY, ex.getSecondCurrency()); + throw ex; + } + }); } @Test void test_factory_total_CurrencyUnitIterable_nullFirst() { Iterable iterable = Arrays.asList(null, GBP_2_33, GBP_2_36); - assertThrows(NullPointerException.class, () -> { - Money.total(GBP, iterable); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> Money.total(GBP, iterable)); } @Test void test_factory_total_CurrencyUnitIterable_nullNotFirst() { Iterable iterable = Arrays.asList(GBP_2_33, null, GBP_2_36); - assertThrows(NullPointerException.class, () -> { - Money.total(GBP, iterable); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> Money.total(GBP, iterable)); } //----------------------------------------------------------------------- @@ -793,29 +764,26 @@ public static Object[][] data_parse() { @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()); + assertThat(test.getCurrencyUnit()).isEqualTo(currency); + assertThat(test.getAmountMinorInt()).isEqualTo(amount); } @Test void test_factory_parse_String_tooShort() { - assertThrows(IllegalArgumentException.class, () -> { - Money.parse("GBP "); - }); + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> Money.parse("GBP ")); } @Test void test_factory_parse_String_badCurrency() { - assertThrows(IllegalArgumentException.class, () -> { - Money.parse("GBX 2.34"); - }); + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> Money.parse("GBX 2.34")); } @Test void test_factory_parse_String_nullString() { - assertThrows(NullPointerException.class, () -> { - Money.parse((String) null); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> Money.parse((String) null)); } //----------------------------------------------------------------------- @@ -824,14 +792,14 @@ void test_factory_parse_String_nullString() { @Test void test_constructor_null1() throws Exception { Constructor con = Money.class.getDeclaredConstructor(BigMoney.class); - assertFalse(Modifier.isPublic(con.getModifiers())); - assertFalse(Modifier.isProtected(con.getModifiers())); + assertThat(Modifier.isPublic(con.getModifiers())).isFalse(); + assertThat(Modifier.isProtected(con.getModifiers())).isFalse(); try { con.setAccessible(true); con.newInstance(new Object[] {null}); - fail(); + fail(""); } catch (InvocationTargetException ex) { - assertEquals(AssertionError.class, ex.getCause().getClass()); + assertThat(ex.getCause().getClass()).isEqualTo(AssertionError.class); } } @@ -841,9 +809,9 @@ void test_constructor_scale() throws Exception { try { con.setAccessible(true); con.newInstance(new Object[] {BigMoney.of(GBP, BIGDEC_2_3)}); - fail(); + fail(""); } catch (InvocationTargetException ex) { - assertEquals(AssertionError.class, ex.getCause().getClass()); + assertThat(ex.getCause().getClass()).isEqualTo(AssertionError.class); } } @@ -859,7 +827,7 @@ void test_serialization() throws Exception { oos.close(); ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); Money input = (Money) ois.readObject(); - assertEquals(a, input); + assertThat(input).isEqualTo(a); } } @@ -872,9 +840,8 @@ void test_serialization_invalidNumericCode() throws IOException { oos.writeObject(m); oos.close(); ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); - assertThrows(InvalidObjectException.class, () -> { - ois.readObject(); - }); + assertThatExceptionOfType(InvalidObjectException.class) + .isThrownBy(() -> ois.readObject()); } } @@ -887,9 +854,8 @@ void test_serialization_invalidDecimalPlaces() throws IOException { oos.writeObject(m); oos.close(); ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); - assertThrows(InvalidObjectException.class, () -> { - ois.readObject(); - }); + assertThatExceptionOfType(InvalidObjectException.class) + .isThrownBy(() -> ois.readObject()); } } @@ -898,12 +864,12 @@ void test_serialization_invalidDecimalPlaces() throws IOException { //----------------------------------------------------------------------- @Test void test_getCurrencyUnit_GBP() { - assertEquals(GBP, GBP_2_34.getCurrencyUnit()); + assertThat(GBP_2_34.getCurrencyUnit()).isEqualTo(GBP); } @Test void test_getCurrencyUnit_EUR() { - assertEquals(EUR, Money.parse("EUR -5.78").getCurrencyUnit()); + assertThat(Money.parse("EUR -5.78").getCurrencyUnit()).isEqualTo(EUR); } //----------------------------------------------------------------------- @@ -912,27 +878,25 @@ void test_getCurrencyUnit_EUR() { @Test void test_withCurrencyUnit_Currency() { Money test = GBP_2_34.withCurrencyUnit(USD); - assertEquals("USD 2.34", test.toString()); + assertThat(test).hasToString("USD 2.34"); } @Test void test_withCurrencyUnit_Currency_same() { Money test = GBP_2_34.withCurrencyUnit(GBP); - assertSame(GBP_2_34, test); + assertThat(test).isSameAs(GBP_2_34); } @Test void test_withCurrencyUnit_Currency_scaleProblem() { - assertThrows(ArithmeticException.class, () -> { - GBP_2_34.withCurrencyUnit(JPY); - }); + assertThatExceptionOfType(ArithmeticException.class) + .isThrownBy(() -> GBP_2_34.withCurrencyUnit(JPY)); } @Test void test_withCurrencyUnit_Currency_nullCurrency() { - assertThrows(NullPointerException.class, () -> { - GBP_2_34.withCurrencyUnit((CurrencyUnit) null); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> GBP_2_34.withCurrencyUnit((CurrencyUnit) null)); } //----------------------------------------------------------------------- @@ -941,33 +905,31 @@ void test_withCurrencyUnit_Currency_nullCurrency() { @Test void test_withCurrencyUnit_CurrencyRoundingMode_DOWN() { Money test = GBP_2_34.withCurrencyUnit(JPY, RoundingMode.DOWN); - assertEquals("JPY 2", test.toString()); + assertThat(test).hasToString("JPY 2"); } @Test void test_withCurrencyUnit_CurrencyRoundingMode_UP() { Money test = GBP_2_34.withCurrencyUnit(JPY, RoundingMode.UP); - assertEquals("JPY 3", test.toString()); + assertThat(test).hasToString("JPY 3"); } @Test void test_withCurrencyUnit_CurrencyRoundingMode_same() { Money test = GBP_2_34.withCurrencyUnit(GBP, RoundingMode.DOWN); - assertSame(GBP_2_34, test); + assertThat(test).isSameAs(GBP_2_34); } @Test void test_withCurrencyUnit_CurrencyRoundingMode_UNECESSARY() { - assertThrows(ArithmeticException.class, () -> { - GBP_2_34.withCurrencyUnit(JPY, RoundingMode.UNNECESSARY); - }); + assertThatExceptionOfType(ArithmeticException.class) + .isThrownBy(() -> GBP_2_34.withCurrencyUnit(JPY, RoundingMode.UNNECESSARY)); } @Test void test_withCurrencyUnit_CurrencyRoundingMode_nullCurrency() { - assertThrows(NullPointerException.class, () -> { - GBP_2_34.withCurrencyUnit((CurrencyUnit) null, RoundingMode.UNNECESSARY); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> GBP_2_34.withCurrencyUnit((CurrencyUnit) null, RoundingMode.UNNECESSARY)); } //----------------------------------------------------------------------- @@ -975,12 +937,12 @@ void test_withCurrencyUnit_CurrencyRoundingMode_nullCurrency() { //----------------------------------------------------------------------- @Test void test_getScale_GBP() { - assertEquals(2, GBP_2_34.getScale()); + assertThat(GBP_2_34.getScale()).isEqualTo(2); } @Test void test_getScale_JPY() { - assertEquals(0, JPY_423.getScale()); + assertThat(JPY_423.getScale()).isEqualTo(0); } //----------------------------------------------------------------------- @@ -988,12 +950,12 @@ void test_getScale_JPY() { //----------------------------------------------------------------------- @Test void test_getAmount_positive() { - assertEquals(BIGDEC_2_34, GBP_2_34.getAmount()); + assertThat(GBP_2_34.getAmount()).isEqualTo(BIGDEC_2_34); } @Test void test_getAmount_negative() { - assertEquals(BIGDEC_M5_78, GBP_M5_78.getAmount()); + assertThat(GBP_M5_78.getAmount()).isEqualTo(BIGDEC_M5_78); } //----------------------------------------------------------------------- @@ -1001,12 +963,12 @@ void test_getAmount_negative() { //----------------------------------------------------------------------- @Test void test_getAmountMajor_positive() { - assertEquals(BigDecimal.valueOf(2), GBP_2_34.getAmountMajor()); + assertThat(GBP_2_34.getAmountMajor()).isEqualTo(BigDecimal.valueOf(2)); } @Test void test_getAmountMajor_negative() { - assertEquals(BigDecimal.valueOf(-5), GBP_M5_78.getAmountMajor()); + assertThat(GBP_M5_78.getAmountMajor()).isEqualTo(BigDecimal.valueOf(-5)); } //----------------------------------------------------------------------- @@ -1014,26 +976,24 @@ void test_getAmountMajor_negative() { //----------------------------------------------------------------------- @Test void test_getAmountMajorLong_positive() { - assertEquals(2L, GBP_2_34.getAmountMajorLong()); + assertThat(GBP_2_34.getAmountMajorLong()).isEqualTo(2L); } @Test void test_getAmountMajorLong_negative() { - assertEquals(-5L, GBP_M5_78.getAmountMajorLong()); + assertThat(GBP_M5_78.getAmountMajorLong()).isEqualTo(-5L); } @Test void test_getAmountMajorLong_tooBigPositive() { - assertThrows(ArithmeticException.class, () -> { - GBP_LONG_MAX_MAJOR_PLUS1.getAmountMajorLong(); - }); + assertThatExceptionOfType(ArithmeticException.class) + .isThrownBy(() -> GBP_LONG_MAX_MAJOR_PLUS1.getAmountMajorLong()); } @Test void test_getAmountMajorLong_tooBigNegative() { - assertThrows(ArithmeticException.class, () -> { - GBP_LONG_MIN_MAJOR_MINUS1.getAmountMajorLong(); - }); + assertThatExceptionOfType(ArithmeticException.class) + .isThrownBy(() -> GBP_LONG_MIN_MAJOR_MINUS1.getAmountMajorLong()); } //----------------------------------------------------------------------- @@ -1041,26 +1001,24 @@ void test_getAmountMajorLong_tooBigNegative() { //----------------------------------------------------------------------- @Test void test_getAmountMajorInt_positive() { - assertEquals(2, GBP_2_34.getAmountMajorInt()); + assertThat(GBP_2_34.getAmountMajorInt()).isEqualTo(2); } @Test void test_getAmountMajorInt_negative() { - assertEquals(-5, GBP_M5_78.getAmountMajorInt()); + assertThat(GBP_M5_78.getAmountMajorInt()).isEqualTo(-5); } @Test void test_getAmountMajorInt_tooBigPositive() { - assertThrows(ArithmeticException.class, () -> { - GBP_INT_MAX_MAJOR_PLUS1.getAmountMajorInt(); - }); + assertThatExceptionOfType(ArithmeticException.class) + .isThrownBy(() -> GBP_INT_MAX_MAJOR_PLUS1.getAmountMajorInt()); } @Test void test_getAmountMajorInt_tooBigNegative() { - assertThrows(ArithmeticException.class, () -> { - GBP_INT_MIN_MAJOR_MINUS1.getAmountMajorInt(); - }); + assertThatExceptionOfType(ArithmeticException.class) + .isThrownBy(() -> GBP_INT_MIN_MAJOR_MINUS1.getAmountMajorInt()); } //----------------------------------------------------------------------- @@ -1068,12 +1026,12 @@ void test_getAmountMajorInt_tooBigNegative() { //----------------------------------------------------------------------- @Test void test_getAmountMinor_positive() { - assertEquals(BigDecimal.valueOf(234), GBP_2_34.getAmountMinor()); + assertThat(GBP_2_34.getAmountMinor()).isEqualTo(BigDecimal.valueOf(234)); } @Test void test_getAmountMinor_negative() { - assertEquals(BigDecimal.valueOf(-578), GBP_M5_78.getAmountMinor()); + assertThat(GBP_M5_78.getAmountMinor()).isEqualTo(BigDecimal.valueOf(-578)); } //----------------------------------------------------------------------- @@ -1081,26 +1039,24 @@ void test_getAmountMinor_negative() { //----------------------------------------------------------------------- @Test void test_getAmountMinorLong_positive() { - assertEquals(234L, GBP_2_34.getAmountMinorLong()); + assertThat(GBP_2_34.getAmountMinorLong()).isEqualTo(234L); } @Test void test_getAmountMinorLong_negative() { - assertEquals(-578L, GBP_M5_78.getAmountMinorLong()); + assertThat(GBP_M5_78.getAmountMinorLong()).isEqualTo(-578L); } @Test void test_getAmountMinorLong_tooBigPositive() { - assertThrows(ArithmeticException.class, () -> { - GBP_LONG_MAX_PLUS1.getAmountMinorLong(); - }); + assertThatExceptionOfType(ArithmeticException.class) + .isThrownBy(() -> GBP_LONG_MAX_PLUS1.getAmountMinorLong()); } @Test void test_getAmountMinorLong_tooBigNegative() { - assertThrows(ArithmeticException.class, () -> { - GBP_LONG_MIN_MINUS1.getAmountMinorLong(); - }); + assertThatExceptionOfType(ArithmeticException.class) + .isThrownBy(() -> GBP_LONG_MIN_MINUS1.getAmountMinorLong()); } //----------------------------------------------------------------------- @@ -1108,26 +1064,24 @@ void test_getAmountMinorLong_tooBigNegative() { //----------------------------------------------------------------------- @Test void test_getAmountMinorInt_positive() { - assertEquals(234, GBP_2_34.getAmountMinorInt()); + assertThat(GBP_2_34.getAmountMinorInt()).isEqualTo(234); } @Test void test_getAmountMinorInt_negative() { - assertEquals(-578, GBP_M5_78.getAmountMinorInt()); + assertThat(GBP_M5_78.getAmountMinorInt()).isEqualTo(-578); } @Test void test_getAmountMinorInt_tooBigPositive() { - assertThrows(ArithmeticException.class, () -> { - GBP_INT_MAX_PLUS1.getAmountMinorInt(); - }); + assertThatExceptionOfType(ArithmeticException.class) + .isThrownBy(() -> GBP_INT_MAX_PLUS1.getAmountMinorInt()); } @Test void test_getAmountMinorInt_tooBigNegative() { - assertThrows(ArithmeticException.class, () -> { - GBP_INT_MIN_MINUS1.getAmountMinorInt(); - }); + assertThatExceptionOfType(ArithmeticException.class) + .isThrownBy(() -> GBP_INT_MIN_MINUS1.getAmountMinorInt()); } //----------------------------------------------------------------------- @@ -1135,12 +1089,12 @@ void test_getAmountMinorInt_tooBigNegative() { //----------------------------------------------------------------------- @Test void test_getMinorPart_positive() { - assertEquals(34, GBP_2_34.getMinorPart()); + assertThat(GBP_2_34.getMinorPart()).isEqualTo(34); } @Test void test_getMinorPart_negative() { - assertEquals(-78, GBP_M5_78.getMinorPart()); + assertThat(GBP_M5_78.getMinorPart()).isEqualTo(-78); } //----------------------------------------------------------------------- @@ -1148,9 +1102,9 @@ void test_getMinorPart_negative() { //----------------------------------------------------------------------- @Test void test_isZero() { - assertTrue(GBP_0_00.isZero()); - assertFalse(GBP_2_34.isZero()); - assertFalse(GBP_M5_78.isZero()); + assertThat(GBP_0_00.isZero()).isTrue(); + assertThat(GBP_2_34.isZero()).isFalse(); + assertThat(GBP_M5_78.isZero()).isFalse(); } //----------------------------------------------------------------------- @@ -1158,9 +1112,9 @@ void test_isZero() { //----------------------------------------------------------------------- @Test void test_isPositive() { - assertFalse(GBP_0_00.isPositive()); - assertTrue(GBP_2_34.isPositive()); - assertFalse(GBP_M5_78.isPositive()); + assertThat(GBP_0_00.isPositive()).isFalse(); + assertThat(GBP_2_34.isPositive()).isTrue(); + assertThat(GBP_M5_78.isPositive()).isFalse(); } //----------------------------------------------------------------------- @@ -1168,9 +1122,9 @@ void test_isPositive() { //----------------------------------------------------------------------- @Test void test_isPositiveOrZero() { - assertTrue(GBP_0_00.isPositiveOrZero()); - assertTrue(GBP_2_34.isPositiveOrZero()); - assertFalse(GBP_M5_78.isPositiveOrZero()); + assertThat(GBP_0_00.isPositiveOrZero()).isTrue(); + assertThat(GBP_2_34.isPositiveOrZero()).isTrue(); + assertThat(GBP_M5_78.isPositiveOrZero()).isFalse(); } //----------------------------------------------------------------------- @@ -1178,9 +1132,9 @@ void test_isPositiveOrZero() { //----------------------------------------------------------------------- @Test void test_isNegative() { - assertFalse(GBP_0_00.isNegative()); - assertFalse(GBP_2_34.isNegative()); - assertTrue(GBP_M5_78.isNegative()); + assertThat(GBP_0_00.isNegative()).isFalse(); + assertThat(GBP_2_34.isNegative()).isFalse(); + assertThat(GBP_M5_78.isNegative()).isTrue(); } //----------------------------------------------------------------------- @@ -1188,9 +1142,9 @@ void test_isNegative() { //----------------------------------------------------------------------- @Test void test_isNegativeOrZero() { - assertTrue(GBP_0_00.isNegativeOrZero()); - assertFalse(GBP_2_34.isNegativeOrZero()); - assertTrue(GBP_M5_78.isNegativeOrZero()); + assertThat(GBP_0_00.isNegativeOrZero()).isTrue(); + assertThat(GBP_2_34.isNegativeOrZero()).isFalse(); + assertThat(GBP_M5_78.isNegativeOrZero()).isTrue(); } //----------------------------------------------------------------------- @@ -1199,27 +1153,25 @@ void test_isNegativeOrZero() { @Test void test_withAmount_BigDecimal() { Money test = GBP_2_34.withAmount(BIGDEC_M5_78); - assertEquals("GBP -5.78", test.toString()); + assertThat(test).hasToString("GBP -5.78"); } @Test void test_withAmount_BigDecimal_same() { Money test = GBP_2_34.withAmount(BIGDEC_2_34); - assertSame(GBP_2_34, test); + assertThat(test).isSameAs(GBP_2_34); } @Test void test_withAmount_BigDecimal_invalidScale() { - assertThrows(ArithmeticException.class, () -> { - GBP_2_34.withAmount(new BigDecimal("2.345")); - }); + assertThatExceptionOfType(ArithmeticException.class) + .isThrownBy(() -> GBP_2_34.withAmount(new BigDecimal("2.345"))); } @Test void test_withAmount_BigDecimal_nullBigDecimal() { - assertThrows(NullPointerException.class, () -> { - GBP_2_34.withAmount((BigDecimal) null); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> GBP_2_34.withAmount((BigDecimal) null)); } //----------------------------------------------------------------------- @@ -1228,40 +1180,37 @@ void test_withAmount_BigDecimal_nullBigDecimal() { @Test void test_withAmount_BigDecimalRoundingMode() { Money test = GBP_2_34.withAmount(BIGDEC_M5_78, RoundingMode.UNNECESSARY); - assertEquals("GBP -5.78", test.toString()); + assertThat(test).hasToString("GBP -5.78"); } @Test void test_withAmount_BigDecimalRoundingMode_same() { Money test = GBP_2_34.withAmount(BIGDEC_2_34, RoundingMode.UNNECESSARY); - assertSame(GBP_2_34, test); + assertThat(test).isSameAs(GBP_2_34); } @Test void test_withAmount_BigDecimalRoundingMode_roundDown() { Money test = GBP_2_34.withAmount(new BigDecimal("2.355"), RoundingMode.DOWN); - assertEquals(GBP_2_35, test); + assertThat(test).isEqualTo(GBP_2_35); } @Test void test_withAmount_BigDecimalRoundingMode_roundUnecessary() { - assertThrows(ArithmeticException.class, () -> { - GBP_2_34.withAmount(new BigDecimal("2.345"), RoundingMode.UNNECESSARY); - }); + assertThatExceptionOfType(ArithmeticException.class) + .isThrownBy(() -> GBP_2_34.withAmount(new BigDecimal("2.345"), RoundingMode.UNNECESSARY)); } @Test void test_withAmount_BigDecimalRoundingMode_nullBigDecimal() { - assertThrows(NullPointerException.class, () -> { - GBP_2_34.withAmount((BigDecimal) null, RoundingMode.UNNECESSARY); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> GBP_2_34.withAmount((BigDecimal) null, RoundingMode.UNNECESSARY)); } @Test void test_withAmount_BigDecimalRoundingMode_nullRoundingMode() { - assertThrows(NullPointerException.class, () -> { - GBP_2_34.withAmount(BIGDEC_2_34, (RoundingMode) null); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> GBP_2_34.withAmount(BIGDEC_2_34, (RoundingMode) null)); } //----------------------------------------------------------------------- @@ -1270,20 +1219,19 @@ void test_withAmount_BigDecimalRoundingMode_nullRoundingMode() { @Test void test_withAmount_double() { Money test = GBP_2_34.withAmount(-5.78d); - assertEquals("GBP -5.78", test.toString()); + assertThat(test).hasToString("GBP -5.78"); } @Test void test_withAmount_double_same() { Money test = GBP_2_34.withAmount(2.34d); - assertSame(GBP_2_34, test); + assertThat(test).isSameAs(GBP_2_34); } @Test void test_withAmount_double_invalidScale() { - assertThrows(ArithmeticException.class, () -> { - GBP_2_34.withAmount(2.345d); - }); + assertThatExceptionOfType(ArithmeticException.class) + .isThrownBy(() -> GBP_2_34.withAmount(2.345d)); } //----------------------------------------------------------------------- @@ -1292,33 +1240,31 @@ void test_withAmount_double_invalidScale() { @Test void test_withAmount_doubleRoundingMode() { Money test = GBP_2_34.withAmount(-5.78d, RoundingMode.UNNECESSARY); - assertEquals("GBP -5.78", test.toString()); + assertThat(test).hasToString("GBP -5.78"); } @Test void test_withAmount_doubleRoundingMode_same() { Money test = GBP_2_34.withAmount(2.34d, RoundingMode.UNNECESSARY); - assertSame(GBP_2_34, test); + assertThat(test).isSameAs(GBP_2_34); } @Test void test_withAmount_doubleRoundingMode_roundDown() { Money test = GBP_2_34.withAmount(2.355d, RoundingMode.DOWN); - assertEquals(GBP_2_35, test); + assertThat(test).isEqualTo(GBP_2_35); } @Test void test_withAmount_doubleRoundingMode_roundUnecessary() { - assertThrows(ArithmeticException.class, () -> { - GBP_2_34.withAmount(2.345d, RoundingMode.UNNECESSARY); - }); + assertThatExceptionOfType(ArithmeticException.class) + .isThrownBy(() -> GBP_2_34.withAmount(2.345d, RoundingMode.UNNECESSARY)); } @Test void test_withAmount_doubleRoundingMode_nullRoundingMode() { - assertThrows(NullPointerException.class, () -> { - GBP_2_34.withAmount(BIGDEC_2_34, (RoundingMode) null); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> GBP_2_34.withAmount(BIGDEC_2_34, (RoundingMode) null)); } //----------------------------------------------------------------------- @@ -1328,43 +1274,42 @@ void test_withAmount_doubleRoundingMode_nullRoundingMode() { 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()); + assertThat(test).hasToString("GBP 5.90"); } @Test void test_plus_Iterable_zero() { Iterable iterable = Arrays.asList(GBP_0_00); Money test = GBP_2_34.plus(iterable); - assertSame(GBP_2_34, test); + assertThat(test).isSameAs(GBP_2_34); } @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; - } - }); + assertThatExceptionOfType(CurrencyMismatchException.class) + .isThrownBy(() -> { + 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_nullEntry() { Iterable iterable = Arrays.asList(GBP_2_33, null); - assertThrows(NullPointerException.class, () -> { - GBP_M5_78.plus(iterable); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> GBP_M5_78.plus(iterable)); } @Test void test_plus_Iterable_nullIterable() { - assertThrows(NullPointerException.class, () -> { - GBP_M5_78.plus((Iterable) null); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> GBP_M5_78.plus((Iterable) null)); } //----------------------------------------------------------------------- @@ -1373,39 +1318,39 @@ void test_plus_Iterable_nullIterable() { @Test void test_plus_Money_zero() { Money test = GBP_2_34.plus(GBP_0_00); - assertSame(GBP_2_34, test); + assertThat(test).isSameAs(GBP_2_34); } @Test void test_plus_Money_positive() { Money test = GBP_2_34.plus(GBP_1_23); - assertEquals("GBP 3.57", test.toString()); + assertThat(test).hasToString("GBP 3.57"); } @Test void test_plus_Money_negative() { Money test = GBP_2_34.plus(GBP_M1_23); - assertEquals("GBP 1.11", test.toString()); + assertThat(test).hasToString("GBP 1.11"); } @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; - } - }); + assertThatExceptionOfType(CurrencyMismatchException.class) + .isThrownBy(() -> { + 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_nullMoney() { - assertThrows(NullPointerException.class, () -> { - GBP_M5_78.plus((Money) null); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> GBP_M5_78.plus((Money) null)); } //----------------------------------------------------------------------- @@ -1414,33 +1359,31 @@ void test_plus_Money_nullMoney() { @Test void test_plus_BigDecimal_zero() { Money test = GBP_2_34.plus(BigDecimal.ZERO); - assertSame(GBP_2_34, test); + assertThat(test).isSameAs(GBP_2_34); } @Test void test_plus_BigDecimal_positive() { Money test = GBP_2_34.plus(new BigDecimal("1.23")); - assertEquals("GBP 3.57", test.toString()); + assertThat(test).hasToString("GBP 3.57"); } @Test void test_plus_BigDecimal_negative() { Money test = GBP_2_34.plus(new BigDecimal("-1.23")); - assertEquals("GBP 1.11", test.toString()); + assertThat(test).hasToString("GBP 1.11"); } @Test void test_plus_BigDecimal_invalidScale() { - assertThrows(ArithmeticException.class, () -> { - GBP_2_34.plus(new BigDecimal("1.235")); - }); + assertThatExceptionOfType(ArithmeticException.class) + .isThrownBy(() -> GBP_2_34.plus(new BigDecimal("1.235"))); } @Test void test_plus_BigDecimal_nullBigDecimal() { - assertThrows(NullPointerException.class, () -> { - GBP_M5_78.plus((BigDecimal) null); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> GBP_M5_78.plus((BigDecimal) null)); } //----------------------------------------------------------------------- @@ -1449,46 +1392,43 @@ void test_plus_BigDecimal_nullBigDecimal() { @Test void test_plus_BigDecimalRoundingMode_zero() { Money test = GBP_2_34.plus(BigDecimal.ZERO, RoundingMode.UNNECESSARY); - assertSame(GBP_2_34, test); + assertThat(test).isSameAs(GBP_2_34); } @Test void test_plus_BigDecimalRoundingMode_positive() { Money test = GBP_2_34.plus(new BigDecimal("1.23"), RoundingMode.UNNECESSARY); - assertEquals("GBP 3.57", test.toString()); + assertThat(test).hasToString("GBP 3.57"); } @Test void test_plus_BigDecimalRoundingMode_negative() { Money test = GBP_2_34.plus(new BigDecimal("-1.23"), RoundingMode.UNNECESSARY); - assertEquals("GBP 1.11", test.toString()); + assertThat(test).hasToString("GBP 1.11"); } @Test void test_plus_BigDecimalRoundingMode_roundDown() { Money test = GBP_2_34.plus(new BigDecimal("1.235"), RoundingMode.DOWN); - assertEquals("GBP 3.57", test.toString()); + assertThat(test).hasToString("GBP 3.57"); } @Test void test_plus_BigDecimalRoundingMode_roundUnecessary() { - assertThrows(ArithmeticException.class, () -> { - GBP_2_34.plus(new BigDecimal("1.235"), RoundingMode.UNNECESSARY); - }); + assertThatExceptionOfType(ArithmeticException.class) + .isThrownBy(() -> GBP_2_34.plus(new BigDecimal("1.235"), RoundingMode.UNNECESSARY)); } @Test void test_plus_BigDecimalRoundingMode_nullBigDecimal() { - assertThrows(NullPointerException.class, () -> { - GBP_M5_78.plus((BigDecimal) null, RoundingMode.UNNECESSARY); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> GBP_M5_78.plus((BigDecimal) null, RoundingMode.UNNECESSARY)); } @Test void test_plus_BigDecimalRoundingMode_nullRoundingMode() { - assertThrows(NullPointerException.class, () -> { - GBP_M5_78.plus(BIGDEC_2_34, (RoundingMode) null); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> GBP_M5_78.plus(BIGDEC_2_34, (RoundingMode) null)); } //----------------------------------------------------------------------- @@ -1497,26 +1437,25 @@ void test_plus_BigDecimalRoundingMode_nullRoundingMode() { @Test void test_plus_double_zero() { Money test = GBP_2_34.plus(0d); - assertSame(GBP_2_34, test); + assertThat(test).isSameAs(GBP_2_34); } @Test void test_plus_double_positive() { Money test = GBP_2_34.plus(1.23d); - assertEquals("GBP 3.57", test.toString()); + assertThat(test).hasToString("GBP 3.57"); } @Test void test_plus_double_negative() { Money test = GBP_2_34.plus(-1.23d); - assertEquals("GBP 1.11", test.toString()); + assertThat(test).hasToString("GBP 1.11"); } @Test void test_plus_double_invalidScale() { - assertThrows(ArithmeticException.class, () -> { - GBP_2_34.plus(1.235d); - }); + assertThatExceptionOfType(ArithmeticException.class) + .isThrownBy(() -> GBP_2_34.plus(1.235d)); } //----------------------------------------------------------------------- @@ -1525,39 +1464,37 @@ void test_plus_double_invalidScale() { @Test void test_plus_doubleRoundingMode_zero() { Money test = GBP_2_34.plus(0d, RoundingMode.UNNECESSARY); - assertSame(GBP_2_34, test); + assertThat(test).isSameAs(GBP_2_34); } @Test void test_plus_doubleRoundingMode_positive() { Money test = GBP_2_34.plus(1.23d, RoundingMode.UNNECESSARY); - assertEquals("GBP 3.57", test.toString()); + assertThat(test).hasToString("GBP 3.57"); } @Test void test_plus_doubleRoundingMode_negative() { Money test = GBP_2_34.plus(-1.23d, RoundingMode.UNNECESSARY); - assertEquals("GBP 1.11", test.toString()); + assertThat(test).hasToString("GBP 1.11"); } @Test void test_plus_doubleRoundingMode_roundDown() { Money test = GBP_2_34.plus(1.235d, RoundingMode.DOWN); - assertEquals("GBP 3.57", test.toString()); + assertThat(test).hasToString("GBP 3.57"); } @Test void test_plus_doubleRoundingMode_roundUnecessary() { - assertThrows(ArithmeticException.class, () -> { - GBP_2_34.plus(1.235d, RoundingMode.UNNECESSARY); - }); + assertThatExceptionOfType(ArithmeticException.class) + .isThrownBy(() -> GBP_2_34.plus(1.235d, RoundingMode.UNNECESSARY)); } @Test void test_plus_doubleRoundingMode_nullRoundingMode() { - assertThrows(NullPointerException.class, () -> { - GBP_M5_78.plus(2.34d, (RoundingMode) null); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> GBP_M5_78.plus(2.34d, (RoundingMode) null)); } //----------------------------------------------------------------------- @@ -1566,19 +1503,19 @@ void test_plus_doubleRoundingMode_nullRoundingMode() { @Test void test_plusMajor_zero() { Money test = GBP_2_34.plusMajor(0); - assertSame(GBP_2_34, test); + assertThat(test).isSameAs(GBP_2_34); } @Test void test_plusMajor_positive() { Money test = GBP_2_34.plusMajor(123); - assertEquals("GBP 125.34", test.toString()); + assertThat(test).hasToString("GBP 125.34"); } @Test void test_plusMajor_negative() { Money test = GBP_2_34.plusMajor(-123); - assertEquals("GBP -120.66", test.toString()); + assertThat(test).hasToString("GBP -120.66"); } //----------------------------------------------------------------------- @@ -1587,19 +1524,19 @@ void test_plusMajor_negative() { @Test void test_plusMinor_zero() { Money test = GBP_2_34.plusMinor(0); - assertSame(GBP_2_34, test); + assertThat(test).isSameAs(GBP_2_34); } @Test void test_plusMinor_positive() { Money test = GBP_2_34.plusMinor(123); - assertEquals("GBP 3.57", test.toString()); + assertThat(test).hasToString("GBP 3.57"); } @Test void test_plusMinor_negative() { Money test = GBP_2_34.plusMinor(-123); - assertEquals("GBP 1.11", test.toString()); + assertThat(test).hasToString("GBP 1.11"); } //----------------------------------------------------------------------- @@ -1609,43 +1546,42 @@ void test_plusMinor_negative() { 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()); + assertThat(test).hasToString("GBP -1.22"); } @Test void test_minus_Iterable_zero() { Iterable iterable = Arrays.asList(GBP_0_00); Money test = GBP_2_34.minus(iterable); - assertSame(GBP_2_34, test); + assertThat(test).isSameAs(GBP_2_34); } @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; - } - }); + assertThatExceptionOfType(CurrencyMismatchException.class) + .isThrownBy(() -> { + 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_nullEntry() { Iterable iterable = Arrays.asList(GBP_2_33, null); - assertThrows(NullPointerException.class, () -> { - GBP_M5_78.minus(iterable); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> GBP_M5_78.minus(iterable)); } @Test void test_minus_Iterable_nullIterable() { - assertThrows(NullPointerException.class, () -> { - GBP_M5_78.minus((Iterable) null); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> GBP_M5_78.minus((Iterable) null)); } //----------------------------------------------------------------------- @@ -1654,39 +1590,39 @@ void test_minus_Iterable_nullIterable() { @Test void test_minus_Money_zero() { Money test = GBP_2_34.minus(GBP_0_00); - assertSame(GBP_2_34, test); + assertThat(test).isSameAs(GBP_2_34); } @Test void test_minus_Money_positive() { Money test = GBP_2_34.minus(GBP_1_23); - assertEquals("GBP 1.11", test.toString()); + assertThat(test).hasToString("GBP 1.11"); } @Test void test_minus_Money_negative() { Money test = GBP_2_34.minus(GBP_M1_23); - assertEquals("GBP 3.57", test.toString()); + assertThat(test).hasToString("GBP 3.57"); } @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; - } - }); + assertThatExceptionOfType(CurrencyMismatchException.class) + .isThrownBy(() -> { + 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_nullMoney() { - assertThrows(NullPointerException.class, () -> { - GBP_M5_78.minus((Money) null); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> GBP_M5_78.minus((Money) null)); } //----------------------------------------------------------------------- @@ -1695,33 +1631,31 @@ void test_minus_Money_nullMoney() { @Test void test_minus_BigDecimal_zero() { Money test = GBP_2_34.minus(BigDecimal.ZERO); - assertSame(GBP_2_34, test); + assertThat(test).isSameAs(GBP_2_34); } @Test void test_minus_BigDecimal_positive() { Money test = GBP_2_34.minus(new BigDecimal("1.23")); - assertEquals("GBP 1.11", test.toString()); + assertThat(test).hasToString("GBP 1.11"); } @Test void test_minus_BigDecimal_negative() { Money test = GBP_2_34.minus(new BigDecimal("-1.23")); - assertEquals("GBP 3.57", test.toString()); + assertThat(test).hasToString("GBP 3.57"); } @Test void test_minus_BigDecimal_invalidScale() { - assertThrows(ArithmeticException.class, () -> { - GBP_2_34.minus(new BigDecimal("1.235")); - }); + assertThatExceptionOfType(ArithmeticException.class) + .isThrownBy(() -> GBP_2_34.minus(new BigDecimal("1.235"))); } @Test void test_minus_BigDecimal_nullBigDecimal() { - assertThrows(NullPointerException.class, () -> { - GBP_M5_78.minus((BigDecimal) null); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> GBP_M5_78.minus((BigDecimal) null)); } //----------------------------------------------------------------------- @@ -1730,46 +1664,43 @@ void test_minus_BigDecimal_nullBigDecimal() { @Test void test_minus_BigDecimalRoundingMode_zero() { Money test = GBP_2_34.minus(BigDecimal.ZERO, RoundingMode.UNNECESSARY); - assertSame(GBP_2_34, test); + assertThat(test).isSameAs(GBP_2_34); } @Test void test_minus_BigDecimalRoundingMode_positive() { Money test = GBP_2_34.minus(new BigDecimal("1.23"), RoundingMode.UNNECESSARY); - assertEquals("GBP 1.11", test.toString()); + assertThat(test).hasToString("GBP 1.11"); } @Test void test_minus_BigDecimalRoundingMode_negative() { Money test = GBP_2_34.minus(new BigDecimal("-1.23"), RoundingMode.UNNECESSARY); - assertEquals("GBP 3.57", test.toString()); + assertThat(test).hasToString("GBP 3.57"); } @Test void test_minus_BigDecimalRoundingMode_roundDown() { Money test = GBP_2_34.minus(new BigDecimal("1.235"), RoundingMode.DOWN); - assertEquals("GBP 1.10", test.toString()); + assertThat(test).hasToString("GBP 1.10"); } @Test void test_minus_BigDecimalRoundingMode_roundUnecessary() { - assertThrows(ArithmeticException.class, () -> { - GBP_2_34.minus(new BigDecimal("1.235"), RoundingMode.UNNECESSARY); - }); + assertThatExceptionOfType(ArithmeticException.class) + .isThrownBy(() -> GBP_2_34.minus(new BigDecimal("1.235"), RoundingMode.UNNECESSARY)); } @Test void test_minus_BigDecimalRoundingMode_nullBigDecimal() { - assertThrows(NullPointerException.class, () -> { - GBP_M5_78.minus((BigDecimal) null, RoundingMode.UNNECESSARY); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> GBP_M5_78.minus((BigDecimal) null, RoundingMode.UNNECESSARY)); } @Test void test_minus_BigDecimalRoundingMode_nullRoundingMode() { - assertThrows(NullPointerException.class, () -> { - GBP_M5_78.minus(BIGDEC_2_34, (RoundingMode) null); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> GBP_M5_78.minus(BIGDEC_2_34, (RoundingMode) null)); } //----------------------------------------------------------------------- @@ -1778,26 +1709,25 @@ void test_minus_BigDecimalRoundingMode_nullRoundingMode() { @Test void test_minus_double_zero() { Money test = GBP_2_34.minus(0d); - assertSame(GBP_2_34, test); + assertThat(test).isSameAs(GBP_2_34); } @Test void test_minus_double_positive() { Money test = GBP_2_34.minus(1.23d); - assertEquals("GBP 1.11", test.toString()); + assertThat(test).hasToString("GBP 1.11"); } @Test void test_minus_double_negative() { Money test = GBP_2_34.minus(-1.23d); - assertEquals("GBP 3.57", test.toString()); + assertThat(test).hasToString("GBP 3.57"); } @Test void test_minus_double_invalidScale() { - assertThrows(ArithmeticException.class, () -> { - GBP_2_34.minus(1.235d); - }); + assertThatExceptionOfType(ArithmeticException.class) + .isThrownBy(() -> GBP_2_34.minus(1.235d)); } //----------------------------------------------------------------------- @@ -1806,39 +1736,37 @@ void test_minus_double_invalidScale() { @Test void test_minus_doubleRoundingMode_zero() { Money test = GBP_2_34.minus(0d, RoundingMode.UNNECESSARY); - assertSame(GBP_2_34, test); + assertThat(test).isSameAs(GBP_2_34); } @Test void test_minus_doubleRoundingMode_positive() { Money test = GBP_2_34.minus(1.23d, RoundingMode.UNNECESSARY); - assertEquals("GBP 1.11", test.toString()); + assertThat(test).hasToString("GBP 1.11"); } @Test void test_minus_doubleRoundingMode_negative() { Money test = GBP_2_34.minus(-1.23d, RoundingMode.UNNECESSARY); - assertEquals("GBP 3.57", test.toString()); + assertThat(test).hasToString("GBP 3.57"); } @Test void test_minus_doubleRoundingMode_roundDown() { Money test = GBP_2_34.minus(1.235d, RoundingMode.DOWN); - assertEquals("GBP 1.10", test.toString()); + assertThat(test).hasToString("GBP 1.10"); } @Test void test_minus_doubleRoundingMode_roundUnecessary() { - assertThrows(ArithmeticException.class, () -> { - GBP_2_34.minus(1.235d, RoundingMode.UNNECESSARY); - }); + assertThatExceptionOfType(ArithmeticException.class) + .isThrownBy(() -> GBP_2_34.minus(1.235d, RoundingMode.UNNECESSARY)); } @Test void test_minus_doubleRoundingMode_nullRoundingMode() { - assertThrows(NullPointerException.class, () -> { - GBP_M5_78.minus(2.34d, (RoundingMode) null); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> GBP_M5_78.minus(2.34d, (RoundingMode) null)); } //----------------------------------------------------------------------- @@ -1847,19 +1775,19 @@ void test_minus_doubleRoundingMode_nullRoundingMode() { @Test void test_minusMajor_zero() { Money test = GBP_2_34.minusMajor(0); - assertSame(GBP_2_34, test); + assertThat(test).isSameAs(GBP_2_34); } @Test void test_minusMajor_positive() { Money test = GBP_2_34.minusMajor(123); - assertEquals("GBP -120.66", test.toString()); + assertThat(test).hasToString("GBP -120.66"); } @Test void test_minusMajor_negative() { Money test = GBP_2_34.minusMajor(-123); - assertEquals("GBP 125.34", test.toString()); + assertThat(test).hasToString("GBP 125.34"); } //----------------------------------------------------------------------- @@ -1868,19 +1796,19 @@ void test_minusMajor_negative() { @Test void test_minusMinor_zero() { Money test = GBP_2_34.minusMinor(0); - assertSame(GBP_2_34, test); + assertThat(test).isSameAs(GBP_2_34); } @Test void test_minusMinor_positive() { Money test = GBP_2_34.minusMinor(123); - assertEquals("GBP 1.11", test.toString()); + assertThat(test).hasToString("GBP 1.11"); } @Test void test_minusMinor_negative() { Money test = GBP_2_34.minusMinor(-123); - assertEquals("GBP 3.57", test.toString()); + assertThat(test).hasToString("GBP 3.57"); } //----------------------------------------------------------------------- @@ -1889,39 +1817,37 @@ void test_minusMinor_negative() { @Test void test_multipliedBy_BigDecimalRoundingMode_one() { Money test = GBP_2_34.multipliedBy(BigDecimal.ONE, RoundingMode.DOWN); - assertSame(GBP_2_34, test); + assertThat(test).isSameAs(GBP_2_34); } @Test void test_multipliedBy_BigDecimalRoundingMode_positive() { Money test = GBP_2_33.multipliedBy(new BigDecimal("2.5"), RoundingMode.DOWN); - assertEquals("GBP 5.82", test.toString()); + assertThat(test).hasToString("GBP 5.82"); } @Test 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()); + assertThat(test).hasToString("GBP 5.83"); } @Test void test_multipliedBy_BigDecimalRoundingMode_negative() { Money test = GBP_2_33.multipliedBy(new BigDecimal("-2.5"), RoundingMode.FLOOR); - assertEquals("GBP -5.83", test.toString()); + assertThat(test).hasToString("GBP -5.83"); } @Test void test_multipliedBy_BigDecimalRoundingMode_nullBigDecimal() { - assertThrows(NullPointerException.class, () -> { - GBP_5_78.multipliedBy((BigDecimal) null, RoundingMode.DOWN); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> GBP_5_78.multipliedBy((BigDecimal) null, RoundingMode.DOWN)); } @Test void test_multipliedBy_BigDecimalRoundingMode_nullRoundingMode() { - assertThrows(NullPointerException.class, () -> { - GBP_5_78.multipliedBy(new BigDecimal("2.5"), (RoundingMode) null); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> GBP_5_78.multipliedBy(new BigDecimal("2.5"), (RoundingMode) null)); } //----------------------------------------------------------------------- @@ -1930,32 +1856,31 @@ void test_multipliedBy_BigDecimalRoundingMode_nullRoundingMode() { @Test void test_multipliedBy_doubleRoundingMode_one() { Money test = GBP_2_34.multipliedBy(1d, RoundingMode.DOWN); - assertSame(GBP_2_34, test); + assertThat(test).isSameAs(GBP_2_34); } @Test void test_multipliedBy_doubleRoundingMode_positive() { Money test = GBP_2_33.multipliedBy(2.5d, RoundingMode.DOWN); - assertEquals("GBP 5.82", test.toString()); + assertThat(test).hasToString("GBP 5.82"); } @Test void test_multipliedBy_doubleRoundingMode_positive_halfUp() { Money test = GBP_2_33.multipliedBy(2.5d, RoundingMode.HALF_UP); - assertEquals("GBP 5.83", test.toString()); + assertThat(test).hasToString("GBP 5.83"); } @Test void test_multipliedBy_doubleRoundingMode_negative() { Money test = GBP_2_33.multipliedBy(-2.5d, RoundingMode.FLOOR); - assertEquals("GBP -5.83", test.toString()); + assertThat(test).hasToString("GBP -5.83"); } @Test void test_multipliedBy_doubleRoundingMode_nullRoundingMode() { - assertThrows(NullPointerException.class, () -> { - GBP_5_78.multipliedBy(2.5d, (RoundingMode) null); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> GBP_5_78.multipliedBy(2.5d, (RoundingMode) null)); } //----------------------------------------------------------------------- @@ -1964,19 +1889,19 @@ void test_multipliedBy_doubleRoundingMode_nullRoundingMode() { @Test void test_multipliedBy_long_one() { Money test = GBP_2_34.multipliedBy(1); - assertSame(GBP_2_34, test); + assertThat(test).isSameAs(GBP_2_34); } @Test void test_multipliedBy_long_positive() { Money test = GBP_2_34.multipliedBy(3); - assertEquals("GBP 7.02", test.toString()); + assertThat(test).hasToString("GBP 7.02"); } @Test void test_multipliedBy_long_negative() { Money test = GBP_2_34.multipliedBy(-3); - assertEquals("GBP -7.02", test.toString()); + assertThat(test).hasToString("GBP -7.02"); } //----------------------------------------------------------------------- @@ -1985,39 +1910,37 @@ void test_multipliedBy_long_negative() { @Test void test_dividedBy_BigDecimalRoundingMode_one() { Money test = GBP_2_34.dividedBy(BigDecimal.ONE, RoundingMode.DOWN); - assertSame(GBP_2_34, test); + assertThat(test).isSameAs(GBP_2_34); } @Test void test_dividedBy_BigDecimalRoundingMode_positive() { Money test = GBP_2_34.dividedBy(new BigDecimal("2.5"), RoundingMode.DOWN); - assertEquals("GBP 0.93", test.toString()); + assertThat(test).hasToString("GBP 0.93"); } @Test 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()); + assertThat(test).hasToString("GBP 0.94"); } @Test void test_dividedBy_BigDecimalRoundingMode_negative() { Money test = GBP_2_34.dividedBy(new BigDecimal("-2.5"), RoundingMode.FLOOR); - assertEquals("GBP -0.94", test.toString()); + assertThat(test).hasToString("GBP -0.94"); } @Test void test_dividedBy_BigDecimalRoundingMode_nullBigDecimal() { - assertThrows(NullPointerException.class, () -> { - GBP_5_78.dividedBy((BigDecimal) null, RoundingMode.DOWN); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> GBP_5_78.dividedBy((BigDecimal) null, RoundingMode.DOWN)); } @Test void test_dividedBy_BigDecimalRoundingMode_nullRoundingMode() { - assertThrows(NullPointerException.class, () -> { - GBP_5_78.dividedBy(new BigDecimal("2.5"), (RoundingMode) null); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> GBP_5_78.dividedBy(new BigDecimal("2.5"), (RoundingMode) null)); } //----------------------------------------------------------------------- @@ -2026,32 +1949,31 @@ void test_dividedBy_BigDecimalRoundingMode_nullRoundingMode() { @Test void test_dividedBy_doubleRoundingMode_one() { Money test = GBP_2_34.dividedBy(1d, RoundingMode.DOWN); - assertSame(GBP_2_34, test); + assertThat(test).isSameAs(GBP_2_34); } @Test void test_dividedBy_doubleRoundingMode_positive() { Money test = GBP_2_34.dividedBy(2.5d, RoundingMode.DOWN); - assertEquals("GBP 0.93", test.toString()); + assertThat(test).hasToString("GBP 0.93"); } @Test void test_dividedBy_doubleRoundingMode_positive_halfUp() { Money test = GBP_2_34.dividedBy(2.5d, RoundingMode.HALF_UP); - assertEquals("GBP 0.94", test.toString()); + assertThat(test).hasToString("GBP 0.94"); } @Test void test_dividedBy_doubleRoundingMode_negative() { Money test = GBP_2_34.dividedBy(-2.5d, RoundingMode.FLOOR); - assertEquals("GBP -0.94", test.toString()); + assertThat(test).hasToString("GBP -0.94"); } @Test void test_dividedBy_doubleRoundingMode_nullRoundingMode() { - assertThrows(NullPointerException.class, () -> { - GBP_5_78.dividedBy(2.5d, (RoundingMode) null); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> GBP_5_78.dividedBy(2.5d, (RoundingMode) null)); } //----------------------------------------------------------------------- @@ -2060,31 +1982,31 @@ void test_dividedBy_doubleRoundingMode_nullRoundingMode() { @Test void test_dividedBy_long_one() { Money test = GBP_2_34.dividedBy(1, RoundingMode.DOWN); - assertSame(GBP_2_34, test); + assertThat(test).isSameAs(GBP_2_34); } @Test void test_dividedBy_long_positive() { Money test = GBP_2_34.dividedBy(3, RoundingMode.DOWN); - assertEquals("GBP 0.78", test.toString()); + assertThat(test).hasToString("GBP 0.78"); } @Test void test_dividedBy_long_positive_roundDown() { Money test = GBP_2_35.dividedBy(3, RoundingMode.DOWN); - assertEquals("GBP 0.78", test.toString()); + assertThat(test).hasToString("GBP 0.78"); } @Test void test_dividedBy_long_positive_roundUp() { Money test = GBP_2_35.dividedBy(3, RoundingMode.UP); - assertEquals("GBP 0.79", test.toString()); + assertThat(test).hasToString("GBP 0.79"); } @Test void test_dividedBy_long_negative() { Money test = GBP_2_34.dividedBy(-3, RoundingMode.DOWN); - assertEquals("GBP -0.78", test.toString()); + assertThat(test).hasToString("GBP -0.78"); } //----------------------------------------------------------------------- @@ -2093,13 +2015,13 @@ void test_dividedBy_long_negative() { @Test void test_negated_positive() { Money test = GBP_2_34.negated(); - assertEquals("GBP -2.34", test.toString()); + assertThat(test).hasToString("GBP -2.34"); } @Test void test_negated_negative() { Money test = Money.parse("GBP -2.34").negated(); - assertEquals("GBP 2.34", test.toString()); + assertThat(test).hasToString("GBP 2.34"); } //----------------------------------------------------------------------- @@ -2108,13 +2030,13 @@ void test_negated_negative() { @Test void test_abs_positive() { Money test = GBP_2_34.abs(); - assertSame(GBP_2_34, test); + assertThat(test).isSameAs(GBP_2_34); } @Test void test_abs_negative() { Money test = Money.parse("GBP -2.34").abs(); - assertEquals("GBP 2.34", test.toString()); + assertThat(test).hasToString("GBP 2.34"); } //----------------------------------------------------------------------- @@ -2123,55 +2045,55 @@ void test_abs_negative() { @Test void test_round_2down() { Money test = GBP_2_34.rounded(2, RoundingMode.DOWN); - assertSame(GBP_2_34, test); + assertThat(test).isSameAs(GBP_2_34); } @Test void test_round_2up() { Money test = GBP_2_34.rounded(2, RoundingMode.DOWN); - assertSame(GBP_2_34, test); + assertThat(test).isSameAs(GBP_2_34); } @Test void test_round_1down() { Money test = GBP_2_34.rounded(1, RoundingMode.DOWN); - assertEquals("GBP 2.30", test.toString()); + assertThat(test).hasToString("GBP 2.30"); } @Test void test_round_1up() { Money test = GBP_2_34.rounded(1, RoundingMode.UP); - assertEquals("GBP 2.40", test.toString()); + assertThat(test).hasToString("GBP 2.40"); } @Test void test_round_0down() { Money test = GBP_2_34.rounded(0, RoundingMode.DOWN); - assertEquals("GBP 2.00", test.toString()); + assertThat(test).hasToString("GBP 2.00"); } @Test void test_round_0up() { Money test = GBP_2_34.rounded(0, RoundingMode.UP); - assertEquals("GBP 3.00", test.toString()); + assertThat(test).hasToString("GBP 3.00"); } @Test void test_round_M1down() { Money test = Money.parse("GBP 432.34").rounded(-1, RoundingMode.DOWN); - assertEquals("GBP 430.00", test.toString()); + assertThat(test).hasToString("GBP 430.00"); } @Test void test_round_M1up() { Money test = Money.parse("GBP 432.34").rounded(-1, RoundingMode.UP); - assertEquals("GBP 440.00", test.toString()); + assertThat(test).hasToString("GBP 440.00"); } @Test void test_round_3() { Money test = GBP_2_34.rounded(3, RoundingMode.DOWN); - assertSame(GBP_2_34, test); + assertThat(test).isSameAs(GBP_2_34); } //----------------------------------------------------------------------- @@ -2180,48 +2102,43 @@ void test_round_3() { @Test void test_convertedTo_BigDecimalRoundingMode_positive() { Money test = GBP_2_33.convertedTo(EUR, new BigDecimal("2.5"), RoundingMode.DOWN); - assertEquals("EUR 5.82", test.toString()); + assertThat(test).hasToString("EUR 5.82"); } @Test 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()); + assertThat(test).hasToString("EUR 5.83"); } @Test void test_convertedTo_BigDecimalRoundingMode_negative() { - assertThrows(IllegalArgumentException.class, () -> { - GBP_2_33.convertedTo(EUR, new BigDecimal("-2.5"), RoundingMode.FLOOR); - }); + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> GBP_2_33.convertedTo(EUR, new BigDecimal("-2.5"), RoundingMode.FLOOR)); } @Test void test_convertedTo_BigDecimalRoundingMode_sameCurrency() { - assertThrows(IllegalArgumentException.class, () -> { - GBP_2_33.convertedTo(GBP, new BigDecimal("2.5"), RoundingMode.DOWN); - }); + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> GBP_2_33.convertedTo(GBP, new BigDecimal("2.5"), RoundingMode.DOWN)); } @Test void test_convertedTo_BigDecimalRoundingMode_nullCurrency() { - assertThrows(NullPointerException.class, () -> { - GBP_5_78.convertedTo((CurrencyUnit) null, new BigDecimal("2"), RoundingMode.DOWN); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> GBP_5_78.convertedTo((CurrencyUnit) null, new BigDecimal("2"), RoundingMode.DOWN)); } @Test void test_convertedTo_BigDecimalRoundingMode_nullBigDecimal() { - assertThrows(NullPointerException.class, () -> { - GBP_5_78.convertedTo(EUR, (BigDecimal) null, RoundingMode.DOWN); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> GBP_5_78.convertedTo(EUR, (BigDecimal) null, RoundingMode.DOWN)); } @Test void test_convertedTo_BigDecimalRoundingMode_nullRoundingMode() { - assertThrows(NullPointerException.class, () -> { - GBP_5_78.convertedTo(EUR, new BigDecimal("2.5"), (RoundingMode) null); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> GBP_5_78.convertedTo(EUR, new BigDecimal("2.5"), (RoundingMode) null)); } //----------------------------------------------------------------------- @@ -2229,7 +2146,7 @@ void test_convertedTo_BigDecimalRoundingMode_nullRoundingMode() { //----------------------------------------------------------------------- @Test void test_toBigMoney() { - assertEquals(BigMoney.ofMinor(GBP, 234), GBP_2_34.toBigMoney()); + assertThat(GBP_2_34.toBigMoney()).isEqualTo(BigMoney.ofMinor(GBP, 234)); } //----------------------------------------------------------------------- @@ -2237,29 +2154,28 @@ void test_toBigMoney() { //----------------------------------------------------------------------- @Test void test_isSameCurrency_Money_same() { - assertTrue(GBP_2_34.isSameCurrency(GBP_2_35)); + assertThat(GBP_2_34.isSameCurrency(GBP_2_35)).isTrue(); } @Test void test_isSameCurrency_Money_different() { - assertFalse(GBP_2_34.isSameCurrency(USD_2_34)); + assertThat(GBP_2_34.isSameCurrency(USD_2_34)).isFalse(); } @Test void test_isSameCurrency_BigMoney_same() { - assertTrue(GBP_2_34.isSameCurrency(BigMoney.parse("GBP 2"))); + assertThat(GBP_2_34.isSameCurrency(BigMoney.parse("GBP 2"))).isTrue(); } @Test void test_isSameCurrency_BigMoney_different() { - assertFalse(GBP_2_34.isSameCurrency(BigMoney.parse("USD 2"))); + assertThat(GBP_2_34.isSameCurrency(BigMoney.parse("USD 2"))).isFalse(); } @Test void test_isSameCurrency_Money_nullMoney() { - assertThrows(NullPointerException.class, () -> { - GBP_2_34.isSameCurrency((Money) null); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> GBP_2_34.isSameCurrency((Money) null)); } //----------------------------------------------------------------------- @@ -2270,18 +2186,18 @@ void test_compareTo_Money() { Money a = GBP_2_34; Money b = GBP_2_35; Money c = GBP_2_36; - assertEquals(0, a.compareTo(a)); - assertEquals(0, b.compareTo(b)); - assertEquals(0, c.compareTo(c)); + assertThat(a.compareTo(a)).isEqualTo(0); + assertThat(b.compareTo(b)).isEqualTo(0); + assertThat(c.compareTo(c)).isEqualTo(0); - assertEquals(-1, a.compareTo(b)); - assertEquals(1, b.compareTo(a)); + assertThat(a.compareTo(b)).isEqualTo(-1); + assertThat(b.compareTo(a)).isEqualTo(1); - assertEquals(-1, a.compareTo(c)); - assertEquals(1, c.compareTo(a)); + assertThat(a.compareTo(c)).isEqualTo(-1); + assertThat(c.compareTo(a)).isEqualTo(1); - assertEquals(-1, b.compareTo(c)); - assertEquals(1, c.compareTo(b)); + assertThat(b.compareTo(c)).isEqualTo(-1); + assertThat(c.compareTo(b)).isEqualTo(1); } @Test @@ -2290,27 +2206,25 @@ void test_compareTo_BigMoney() { BigMoney a = BigMoney.ofMinor(GBP, 234); BigMoney b = BigMoney.ofMinor(GBP, 235); BigMoney c = BigMoney.ofMinor(GBP, 236); - assertEquals(1, t.compareTo(a)); - assertEquals(0, t.compareTo(b)); - assertEquals(-1, t.compareTo(c)); + assertThat(t.compareTo(a)).isEqualTo(1); + assertThat(t.compareTo(b)).isEqualTo(0); + assertThat(t.compareTo(c)).isEqualTo(-1); } @Test void test_compareTo_currenciesDiffer() { Money a = GBP_2_34; Money b = USD_2_35; - assertThrows(CurrencyMismatchException.class, () -> { - a.compareTo(b); - }); + assertThatExceptionOfType(CurrencyMismatchException.class) + .isThrownBy(() -> a.compareTo(b)); } @Test @SuppressWarnings({"unchecked", "rawtypes"}) void test_compareTo_wrongType() { Comparable a = GBP_2_34; - assertThrows(ClassCastException.class, () -> { - a.compareTo("NotRightType"); - }); + assertThatExceptionOfType(ClassCastException.class) + .isThrownBy(() -> a.compareTo("NotRightType")); } //----------------------------------------------------------------------- @@ -2321,34 +2235,33 @@ void test_isEqual() { Money a = GBP_2_34; Money b = GBP_2_35; Money c = GBP_2_36; - assertTrue(a.isEqual(a)); - assertTrue(b.isEqual(b)); - assertTrue(c.isEqual(c)); + assertThat(a.isEqual(a)).isTrue(); + assertThat(b.isEqual(b)).isTrue(); + assertThat(c.isEqual(c)).isTrue(); - assertFalse(a.isEqual(b)); - assertFalse(b.isEqual(a)); + assertThat(a.isEqual(b)).isFalse(); + assertThat(b.isEqual(a)).isFalse(); - assertFalse(a.isEqual(c)); - assertFalse(c.isEqual(a)); + assertThat(a.isEqual(c)).isFalse(); + assertThat(c.isEqual(a)).isFalse(); - assertFalse(b.isEqual(c)); - assertFalse(c.isEqual(b)); + assertThat(b.isEqual(c)).isFalse(); + assertThat(c.isEqual(b)).isFalse(); } @Test void test_isEqual_Money() { Money a = GBP_2_34; BigMoney b = BigMoney.ofMinor(GBP, 234); - assertTrue(a.isEqual(b)); + assertThat(a.isEqual(b)).isTrue(); } @Test void test_isEqual_currenciesDiffer() { Money a = GBP_2_34; Money b = USD_2_35; - assertThrows(CurrencyMismatchException.class, () -> { - a.isEqual(b); - }); + assertThatExceptionOfType(CurrencyMismatchException.class) + .isThrownBy(() -> a.isEqual(b)); } //----------------------------------------------------------------------- @@ -2359,26 +2272,25 @@ void test_isGreaterThan() { Money a = GBP_2_34; Money b = GBP_2_35; Money c = GBP_2_36; - assertFalse(a.isGreaterThan(a)); - assertFalse(a.isGreaterThan(b)); - assertFalse(a.isGreaterThan(c)); + assertThat(a.isGreaterThan(a)).isFalse(); + assertThat(a.isGreaterThan(b)).isFalse(); + assertThat(a.isGreaterThan(c)).isFalse(); - assertTrue(b.isGreaterThan(a)); - assertFalse(b.isGreaterThan(b)); - assertFalse(b.isGreaterThan(c)); + assertThat(b.isGreaterThan(a)).isTrue(); + assertThat(b.isGreaterThan(b)).isFalse(); + assertThat(b.isGreaterThan(c)).isFalse(); - assertTrue(c.isGreaterThan(a)); - assertTrue(c.isGreaterThan(b)); - assertFalse(c.isGreaterThan(c)); + assertThat(c.isGreaterThan(a)).isTrue(); + assertThat(c.isGreaterThan(b)).isTrue(); + assertThat(c.isGreaterThan(c)).isFalse(); } @Test void test_isGreaterThan_currenciesDiffer() { Money a = GBP_2_34; Money b = USD_2_35; - assertThrows(CurrencyMismatchException.class, () -> { - a.isGreaterThan(b); - }); + assertThatExceptionOfType(CurrencyMismatchException.class) + .isThrownBy(() -> a.isGreaterThan(b)); } //----------------------------------------------------------------------- @@ -2389,26 +2301,25 @@ void test_isGreaterThanOrEqual() { Money a = GBP_2_34; Money b = GBP_2_35; Money c = GBP_2_36; - assertTrue(a.isGreaterThanOrEqual(a)); - assertFalse(a.isGreaterThanOrEqual(b)); - assertFalse(a.isGreaterThanOrEqual(c)); + assertThat(a.isGreaterThanOrEqual(a)).isTrue(); + assertThat(a.isGreaterThanOrEqual(b)).isFalse(); + assertThat(a.isGreaterThanOrEqual(c)).isFalse(); - assertTrue(b.isGreaterThanOrEqual(a)); - assertTrue(b.isGreaterThanOrEqual(b)); - assertFalse(b.isGreaterThanOrEqual(c)); + assertThat(b.isGreaterThanOrEqual(a)).isTrue(); + assertThat(b.isGreaterThanOrEqual(b)).isTrue(); + assertThat(b.isGreaterThanOrEqual(c)).isFalse(); - assertTrue(c.isGreaterThanOrEqual(a)); - assertTrue(c.isGreaterThanOrEqual(b)); - assertTrue(c.isGreaterThanOrEqual(c)); + assertThat(c.isGreaterThanOrEqual(a)).isTrue(); + assertThat(c.isGreaterThanOrEqual(b)).isTrue(); + assertThat(c.isGreaterThanOrEqual(c)).isTrue(); } @Test void test_isGreaterThanOrEqual_currenciesDiffer() { Money a = GBP_2_34; Money b = USD_2_35; - assertThrows(CurrencyMismatchException.class, () -> { - a.isGreaterThanOrEqual(b); - }); + assertThatExceptionOfType(CurrencyMismatchException.class) + .isThrownBy(() -> a.isGreaterThanOrEqual(b)); } //----------------------------------------------------------------------- @@ -2419,26 +2330,25 @@ void test_isLessThan() { Money a = GBP_2_34; Money b = GBP_2_35; Money c = GBP_2_36; - assertFalse(a.isLessThan(a)); - assertTrue(a.isLessThan(b)); - assertTrue(a.isLessThan(c)); + assertThat(a.isLessThan(a)).isFalse(); + assertThat(a.isLessThan(b)).isTrue(); + assertThat(a.isLessThan(c)).isTrue(); - assertFalse(b.isLessThan(a)); - assertFalse(b.isLessThan(b)); - assertTrue(b.isLessThan(c)); + assertThat(b.isLessThan(a)).isFalse(); + assertThat(b.isLessThan(b)).isFalse(); + assertThat(b.isLessThan(c)).isTrue(); - assertFalse(c.isLessThan(a)); - assertFalse(c.isLessThan(b)); - assertFalse(c.isLessThan(c)); + assertThat(c.isLessThan(a)).isFalse(); + assertThat(c.isLessThan(b)).isFalse(); + assertThat(c.isLessThan(c)).isFalse(); } @Test void test_isLessThan_currenciesDiffer() { Money a = GBP_2_34; Money b = USD_2_35; - assertThrows(CurrencyMismatchException.class, () -> { - a.isLessThan(b); - }); + assertThatExceptionOfType(CurrencyMismatchException.class) + .isThrownBy(() -> a.isLessThan(b)); } //----------------------------------------------------------------------- @@ -2449,26 +2359,25 @@ void test_isLessThanOrEqual() { Money a = GBP_2_34; Money b = GBP_2_35; Money c = GBP_2_36; - assertTrue(a.isLessThanOrEqual(a)); - assertTrue(a.isLessThanOrEqual(b)); - assertTrue(a.isLessThanOrEqual(c)); + assertThat(a.isLessThanOrEqual(a)).isTrue(); + assertThat(a.isLessThanOrEqual(b)).isTrue(); + assertThat(a.isLessThanOrEqual(c)).isTrue(); - assertFalse(b.isLessThanOrEqual(a)); - assertTrue(b.isLessThanOrEqual(b)); - assertTrue(b.isLessThanOrEqual(c)); + assertThat(b.isLessThanOrEqual(a)).isFalse(); + assertThat(b.isLessThanOrEqual(b)).isTrue(); + assertThat(b.isLessThanOrEqual(c)).isTrue(); - assertFalse(c.isLessThanOrEqual(a)); - assertFalse(c.isLessThanOrEqual(b)); - assertTrue(c.isLessThanOrEqual(c)); + assertThat(c.isLessThanOrEqual(a)).isFalse(); + assertThat(c.isLessThanOrEqual(b)).isFalse(); + assertThat(c.isLessThanOrEqual(c)).isTrue(); } @Test void test_isLessThanOrEqual_currenciesDiffer() { Money a = GBP_2_34; Money b = USD_2_35; - assertThrows(CurrencyMismatchException.class, () -> { - a.isLessThanOrEqual(b); - }); + assertThatExceptionOfType(CurrencyMismatchException.class) + .isThrownBy(() -> a.isLessThanOrEqual(b)); } //----------------------------------------------------------------------- @@ -2479,23 +2388,23 @@ void test_equals_hashCode_positive() { Money a = GBP_2_34; Money b = GBP_2_34; Money c = GBP_2_35; - assertTrue(a.equals(a)); - assertTrue(b.equals(b)); - assertTrue(c.equals(c)); + assertThat(a).isEqualTo(a); + assertThat(b).isEqualTo(b); + assertThat(c).isEqualTo(c); - assertTrue(a.equals(b)); - assertTrue(b.equals(a)); - assertTrue(a.hashCode() == b.hashCode()); + assertThat(b).isEqualTo(a); + assertThat(a).isEqualTo(b); + assertThat(b.hashCode()).isEqualTo(a.hashCode()); - assertFalse(a.equals(c)); - assertFalse(b.equals(c)); + assertThat(c).isNotEqualTo(a); + assertThat(c).isNotEqualTo(b); } @Test void test_equals_false() { Money a = GBP_2_34; - assertFalse(a.equals(null)); - assertFalse(a.equals(new Object())); + assertThat(a).isNotEqualTo(null); + assertThat(new Object()).isNotEqualTo(a); } //----------------------------------------------------------------------- @@ -2504,13 +2413,13 @@ void test_equals_false() { @Test void test_toString_positive() { Money test = Money.of(GBP, BIGDEC_2_34); - assertEquals("GBP 2.34", test.toString()); + assertThat(test).hasToString("GBP 2.34"); } @Test void test_toString_negative() { Money test = Money.of(EUR, BIGDEC_M5_78); - assertEquals("EUR -5.78", test.toString()); + assertThat(test).hasToString("EUR -5.78"); } } diff --git a/src/test/java/org/joda/money/TestMoneyUtils_BigMoney.java b/src/test/java/org/joda/money/TestMoneyUtils_BigMoney.java index 93dd899..260a0b6 100644 --- a/src/test/java/org/joda/money/TestMoneyUtils_BigMoney.java +++ b/src/test/java/org/joda/money/TestMoneyUtils_BigMoney.java @@ -15,12 +15,8 @@ */ package org.joda.money; -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 static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType; import java.lang.reflect.Constructor; import java.lang.reflect.Modifier; @@ -46,7 +42,7 @@ class TestMoneyUtils_BigMoney { @Test void test_constructor() throws Exception { Constructor con = MoneyUtils.class.getDeclaredConstructor(); - assertTrue(Modifier.isPrivate(con.getModifiers())); + assertThat(Modifier.isPrivate(con.getModifiers())).isTrue(); con.setAccessible(true); con.newInstance(); } @@ -56,10 +52,10 @@ void test_constructor() throws Exception { //----------------------------------------------------------------------- @Test void test_isZero() { - assertTrue(MoneyUtils.isZero(null)); - assertTrue(MoneyUtils.isZero(GBP_0)); - assertFalse(MoneyUtils.isZero(GBP_30)); - assertFalse(MoneyUtils.isZero(GBP_M30)); + assertThat(MoneyUtils.isZero(null)).isTrue(); + assertThat(MoneyUtils.isZero(GBP_0)).isTrue(); + assertThat(MoneyUtils.isZero(GBP_30)).isFalse(); + assertThat(MoneyUtils.isZero(GBP_M30)).isFalse(); } //----------------------------------------------------------------------- @@ -67,10 +63,10 @@ void test_isZero() { //----------------------------------------------------------------------- @Test void test_isPositive() { - assertFalse(MoneyUtils.isPositive(null)); - assertFalse(MoneyUtils.isPositive(GBP_0)); - assertTrue(MoneyUtils.isPositive(GBP_30)); - assertFalse(MoneyUtils.isPositive(GBP_M30)); + assertThat(MoneyUtils.isPositive(null)).isFalse(); + assertThat(MoneyUtils.isPositive(GBP_0)).isFalse(); + assertThat(MoneyUtils.isPositive(GBP_30)).isTrue(); + assertThat(MoneyUtils.isPositive(GBP_M30)).isFalse(); } //----------------------------------------------------------------------- @@ -78,10 +74,10 @@ void test_isPositive() { //----------------------------------------------------------------------- @Test void test_isPositiveOrZero() { - assertTrue(MoneyUtils.isPositiveOrZero(null)); - assertTrue(MoneyUtils.isPositiveOrZero(GBP_0)); - assertTrue(MoneyUtils.isPositiveOrZero(GBP_30)); - assertFalse(MoneyUtils.isPositiveOrZero(GBP_M30)); + assertThat(MoneyUtils.isPositiveOrZero(null)).isTrue(); + assertThat(MoneyUtils.isPositiveOrZero(GBP_0)).isTrue(); + assertThat(MoneyUtils.isPositiveOrZero(GBP_30)).isTrue(); + assertThat(MoneyUtils.isPositiveOrZero(GBP_M30)).isFalse(); } //----------------------------------------------------------------------- @@ -89,10 +85,10 @@ void test_isPositiveOrZero() { //----------------------------------------------------------------------- @Test void test_isNegative() { - assertFalse(MoneyUtils.isNegative(null)); - assertFalse(MoneyUtils.isNegative(GBP_0)); - assertFalse(MoneyUtils.isNegative(GBP_30)); - assertTrue(MoneyUtils.isNegative(GBP_M30)); + assertThat(MoneyUtils.isNegative(null)).isFalse(); + assertThat(MoneyUtils.isNegative(GBP_0)).isFalse(); + assertThat(MoneyUtils.isNegative(GBP_30)).isFalse(); + assertThat(MoneyUtils.isNegative(GBP_M30)).isTrue(); } //----------------------------------------------------------------------- @@ -100,10 +96,10 @@ void test_isNegative() { //----------------------------------------------------------------------- @Test void test_isNegativeOrZero() { - assertTrue(MoneyUtils.isNegativeOrZero(null)); - assertTrue(MoneyUtils.isNegativeOrZero(GBP_0)); - assertFalse(MoneyUtils.isNegativeOrZero(GBP_30)); - assertTrue(MoneyUtils.isNegativeOrZero(GBP_M30)); + assertThat(MoneyUtils.isNegativeOrZero(null)).isTrue(); + assertThat(MoneyUtils.isNegativeOrZero(GBP_0)).isTrue(); + assertThat(MoneyUtils.isNegativeOrZero(GBP_30)).isFalse(); + assertThat(MoneyUtils.isNegativeOrZero(GBP_M30)).isTrue(); } //----------------------------------------------------------------------- @@ -111,34 +107,33 @@ void test_isNegativeOrZero() { //----------------------------------------------------------------------- @Test void test_max1() { - assertSame(GBP_30, MoneyUtils.max(GBP_20, GBP_30)); + assertThat(MoneyUtils.max(GBP_20, GBP_30)).isSameAs(GBP_30); } @Test void test_max2() { - assertSame(GBP_30, MoneyUtils.max(GBP_30, GBP_20)); + assertThat(MoneyUtils.max(GBP_30, GBP_20)).isSameAs(GBP_30); } @Test void test_max_differentCurrencies() { - assertThrows(CurrencyMismatchException.class, () -> { - MoneyUtils.max(GBP_20, EUR_30); - }); + assertThatExceptionOfType(CurrencyMismatchException.class) + .isThrownBy(() -> MoneyUtils.max(GBP_20, EUR_30)); } @Test void test_max_null1() { - assertSame(GBP_30, MoneyUtils.max((BigMoney) null, GBP_30)); + assertThat(MoneyUtils.max((BigMoney) null, GBP_30)).isSameAs(GBP_30); } @Test void test_max_null2() { - assertSame(GBP_20, MoneyUtils.max(GBP_20, (BigMoney) null)); + assertThat(MoneyUtils.max(GBP_20, (BigMoney) null)).isSameAs(GBP_20); } @Test void test_max_nullBoth() { - assertNull(MoneyUtils.max((BigMoney) null, (BigMoney) null)); + assertThat(MoneyUtils.max((BigMoney) null, (BigMoney) null)).isNull(); } //----------------------------------------------------------------------- @@ -146,34 +141,33 @@ void test_max_nullBoth() { //----------------------------------------------------------------------- @Test void test_min1() { - assertSame(GBP_20, MoneyUtils.min(GBP_20, GBP_30)); + assertThat(MoneyUtils.min(GBP_20, GBP_30)).isSameAs(GBP_20); } @Test void test_min2() { - assertSame(GBP_20, MoneyUtils.min(GBP_30, GBP_20)); + assertThat(MoneyUtils.min(GBP_30, GBP_20)).isSameAs(GBP_20); } @Test void test_min_differentCurrencies() { - assertThrows(CurrencyMismatchException.class, () -> { - MoneyUtils.min(GBP_20, EUR_30); - }); + assertThatExceptionOfType(CurrencyMismatchException.class) + .isThrownBy(() -> MoneyUtils.min(GBP_20, EUR_30)); } @Test void test_min_null1() { - assertSame(GBP_30, MoneyUtils.min((BigMoney) null, GBP_30)); + assertThat(MoneyUtils.min((BigMoney) null, GBP_30)).isSameAs(GBP_30); } @Test void test_min_null2() { - assertSame(GBP_20, MoneyUtils.min(GBP_20, (BigMoney) null)); + assertThat(MoneyUtils.min(GBP_20, (BigMoney) null)).isSameAs(GBP_20); } @Test void test_min_nullBoth() { - assertNull(MoneyUtils.min((BigMoney) null, (BigMoney) null)); + assertThat(MoneyUtils.min((BigMoney) null, (BigMoney) null)).isNull(); } //----------------------------------------------------------------------- @@ -181,29 +175,28 @@ void test_min_nullBoth() { //----------------------------------------------------------------------- @Test void test_add() { - assertEquals(GBP_50, MoneyUtils.add(GBP_20, GBP_30)); + assertThat(MoneyUtils.add(GBP_20, GBP_30)).isEqualTo(GBP_50); } @Test void test_add_differentCurrencies() { - assertThrows(CurrencyMismatchException.class, () -> { - MoneyUtils.add(GBP_20, EUR_30); - }); + assertThatExceptionOfType(CurrencyMismatchException.class) + .isThrownBy(() -> MoneyUtils.add(GBP_20, EUR_30)); } @Test void test_add_null1() { - assertSame(GBP_30, MoneyUtils.add((BigMoney) null, GBP_30)); + assertThat(MoneyUtils.add((BigMoney) null, GBP_30)).isSameAs(GBP_30); } @Test void test_add_null2() { - assertSame(GBP_20, MoneyUtils.add(GBP_20, (BigMoney) null)); + assertThat(MoneyUtils.add(GBP_20, (BigMoney) null)).isSameAs(GBP_20); } @Test void test_add_nullBoth() { - assertNull(MoneyUtils.add((BigMoney) null, (BigMoney) null)); + assertThat(MoneyUtils.add((BigMoney) null, (BigMoney) null)).isNull(); } //----------------------------------------------------------------------- @@ -211,29 +204,28 @@ void test_add_nullBoth() { //----------------------------------------------------------------------- @Test void test_subtract() { - assertEquals(GBP_M10, MoneyUtils.subtract(GBP_20, GBP_30)); + assertThat(MoneyUtils.subtract(GBP_20, GBP_30)).isEqualTo(GBP_M10); } @Test void test_subtract_differentCurrencies() { - assertThrows(CurrencyMismatchException.class, () -> { - MoneyUtils.subtract(GBP_20, EUR_30); - }); + assertThatExceptionOfType(CurrencyMismatchException.class) + .isThrownBy(() -> MoneyUtils.subtract(GBP_20, EUR_30)); } @Test void test_subtract_null1() { - assertEquals(GBP_M30, MoneyUtils.subtract((BigMoney) null, GBP_30)); + assertThat(MoneyUtils.subtract((BigMoney) null, GBP_30)).isEqualTo(GBP_M30); } @Test void test_subtract_null2() { - assertSame(GBP_20, MoneyUtils.subtract(GBP_20, (BigMoney) null)); + assertThat(MoneyUtils.subtract(GBP_20, (BigMoney) null)).isSameAs(GBP_20); } @Test void test_subtract_nullBoth() { - assertNull(MoneyUtils.subtract((BigMoney) null, (BigMoney) null)); + assertThat(MoneyUtils.subtract((BigMoney) null, (BigMoney) null)).isNull(); } } diff --git a/src/test/java/org/joda/money/TestMoneyUtils_Money.java b/src/test/java/org/joda/money/TestMoneyUtils_Money.java index a0a9e30..4b69969 100644 --- a/src/test/java/org/joda/money/TestMoneyUtils_Money.java +++ b/src/test/java/org/joda/money/TestMoneyUtils_Money.java @@ -15,12 +15,8 @@ */ package org.joda.money; -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 static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType; import org.junit.jupiter.api.Test; @@ -47,14 +43,9 @@ void test_checkNotNull_notNull() { @Test void test_checkNotNull_null() { - assertThrows(NullPointerException.class, () -> { - try { - MoneyUtils.checkNotNull(null, "Hello"); - } catch (NullPointerException ex) { - assertEquals("Hello", ex.getMessage()); - throw ex; - } - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> MoneyUtils.checkNotNull(null, "Hello")) + .withMessage("Hello"); } //----------------------------------------------------------------------- @@ -62,10 +53,10 @@ void test_checkNotNull_null() { //----------------------------------------------------------------------- @Test void test_isZero() { - assertTrue(MoneyUtils.isZero(null)); - assertTrue(MoneyUtils.isZero(GBP_0)); - assertFalse(MoneyUtils.isZero(GBP_30)); - assertFalse(MoneyUtils.isZero(GBP_M30)); + assertThat(MoneyUtils.isZero(null)).isTrue(); + assertThat(MoneyUtils.isZero(GBP_0)).isTrue(); + assertThat(MoneyUtils.isZero(GBP_30)).isFalse(); + assertThat(MoneyUtils.isZero(GBP_M30)).isFalse(); } //----------------------------------------------------------------------- @@ -73,10 +64,10 @@ void test_isZero() { //----------------------------------------------------------------------- @Test void test_isPositive() { - assertFalse(MoneyUtils.isPositive(null)); - assertFalse(MoneyUtils.isPositive(GBP_0)); - assertTrue(MoneyUtils.isPositive(GBP_30)); - assertFalse(MoneyUtils.isPositive(GBP_M30)); + assertThat(MoneyUtils.isPositive(null)).isFalse(); + assertThat(MoneyUtils.isPositive(GBP_0)).isFalse(); + assertThat(MoneyUtils.isPositive(GBP_30)).isTrue(); + assertThat(MoneyUtils.isPositive(GBP_M30)).isFalse(); } //----------------------------------------------------------------------- @@ -84,10 +75,10 @@ void test_isPositive() { //----------------------------------------------------------------------- @Test void test_isPositiveOrZero() { - assertTrue(MoneyUtils.isPositiveOrZero(null)); - assertTrue(MoneyUtils.isPositiveOrZero(GBP_0)); - assertTrue(MoneyUtils.isPositiveOrZero(GBP_30)); - assertFalse(MoneyUtils.isPositiveOrZero(GBP_M30)); + assertThat(MoneyUtils.isPositiveOrZero(null)).isTrue(); + assertThat(MoneyUtils.isPositiveOrZero(GBP_0)).isTrue(); + assertThat(MoneyUtils.isPositiveOrZero(GBP_30)).isTrue(); + assertThat(MoneyUtils.isPositiveOrZero(GBP_M30)).isFalse(); } //----------------------------------------------------------------------- @@ -95,10 +86,10 @@ void test_isPositiveOrZero() { //----------------------------------------------------------------------- @Test void test_isNegative() { - assertFalse(MoneyUtils.isNegative(null)); - assertFalse(MoneyUtils.isNegative(GBP_0)); - assertFalse(MoneyUtils.isNegative(GBP_30)); - assertTrue(MoneyUtils.isNegative(GBP_M30)); + assertThat(MoneyUtils.isNegative(null)).isFalse(); + assertThat(MoneyUtils.isNegative(GBP_0)).isFalse(); + assertThat(MoneyUtils.isNegative(GBP_30)).isFalse(); + assertThat(MoneyUtils.isNegative(GBP_M30)).isTrue(); } //----------------------------------------------------------------------- @@ -106,10 +97,10 @@ void test_isNegative() { //----------------------------------------------------------------------- @Test void test_isNegativeOrZero() { - assertTrue(MoneyUtils.isNegativeOrZero(null)); - assertTrue(MoneyUtils.isNegativeOrZero(GBP_0)); - assertFalse(MoneyUtils.isNegativeOrZero(GBP_30)); - assertTrue(MoneyUtils.isNegativeOrZero(GBP_M30)); + assertThat(MoneyUtils.isNegativeOrZero(null)).isTrue(); + assertThat(MoneyUtils.isNegativeOrZero(GBP_0)).isTrue(); + assertThat(MoneyUtils.isNegativeOrZero(GBP_30)).isFalse(); + assertThat(MoneyUtils.isNegativeOrZero(GBP_M30)).isTrue(); } //----------------------------------------------------------------------- @@ -117,34 +108,33 @@ void test_isNegativeOrZero() { //----------------------------------------------------------------------- @Test void test_max1() { - assertSame(GBP_30, MoneyUtils.max(GBP_20, GBP_30)); + assertThat(MoneyUtils.max(GBP_20, GBP_30)).isSameAs(GBP_30); } @Test void test_max2() { - assertSame(GBP_30, MoneyUtils.max(GBP_30, GBP_20)); + assertThat(MoneyUtils.max(GBP_30, GBP_20)).isSameAs(GBP_30); } @Test void test_max_differentCurrencies() { - assertThrows(CurrencyMismatchException.class, () -> { - MoneyUtils.max(GBP_20, EUR_30); - }); + assertThatExceptionOfType(CurrencyMismatchException.class) + .isThrownBy(() -> MoneyUtils.max(GBP_20, EUR_30)); } @Test void test_max_null1() { - assertSame(GBP_30, MoneyUtils.max((Money) null, GBP_30)); + assertThat(MoneyUtils.max((Money) null, GBP_30)).isSameAs(GBP_30); } @Test void test_max_null2() { - assertSame(GBP_20, MoneyUtils.max(GBP_20, (Money) null)); + assertThat(MoneyUtils.max(GBP_20, (Money) null)).isSameAs(GBP_20); } @Test void test_max_nullBoth() { - assertNull(MoneyUtils.max((Money) null, (Money) null)); + assertThat(MoneyUtils.max((Money) null, (Money) null)).isNull(); } //----------------------------------------------------------------------- @@ -152,34 +142,33 @@ void test_max_nullBoth() { //----------------------------------------------------------------------- @Test void test_min1() { - assertSame(GBP_20, MoneyUtils.min(GBP_20, GBP_30)); + assertThat(MoneyUtils.min(GBP_20, GBP_30)).isSameAs(GBP_20); } @Test void test_min2() { - assertSame(GBP_20, MoneyUtils.min(GBP_30, GBP_20)); + assertThat(MoneyUtils.min(GBP_30, GBP_20)).isSameAs(GBP_20); } @Test void test_min_differentCurrencies() { - assertThrows(CurrencyMismatchException.class, () -> { - MoneyUtils.min(GBP_20, EUR_30); - }); + assertThatExceptionOfType(CurrencyMismatchException.class) + .isThrownBy(() -> MoneyUtils.min(GBP_20, EUR_30)); } @Test void test_min_null1() { - assertSame(GBP_30, MoneyUtils.min((Money) null, GBP_30)); + assertThat(MoneyUtils.min((Money) null, GBP_30)).isSameAs(GBP_30); } @Test void test_min_null2() { - assertSame(GBP_20, MoneyUtils.min(GBP_20, (Money) null)); + assertThat(MoneyUtils.min(GBP_20, (Money) null)).isSameAs(GBP_20); } @Test void test_min_nullBoth() { - assertNull(MoneyUtils.min((Money) null, (Money) null)); + assertThat(MoneyUtils.min((Money) null, (Money) null)).isNull(); } //----------------------------------------------------------------------- @@ -187,29 +176,28 @@ void test_min_nullBoth() { //----------------------------------------------------------------------- @Test void test_add() { - assertEquals(GBP_50, MoneyUtils.add(GBP_20, GBP_30)); + assertThat(MoneyUtils.add(GBP_20, GBP_30)).isEqualTo(GBP_50); } @Test void test_add_differentCurrencies() { - assertThrows(CurrencyMismatchException.class, () -> { - MoneyUtils.add(GBP_20, EUR_30); - }); + assertThatExceptionOfType(CurrencyMismatchException.class) + .isThrownBy(() -> MoneyUtils.add(GBP_20, EUR_30)); } @Test void test_add_null1() { - assertSame(GBP_30, MoneyUtils.add((Money) null, GBP_30)); + assertThat(MoneyUtils.add((Money) null, GBP_30)).isSameAs(GBP_30); } @Test void test_add_null2() { - assertSame(GBP_20, MoneyUtils.add(GBP_20, (Money) null)); + assertThat(MoneyUtils.add(GBP_20, (Money) null)).isSameAs(GBP_20); } @Test void test_add_nullBoth() { - assertNull(MoneyUtils.add((Money) null, (Money) null)); + assertThat(MoneyUtils.add((Money) null, (Money) null)).isNull(); } //----------------------------------------------------------------------- @@ -217,29 +205,28 @@ void test_add_nullBoth() { //----------------------------------------------------------------------- @Test void test_subtract() { - assertEquals(GBP_M10, MoneyUtils.subtract(GBP_20, GBP_30)); + assertThat(MoneyUtils.subtract(GBP_20, GBP_30)).isEqualTo(GBP_M10); } @Test void test_subtract_differentCurrencies() { - assertThrows(CurrencyMismatchException.class, () -> { - MoneyUtils.subtract(GBP_20, EUR_30); - }); + assertThatExceptionOfType(CurrencyMismatchException.class) + .isThrownBy(() -> MoneyUtils.subtract(GBP_20, EUR_30)); } @Test void test_subtract_null1() { - assertEquals(GBP_M30, MoneyUtils.subtract((Money) null, GBP_30)); + assertThat(MoneyUtils.subtract((Money) null, GBP_30)).isEqualTo(GBP_M30); } @Test void test_subtract_null2() { - assertSame(GBP_20, MoneyUtils.subtract(GBP_20, (Money) null)); + assertThat(MoneyUtils.subtract(GBP_20, (Money) null)).isSameAs(GBP_20); } @Test void test_subtract_nullBoth() { - assertNull(MoneyUtils.subtract((Money) null, (Money) null)); + assertThat(MoneyUtils.subtract((Money) null, (Money) null)).isNull(); } } diff --git a/src/test/java/org/joda/money/TestStringConvert.java b/src/test/java/org/joda/money/TestStringConvert.java index 6d00e99..d049394 100644 --- a/src/test/java/org/joda/money/TestStringConvert.java +++ b/src/test/java/org/joda/money/TestStringConvert.java @@ -15,7 +15,7 @@ */ package org.joda.money; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import org.joda.convert.StringConvert; @@ -30,24 +30,24 @@ class TestStringConvert { void test_BigMoney() { BigMoney test = BigMoney.of(CurrencyUnit.CHF, 1234.5678d); String str = StringConvert.INSTANCE.convertToString(test); - assertEquals("CHF 1234.5678", str); - assertEquals(test, StringConvert.INSTANCE.convertFromString(BigMoney.class, str)); + assertThat(str).isEqualTo("CHF 1234.5678"); + assertThat(StringConvert.INSTANCE.convertFromString(BigMoney.class, str)).isEqualTo(test); } @Test void test_Money() { Money test = Money.of(CurrencyUnit.CHF, 1234.56d); String str = StringConvert.INSTANCE.convertToString(test); - assertEquals("CHF 1234.56", str); - assertEquals(test, StringConvert.INSTANCE.convertFromString(Money.class, str)); + assertThat(str).isEqualTo("CHF 1234.56"); + assertThat(StringConvert.INSTANCE.convertFromString(Money.class, str)).isEqualTo(test); } @Test void test_CurrencyUnit() { CurrencyUnit test = CurrencyUnit.CHF; String str = StringConvert.INSTANCE.convertToString(test); - assertEquals("CHF", str); - assertEquals(test, StringConvert.INSTANCE.convertFromString(CurrencyUnit.class, str)); + assertThat(str).isEqualTo("CHF"); + assertThat(StringConvert.INSTANCE.convertFromString(CurrencyUnit.class, str)).isEqualTo(test); } } diff --git a/src/test/java/org/joda/money/format/TestMoneyAmountStyle.java b/src/test/java/org/joda/money/format/TestMoneyAmountStyle.java index 92435f4..0615738 100644 --- a/src/test/java/org/joda/money/format/TestMoneyAmountStyle.java +++ b/src/test/java/org/joda/money/format/TestMoneyAmountStyle.java @@ -15,12 +15,8 @@ */ package org.joda.money.format; -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 static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType; import java.math.BigDecimal; import java.util.Locale; @@ -58,176 +54,176 @@ void afterMethod() { @Test void test_ASCII_DECIMAL_POINT_GROUP3_COMMA() { MoneyAmountStyle style = MoneyAmountStyle.ASCII_DECIMAL_POINT_GROUP3_COMMA; - assertEquals((Character) '0', style.getZeroCharacter()); - assertEquals((Character) '+', style.getPositiveSignCharacter()); - assertEquals((Character) '-', style.getNegativeSignCharacter()); - assertEquals((Character) '.', style.getDecimalPointCharacter()); - assertEquals((Character) ',', style.getGroupingCharacter()); - assertEquals(GroupingStyle.FULL, style.getGroupingStyle()); - assertEquals((Integer) 3, style.getGroupingSize()); - assertEquals((Integer) 0, style.getExtendedGroupingSize()); - assertFalse(style.isForcedDecimalPoint()); + assertThat(style.getZeroCharacter()).isEqualTo((Character) '0'); + assertThat(style.getPositiveSignCharacter()).isEqualTo((Character) '+'); + assertThat(style.getNegativeSignCharacter()).isEqualTo((Character) '-'); + assertThat(style.getDecimalPointCharacter()).isEqualTo((Character) '.'); + assertThat(style.getGroupingCharacter()).isEqualTo((Character) ','); + assertThat(style.getGroupingStyle()).isEqualTo(GroupingStyle.FULL); + assertThat(style.getGroupingSize()).isEqualTo((Integer) 3); + assertThat(style.getExtendedGroupingSize()).isEqualTo((Integer) 0); + assertThat(style.isForcedDecimalPoint()).isFalse(); } @Test 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)); + assertThat(test.print(MONEY)).isEqualTo("87,654,321.123,456,78"); } @Test void test_ASCII_DECIMAL_POINT_GROUP3_SPACE() { MoneyAmountStyle style = MoneyAmountStyle.ASCII_DECIMAL_POINT_GROUP3_SPACE; - assertEquals((Character) '0', style.getZeroCharacter()); - assertEquals((Character) '+', style.getPositiveSignCharacter()); - assertEquals((Character) '-', style.getNegativeSignCharacter()); - assertEquals((Character) '.', style.getDecimalPointCharacter()); - assertEquals((Character) ' ', style.getGroupingCharacter()); - assertEquals(GroupingStyle.FULL, style.getGroupingStyle()); - assertEquals((Integer) 3, style.getGroupingSize()); - assertEquals((Integer) 0, style.getExtendedGroupingSize()); - assertFalse(style.isForcedDecimalPoint()); + assertThat(style.getZeroCharacter()).isEqualTo((Character) '0'); + assertThat(style.getPositiveSignCharacter()).isEqualTo((Character) '+'); + assertThat(style.getNegativeSignCharacter()).isEqualTo((Character) '-'); + assertThat(style.getDecimalPointCharacter()).isEqualTo((Character) '.'); + assertThat(style.getGroupingCharacter()).isEqualTo((Character) ' '); + assertThat(style.getGroupingStyle()).isEqualTo(GroupingStyle.FULL); + assertThat(style.getGroupingSize()).isEqualTo((Integer) 3); + assertThat(style.getExtendedGroupingSize()).isEqualTo((Integer) 0); + assertThat(style.isForcedDecimalPoint()).isFalse(); } @Test 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)); + assertThat(test.print(MONEY)).isEqualTo("87 654 321.123 456 78"); } @Test void test_ASCII_DECIMAL_POINT_NO_GROUPING() { MoneyAmountStyle style = MoneyAmountStyle.ASCII_DECIMAL_POINT_NO_GROUPING; - assertEquals((Character) '0', style.getZeroCharacter()); - assertEquals((Character) '+', style.getPositiveSignCharacter()); - assertEquals((Character) '-', style.getNegativeSignCharacter()); - assertEquals((Character) '.', style.getDecimalPointCharacter()); - assertEquals((Character) ',', style.getGroupingCharacter()); - assertEquals(GroupingStyle.NONE, style.getGroupingStyle()); - assertEquals((Integer) 3, style.getGroupingSize()); - assertEquals((Integer) 0, style.getExtendedGroupingSize()); - assertFalse(style.isForcedDecimalPoint()); + assertThat(style.getZeroCharacter()).isEqualTo((Character) '0'); + assertThat(style.getPositiveSignCharacter()).isEqualTo((Character) '+'); + assertThat(style.getNegativeSignCharacter()).isEqualTo((Character) '-'); + assertThat(style.getDecimalPointCharacter()).isEqualTo((Character) '.'); + assertThat(style.getGroupingCharacter()).isEqualTo((Character) ','); + assertThat(style.getGroupingStyle()).isEqualTo(GroupingStyle.NONE); + assertThat(style.getGroupingSize()).isEqualTo((Integer) 3); + assertThat(style.getExtendedGroupingSize()).isEqualTo((Integer) 0); + assertThat(style.isForcedDecimalPoint()).isFalse(); } @Test 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)); + assertThat(test.print(MONEY)).isEqualTo("87654321.12345678"); } @Test 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()); - assertEquals((Character) '-', style.getNegativeSignCharacter()); - assertEquals((Character) ',', style.getDecimalPointCharacter()); - assertEquals((Character) '.', style.getGroupingCharacter()); - assertEquals(GroupingStyle.FULL, style.getGroupingStyle()); - assertEquals((Integer) 3, style.getGroupingSize()); - assertEquals((Integer) 0, style.getExtendedGroupingSize()); - assertFalse(style.isForcedDecimalPoint()); + assertThat(style.getZeroCharacter()).isEqualTo((Character) '0'); + assertThat(style.getPositiveSignCharacter()).isEqualTo((Character) '+'); + assertThat(style.getNegativeSignCharacter()).isEqualTo((Character) '-'); + assertThat(style.getDecimalPointCharacter()).isEqualTo((Character) ','); + assertThat(style.getGroupingCharacter()).isEqualTo((Character) '.'); + assertThat(style.getGroupingStyle()).isEqualTo(GroupingStyle.FULL); + assertThat(style.getGroupingSize()).isEqualTo((Integer) 3); + assertThat(style.getExtendedGroupingSize()).isEqualTo((Integer) 0); + assertThat(style.isForcedDecimalPoint()).isFalse(); } @Test 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)); + assertThat(test.print(MONEY)).isEqualTo("87.654.321,123.456.78"); } @Test void test_ASCII_DECIMAL_COMMA_GROUP3_SPACE() { MoneyAmountStyle style = MoneyAmountStyle.ASCII_DECIMAL_COMMA_GROUP3_SPACE; - assertEquals((Character) '0', style.getZeroCharacter()); - assertEquals((Character) '+', style.getPositiveSignCharacter()); - assertEquals((Character) '-', style.getNegativeSignCharacter()); - assertEquals((Character) ',', style.getDecimalPointCharacter()); - assertEquals((Character) ' ', style.getGroupingCharacter()); - assertEquals(GroupingStyle.FULL, style.getGroupingStyle()); - assertEquals((Integer) 3, style.getGroupingSize()); - assertEquals((Integer) 0, style.getExtendedGroupingSize()); - assertFalse(style.isForcedDecimalPoint()); + assertThat(style.getZeroCharacter()).isEqualTo((Character) '0'); + assertThat(style.getPositiveSignCharacter()).isEqualTo((Character) '+'); + assertThat(style.getNegativeSignCharacter()).isEqualTo((Character) '-'); + assertThat(style.getDecimalPointCharacter()).isEqualTo((Character) ','); + assertThat(style.getGroupingCharacter()).isEqualTo((Character) ' '); + assertThat(style.getGroupingStyle()).isEqualTo(GroupingStyle.FULL); + assertThat(style.getGroupingSize()).isEqualTo((Integer) 3); + assertThat(style.getExtendedGroupingSize()).isEqualTo((Integer) 0); + assertThat(style.isForcedDecimalPoint()).isFalse(); } @Test 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)); + assertThat(test.print(MONEY)).isEqualTo("87 654 321,123 456 78"); } @Test void test_ASCII_DECIMAL_COMMA_NO_GROUPING() { MoneyAmountStyle style = MoneyAmountStyle.ASCII_DECIMAL_COMMA_NO_GROUPING; - assertEquals((Character) '0', style.getZeroCharacter()); - assertEquals((Character) '+', style.getPositiveSignCharacter()); - assertEquals((Character) '-', style.getNegativeSignCharacter()); - assertEquals((Character) ',', style.getDecimalPointCharacter()); - assertEquals((Character) '.', style.getGroupingCharacter()); - assertEquals(GroupingStyle.NONE, style.getGroupingStyle()); - assertEquals((Integer) 3, style.getGroupingSize()); - assertEquals((Integer) 0, style.getExtendedGroupingSize()); - assertFalse(style.isForcedDecimalPoint()); + assertThat(style.getZeroCharacter()).isEqualTo((Character) '0'); + assertThat(style.getPositiveSignCharacter()).isEqualTo((Character) '+'); + assertThat(style.getNegativeSignCharacter()).isEqualTo((Character) '-'); + assertThat(style.getDecimalPointCharacter()).isEqualTo((Character) ','); + assertThat(style.getGroupingCharacter()).isEqualTo((Character) '.'); + assertThat(style.getGroupingStyle()).isEqualTo(GroupingStyle.NONE); + assertThat(style.getGroupingSize()).isEqualTo((Integer) 3); + assertThat(style.getExtendedGroupingSize()).isEqualTo((Integer) 0); + assertThat(style.isForcedDecimalPoint()).isFalse(); } @Test 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)); + assertThat(test.print(MONEY)).isEqualTo("87654321,12345678"); } @Test void test_LOCALIZED_GROUPING() { MoneyAmountStyle style = MoneyAmountStyle.LOCALIZED_GROUPING; - assertNull(style.getZeroCharacter()); - assertNull(style.getPositiveSignCharacter()); - assertNull(style.getNegativeSignCharacter()); - assertNull(style.getDecimalPointCharacter()); - assertNull(style.getGroupingCharacter()); - assertEquals(GroupingStyle.FULL, style.getGroupingStyle()); - assertNull(style.getGroupingSize()); - assertNull(style.getExtendedGroupingSize()); - assertFalse(style.isForcedDecimalPoint()); + assertThat(style.getZeroCharacter()).isNull(); + assertThat(style.getPositiveSignCharacter()).isNull(); + assertThat(style.getNegativeSignCharacter()).isNull(); + assertThat(style.getDecimalPointCharacter()).isNull(); + assertThat(style.getGroupingCharacter()).isNull(); + assertThat(style.getGroupingStyle()).isEqualTo(GroupingStyle.FULL); + assertThat(style.getGroupingSize()).isNull(); + assertThat(style.getExtendedGroupingSize()).isNull(); + assertThat(style.isForcedDecimalPoint()).isFalse(); } @Test 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)); + assertThat(test.print(MONEY)).isEqualTo("87,654,321.123,456,78"); } @Test void test_LOCALIZED_NO_GROUPING() { MoneyAmountStyle style = MoneyAmountStyle.LOCALIZED_NO_GROUPING; - assertNull(style.getZeroCharacter()); - assertNull(style.getPositiveSignCharacter()); - assertNull(style.getNegativeSignCharacter()); - assertNull(style.getDecimalPointCharacter()); - assertNull(style.getGroupingCharacter()); - assertEquals(GroupingStyle.NONE, style.getGroupingStyle()); - assertNull(style.getGroupingSize()); - assertNull(style.getExtendedGroupingSize()); - assertFalse(style.isForcedDecimalPoint()); + assertThat(style.getZeroCharacter()).isNull(); + assertThat(style.getPositiveSignCharacter()).isNull(); + assertThat(style.getNegativeSignCharacter()).isNull(); + assertThat(style.getDecimalPointCharacter()).isNull(); + assertThat(style.getGroupingCharacter()).isNull(); + assertThat(style.getGroupingStyle()).isEqualTo(GroupingStyle.NONE); + assertThat(style.getGroupingSize()).isNull(); + assertThat(style.getExtendedGroupingSize()).isNull(); + assertThat(style.isForcedDecimalPoint()).isFalse(); } @Test 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)); + assertThat(test.print(MONEY)).isEqualTo("87654321.12345678"); } @Test 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)); + assertThat(test.print(MONEY)).isEqualTo("87,654,321.12345678"); } //----------------------------------------------------------------------- @@ -236,29 +232,29 @@ void test_print_groupBeforeDecimal() { @Test void test_of_Locale_GB() { MoneyAmountStyle style = MoneyAmountStyle.of(TEST_GB_LOCALE); - assertEquals((Character) '0', style.getZeroCharacter()); - assertEquals((Character) '+', style.getPositiveSignCharacter()); - assertEquals((Character) '-', style.getNegativeSignCharacter()); - assertEquals((Character) '.', style.getDecimalPointCharacter()); - assertEquals((Character) ',', style.getGroupingCharacter()); - assertEquals(GroupingStyle.FULL, style.getGroupingStyle()); - assertEquals((Integer) 3, style.getGroupingSize()); - assertEquals((Integer) 0, style.getExtendedGroupingSize()); - assertFalse(style.isForcedDecimalPoint()); + assertThat(style.getZeroCharacter()).isEqualTo((Character) '0'); + assertThat(style.getPositiveSignCharacter()).isEqualTo((Character) '+'); + assertThat(style.getNegativeSignCharacter()).isEqualTo((Character) '-'); + assertThat(style.getDecimalPointCharacter()).isEqualTo((Character) '.'); + assertThat(style.getGroupingCharacter()).isEqualTo((Character) ','); + assertThat(style.getGroupingStyle()).isEqualTo(GroupingStyle.FULL); + assertThat(style.getGroupingSize()).isEqualTo((Integer) 3); + assertThat(style.getExtendedGroupingSize()).isEqualTo((Integer) 0); + assertThat(style.isForcedDecimalPoint()).isFalse(); } @Test void test_of_Locale_DE() { MoneyAmountStyle style = MoneyAmountStyle.of(TEST_DE_LOCALE); - assertEquals((Character) '0', style.getZeroCharacter()); - assertEquals((Character) '+', style.getPositiveSignCharacter()); - assertEquals((Character) '-', style.getNegativeSignCharacter()); - assertEquals((Character) ',', style.getDecimalPointCharacter()); - assertEquals((Character) '.', style.getGroupingCharacter()); - assertEquals(GroupingStyle.FULL, style.getGroupingStyle()); - assertEquals((Integer) 3, style.getGroupingSize()); - assertEquals((Integer) 0, style.getExtendedGroupingSize()); - assertFalse(style.isForcedDecimalPoint()); + assertThat(style.getZeroCharacter()).isEqualTo((Character) '0'); + assertThat(style.getPositiveSignCharacter()).isEqualTo((Character) '+'); + assertThat(style.getNegativeSignCharacter()).isEqualTo((Character) '-'); + assertThat(style.getDecimalPointCharacter()).isEqualTo((Character) ','); + assertThat(style.getGroupingCharacter()).isEqualTo((Character) '.'); + assertThat(style.getGroupingStyle()).isEqualTo(GroupingStyle.FULL); + assertThat(style.getGroupingSize()).isEqualTo((Integer) 3); + assertThat(style.getExtendedGroupingSize()).isEqualTo((Integer) 0); + assertThat(style.isForcedDecimalPoint()).isFalse(); } //----------------------------------------------------------------------- @@ -267,147 +263,147 @@ void test_of_Locale_DE() { @Test void test_localize_GB() { MoneyAmountStyle style = MoneyAmountStyle.LOCALIZED_GROUPING.localize(TEST_GB_LOCALE); - assertEquals((Character) '0', style.getZeroCharacter()); - assertEquals((Character) '+', style.getPositiveSignCharacter()); - assertEquals((Character) '-', style.getNegativeSignCharacter()); - assertEquals((Character) '.', style.getDecimalPointCharacter()); - assertEquals((Character) ',', style.getGroupingCharacter()); - assertEquals(GroupingStyle.FULL, style.getGroupingStyle()); - assertEquals((Integer) 3, style.getGroupingSize()); - assertEquals((Integer) 0, style.getExtendedGroupingSize()); - assertFalse(style.isForcedDecimalPoint()); + assertThat(style.getZeroCharacter()).isEqualTo((Character) '0'); + assertThat(style.getPositiveSignCharacter()).isEqualTo((Character) '+'); + assertThat(style.getNegativeSignCharacter()).isEqualTo((Character) '-'); + assertThat(style.getDecimalPointCharacter()).isEqualTo((Character) '.'); + assertThat(style.getGroupingCharacter()).isEqualTo((Character) ','); + assertThat(style.getGroupingStyle()).isEqualTo(GroupingStyle.FULL); + assertThat(style.getGroupingSize()).isEqualTo((Integer) 3); + assertThat(style.getExtendedGroupingSize()).isEqualTo((Integer) 0); + assertThat(style.isForcedDecimalPoint()).isFalse(); } @Test void test_localize_DE() { MoneyAmountStyle style = MoneyAmountStyle.LOCALIZED_GROUPING.localize(TEST_DE_LOCALE); - assertEquals((Character) '0', style.getZeroCharacter()); - assertEquals((Character) '+', style.getPositiveSignCharacter()); - assertEquals((Character) '-', style.getNegativeSignCharacter()); - assertEquals((Character) ',', style.getDecimalPointCharacter()); - assertEquals((Character) '.', style.getGroupingCharacter()); - assertEquals(GroupingStyle.FULL, style.getGroupingStyle()); - assertEquals((Integer) 3, style.getGroupingSize()); - assertEquals((Integer) 0, style.getExtendedGroupingSize()); - assertFalse(style.isForcedDecimalPoint()); + assertThat(style.getZeroCharacter()).isEqualTo((Character) '0'); + assertThat(style.getPositiveSignCharacter()).isEqualTo((Character) '+'); + assertThat(style.getNegativeSignCharacter()).isEqualTo((Character) '-'); + assertThat(style.getDecimalPointCharacter()).isEqualTo((Character) ','); + assertThat(style.getGroupingCharacter()).isEqualTo((Character) '.'); + assertThat(style.getGroupingStyle()).isEqualTo(GroupingStyle.FULL); + assertThat(style.getGroupingSize()).isEqualTo((Integer) 3); + assertThat(style.getExtendedGroupingSize()).isEqualTo((Integer) 0); + assertThat(style.isForcedDecimalPoint()).isFalse(); } @Test void test_localize_DE_fixedZero() { MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING.withZeroCharacter('_'); MoneyAmountStyle style = base.localize(TEST_DE_LOCALE); - assertEquals((Character) '_', style.getZeroCharacter()); - assertEquals((Character) '+', style.getPositiveSignCharacter()); - assertEquals((Character) '-', style.getNegativeSignCharacter()); - assertEquals((Character) ',', style.getDecimalPointCharacter()); - assertEquals((Character) '.', style.getGroupingCharacter()); - assertEquals(GroupingStyle.FULL, style.getGroupingStyle()); - assertEquals((Integer) 3, style.getGroupingSize()); - assertEquals((Integer) 0, style.getExtendedGroupingSize()); - assertFalse(style.isForcedDecimalPoint()); + assertThat(style.getZeroCharacter()).isEqualTo((Character) '_'); + assertThat(style.getPositiveSignCharacter()).isEqualTo((Character) '+'); + assertThat(style.getNegativeSignCharacter()).isEqualTo((Character) '-'); + assertThat(style.getDecimalPointCharacter()).isEqualTo((Character) ','); + assertThat(style.getGroupingCharacter()).isEqualTo((Character) '.'); + assertThat(style.getGroupingStyle()).isEqualTo(GroupingStyle.FULL); + assertThat(style.getGroupingSize()).isEqualTo((Integer) 3); + assertThat(style.getExtendedGroupingSize()).isEqualTo((Integer) 0); + assertThat(style.isForcedDecimalPoint()).isFalse(); } @Test void test_localize_DE_fixedPositive() { MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING.withPositiveSignCharacter('_'); MoneyAmountStyle style = base.localize(TEST_DE_LOCALE); - assertEquals((Character) '0', style.getZeroCharacter()); - assertEquals((Character) '_', style.getPositiveSignCharacter()); - assertEquals((Character) '-', style.getNegativeSignCharacter()); - assertEquals((Character) ',', style.getDecimalPointCharacter()); - assertEquals((Character) '.', style.getGroupingCharacter()); - assertEquals(GroupingStyle.FULL, style.getGroupingStyle()); - assertEquals((Integer) 3, style.getGroupingSize()); - assertEquals((Integer) 0, style.getExtendedGroupingSize()); - assertFalse(style.isForcedDecimalPoint()); + assertThat(style.getZeroCharacter()).isEqualTo((Character) '0'); + assertThat(style.getPositiveSignCharacter()).isEqualTo((Character) '_'); + assertThat(style.getNegativeSignCharacter()).isEqualTo((Character) '-'); + assertThat(style.getDecimalPointCharacter()).isEqualTo((Character) ','); + assertThat(style.getGroupingCharacter()).isEqualTo((Character) '.'); + assertThat(style.getGroupingStyle()).isEqualTo(GroupingStyle.FULL); + assertThat(style.getGroupingSize()).isEqualTo((Integer) 3); + assertThat(style.getExtendedGroupingSize()).isEqualTo((Integer) 0); + assertThat(style.isForcedDecimalPoint()).isFalse(); } @Test void test_localize_DE_fixedNegative() { MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING.withNegativeSignCharacter('_'); MoneyAmountStyle style = base.localize(TEST_DE_LOCALE); - assertEquals((Character) '0', style.getZeroCharacter()); - assertEquals((Character) '+', style.getPositiveSignCharacter()); - assertEquals((Character) '_', style.getNegativeSignCharacter()); - assertEquals((Character) ',', style.getDecimalPointCharacter()); - assertEquals((Character) '.', style.getGroupingCharacter()); - assertEquals(GroupingStyle.FULL, style.getGroupingStyle()); - assertEquals((Integer) 3, style.getGroupingSize()); - assertEquals((Integer) 0, style.getExtendedGroupingSize()); - assertFalse(style.isForcedDecimalPoint()); + assertThat(style.getZeroCharacter()).isEqualTo((Character) '0'); + assertThat(style.getPositiveSignCharacter()).isEqualTo((Character) '+'); + assertThat(style.getNegativeSignCharacter()).isEqualTo((Character) '_'); + assertThat(style.getDecimalPointCharacter()).isEqualTo((Character) ','); + assertThat(style.getGroupingCharacter()).isEqualTo((Character) '.'); + assertThat(style.getGroupingStyle()).isEqualTo(GroupingStyle.FULL); + assertThat(style.getGroupingSize()).isEqualTo((Integer) 3); + assertThat(style.getExtendedGroupingSize()).isEqualTo((Integer) 0); + assertThat(style.isForcedDecimalPoint()).isFalse(); } @Test void test_localize_DE_fixedDecimal() { MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING.withDecimalPointCharacter('_'); MoneyAmountStyle style = base.localize(TEST_DE_LOCALE); - assertEquals((Character) '0', style.getZeroCharacter()); - assertEquals((Character) '+', style.getPositiveSignCharacter()); - assertEquals((Character) '-', style.getNegativeSignCharacter()); - assertEquals((Character) '_', style.getDecimalPointCharacter()); - assertEquals((Character) '.', style.getGroupingCharacter()); - assertEquals(GroupingStyle.FULL, style.getGroupingStyle()); - assertEquals((Integer) 3, style.getGroupingSize()); - assertEquals((Integer) 0, style.getExtendedGroupingSize()); - assertFalse(style.isForcedDecimalPoint()); + assertThat(style.getZeroCharacter()).isEqualTo((Character) '0'); + assertThat(style.getPositiveSignCharacter()).isEqualTo((Character) '+'); + assertThat(style.getNegativeSignCharacter()).isEqualTo((Character) '-'); + assertThat(style.getDecimalPointCharacter()).isEqualTo((Character) '_'); + assertThat(style.getGroupingCharacter()).isEqualTo((Character) '.'); + assertThat(style.getGroupingStyle()).isEqualTo(GroupingStyle.FULL); + assertThat(style.getGroupingSize()).isEqualTo((Integer) 3); + assertThat(style.getExtendedGroupingSize()).isEqualTo((Integer) 0); + assertThat(style.isForcedDecimalPoint()).isFalse(); } @Test void test_localize_DE_fixedGrouping() { MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING.withGroupingCharacter('_'); MoneyAmountStyle style = base.localize(TEST_DE_LOCALE); - assertEquals((Character) '0', style.getZeroCharacter()); - assertEquals((Character) '+', style.getPositiveSignCharacter()); - assertEquals((Character) '-', style.getNegativeSignCharacter()); - assertEquals((Character) ',', style.getDecimalPointCharacter()); - assertEquals((Character) '_', style.getGroupingCharacter()); - assertEquals(GroupingStyle.FULL, style.getGroupingStyle()); - assertEquals((Integer) 3, style.getGroupingSize()); - assertEquals((Integer) 0, style.getExtendedGroupingSize()); - assertFalse(style.isForcedDecimalPoint()); + assertThat(style.getZeroCharacter()).isEqualTo((Character) '0'); + assertThat(style.getPositiveSignCharacter()).isEqualTo((Character) '+'); + assertThat(style.getNegativeSignCharacter()).isEqualTo((Character) '-'); + assertThat(style.getDecimalPointCharacter()).isEqualTo((Character) ','); + assertThat(style.getGroupingCharacter()).isEqualTo((Character) '_'); + assertThat(style.getGroupingStyle()).isEqualTo(GroupingStyle.FULL); + assertThat(style.getGroupingSize()).isEqualTo((Integer) 3); + assertThat(style.getExtendedGroupingSize()).isEqualTo((Integer) 0); + assertThat(style.isForcedDecimalPoint()).isFalse(); } @Test void test_localize_DE_fixedZeroAndDecimal() { MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING.withZeroCharacter('_').withDecimalPointCharacter('-'); MoneyAmountStyle style = base.localize(TEST_DE_LOCALE); - assertEquals((Character) '_', style.getZeroCharacter()); - assertEquals((Character) '+', style.getPositiveSignCharacter()); - assertEquals((Character) '-', style.getNegativeSignCharacter()); - assertEquals((Character) '-', style.getDecimalPointCharacter()); - assertEquals((Character) '.', style.getGroupingCharacter()); - assertEquals(GroupingStyle.FULL, style.getGroupingStyle()); - assertEquals((Integer) 3, style.getGroupingSize()); - assertEquals((Integer) 0, style.getExtendedGroupingSize()); - assertFalse(style.isForcedDecimalPoint()); + assertThat(style.getZeroCharacter()).isEqualTo((Character) '_'); + assertThat(style.getPositiveSignCharacter()).isEqualTo((Character) '+'); + assertThat(style.getNegativeSignCharacter()).isEqualTo((Character) '-'); + assertThat(style.getDecimalPointCharacter()).isEqualTo((Character) '-'); + assertThat(style.getGroupingCharacter()).isEqualTo((Character) '.'); + assertThat(style.getGroupingStyle()).isEqualTo(GroupingStyle.FULL); + assertThat(style.getGroupingSize()).isEqualTo((Integer) 3); + assertThat(style.getExtendedGroupingSize()).isEqualTo((Integer) 0); + assertThat(style.isForcedDecimalPoint()).isFalse(); } @Test void test_localize_DE_noGrouping() { MoneyAmountStyle style = MoneyAmountStyle.LOCALIZED_NO_GROUPING.localize(TEST_DE_LOCALE); - assertEquals((Character) '0', style.getZeroCharacter()); - assertEquals((Character) '+', style.getPositiveSignCharacter()); - assertEquals((Character) '-', style.getNegativeSignCharacter()); - assertEquals((Character) ',', style.getDecimalPointCharacter()); - assertEquals((Character) '.', style.getGroupingCharacter()); - assertEquals(GroupingStyle.NONE, style.getGroupingStyle()); - assertEquals((Integer) 3, style.getGroupingSize()); - assertEquals((Integer) 0, style.getExtendedGroupingSize()); - assertFalse(style.isForcedDecimalPoint()); + assertThat(style.getZeroCharacter()).isEqualTo((Character) '0'); + assertThat(style.getPositiveSignCharacter()).isEqualTo((Character) '+'); + assertThat(style.getNegativeSignCharacter()).isEqualTo((Character) '-'); + assertThat(style.getDecimalPointCharacter()).isEqualTo((Character) ','); + assertThat(style.getGroupingCharacter()).isEqualTo((Character) '.'); + assertThat(style.getGroupingStyle()).isEqualTo(GroupingStyle.NONE); + assertThat(style.getGroupingSize()).isEqualTo((Integer) 3); + assertThat(style.getExtendedGroupingSize()).isEqualTo((Integer) 0); + assertThat(style.isForcedDecimalPoint()).isFalse(); } @Test void test_localize_LV() { MoneyAmountStyle style = MoneyAmountStyle.LOCALIZED_NO_GROUPING.localize(TEST_LV_LOCALE); - assertEquals((Character) '0', style.getZeroCharacter()); - assertEquals((Character) '+', style.getPositiveSignCharacter()); - assertEquals((Character) '-', style.getNegativeSignCharacter()); - assertEquals((Character) ',', style.getDecimalPointCharacter()); - assertEquals((Character) '\u00a0', style.getGroupingCharacter()); - assertEquals(GroupingStyle.NONE, style.getGroupingStyle()); - assertEquals((Integer) 3, style.getGroupingSize()); - assertEquals((Integer) 0, style.getExtendedGroupingSize()); - assertFalse(style.isForcedDecimalPoint()); + assertThat(style.getZeroCharacter()).isEqualTo((Character) '0'); + assertThat(style.getPositiveSignCharacter()).isEqualTo((Character) '+'); + assertThat(style.getNegativeSignCharacter()).isEqualTo((Character) '-'); + assertThat(style.getDecimalPointCharacter()).isEqualTo((Character) ','); + assertThat(style.getGroupingCharacter()).isEqualTo((Character) '\u00a0'); + assertThat(style.getGroupingStyle()).isEqualTo(GroupingStyle.NONE); + assertThat(style.getGroupingSize()).isEqualTo((Integer) 3); + assertThat(style.getExtendedGroupingSize()).isEqualTo((Integer) 0); + assertThat(style.isForcedDecimalPoint()).isFalse(); } //----------------------------------------------------------------------- @@ -416,218 +412,217 @@ void test_localize_LV() { @Test void test_withZeroCharacter() { MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING; - assertNull(base.getZeroCharacter()); + assertThat(base.getZeroCharacter()).isNull(); MoneyAmountStyle test = base.withZeroCharacter('_'); - assertNull(base.getZeroCharacter()); - assertEquals((Character) '_', test.getZeroCharacter()); + assertThat(base.getZeroCharacter()).isNull(); + assertThat(test.getZeroCharacter()).isEqualTo((Character) '_'); } @Test void test_withZeroCharacter_same() { MoneyAmountStyle base = MoneyAmountStyle.ASCII_DECIMAL_POINT_GROUP3_COMMA; - assertEquals((Character) '0', base.getZeroCharacter()); + assertThat(base.getZeroCharacter()).isEqualTo((Character) '0'); MoneyAmountStyle test = base.withZeroCharacter('0'); - assertSame(base, test); + assertThat(test).isSameAs(base); } @Test void test_withZeroCharacter_sameNull() { MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING; - assertNull(base.getZeroCharacter()); + assertThat(base.getZeroCharacter()).isNull(); MoneyAmountStyle test = base.withZeroCharacter(null); - assertSame(base, test); + assertThat(test).isSameAs(base); } //----------------------------------------------------------------------- @Test void test_withPositiveSignCharacter() { MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING; - assertNull(base.getPositiveSignCharacter()); + assertThat(base.getPositiveSignCharacter()).isNull(); MoneyAmountStyle test = base.withPositiveSignCharacter('_'); - assertNull(base.getPositiveSignCharacter()); - assertEquals((Character) '_', test.getPositiveSignCharacter()); + assertThat(base.getPositiveSignCharacter()).isNull(); + assertThat(test.getPositiveSignCharacter()).isEqualTo((Character) '_'); } @Test void test_withPositiveSignCharacter_same() { MoneyAmountStyle base = MoneyAmountStyle.ASCII_DECIMAL_POINT_GROUP3_COMMA; - assertEquals((Character) '+', base.getPositiveSignCharacter()); + assertThat(base.getPositiveSignCharacter()).isEqualTo((Character) '+'); MoneyAmountStyle test = base.withPositiveSignCharacter('+'); - assertSame(base, test); + assertThat(test).isSameAs(base); } @Test void test_withPositiveSignCharacter_sameNull() { MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING; - assertNull(base.getPositiveSignCharacter()); + assertThat(base.getPositiveSignCharacter()).isNull(); MoneyAmountStyle test = base.withPositiveSignCharacter(null); - assertSame(base, test); + assertThat(test).isSameAs(base); } //----------------------------------------------------------------------- @Test void test_withNegativeSignCharacter() { MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING; - assertNull(base.getNegativeSignCharacter()); + assertThat(base.getNegativeSignCharacter()).isNull(); MoneyAmountStyle test = base.withNegativeSignCharacter('_'); - assertNull(base.getNegativeSignCharacter()); - assertEquals((Character) '_', test.getNegativeSignCharacter()); + assertThat(base.getNegativeSignCharacter()).isNull(); + assertThat(test.getNegativeSignCharacter()).isEqualTo((Character) '_'); } @Test void test_withNegativeSignCharacter_same() { MoneyAmountStyle base = MoneyAmountStyle.ASCII_DECIMAL_POINT_GROUP3_COMMA; - assertEquals((Character) '-', base.getNegativeSignCharacter()); + assertThat(base.getNegativeSignCharacter()).isEqualTo((Character) '-'); MoneyAmountStyle test = base.withNegativeSignCharacter('-'); - assertSame(base, test); + assertThat(test).isSameAs(base); } @Test void test_withNegativeSignCharacter_sameNull() { MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING; - assertNull(base.getNegativeSignCharacter()); + assertThat(base.getNegativeSignCharacter()).isNull(); MoneyAmountStyle test = base.withNegativeSignCharacter(null); - assertSame(base, test); + assertThat(test).isSameAs(base); } //----------------------------------------------------------------------- @Test void test_withDecimalPointCharacter() { MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING; - assertNull(base.getDecimalPointCharacter()); + assertThat(base.getDecimalPointCharacter()).isNull(); MoneyAmountStyle test = base.withDecimalPointCharacter('_'); - assertNull(base.getDecimalPointCharacter()); - assertEquals((Character) '_', test.getDecimalPointCharacter()); + assertThat(base.getDecimalPointCharacter()).isNull(); + assertThat(test.getDecimalPointCharacter()).isEqualTo((Character) '_'); } @Test void test_withDecimalPointCharacter_same() { MoneyAmountStyle base = MoneyAmountStyle.ASCII_DECIMAL_POINT_GROUP3_COMMA; - assertEquals((Character) '.', base.getDecimalPointCharacter()); + assertThat(base.getDecimalPointCharacter()).isEqualTo((Character) '.'); MoneyAmountStyle test = base.withDecimalPointCharacter('.'); - assertSame(base, test); + assertThat(test).isSameAs(base); } @Test void test_withDecimalPointCharacter_sameNull() { MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING; - assertNull(base.getDecimalPointCharacter()); + assertThat(base.getDecimalPointCharacter()).isNull(); MoneyAmountStyle test = base.withDecimalPointCharacter(null); - assertSame(base, test); + assertThat(test).isSameAs(base); } //----------------------------------------------------------------------- @Test void test_withGroupingCharacter() { MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING; - assertNull(base.getGroupingCharacter()); + assertThat(base.getGroupingCharacter()).isNull(); MoneyAmountStyle test = base.withGroupingCharacter('_'); - assertNull(base.getGroupingCharacter()); - assertEquals((Character) '_', test.getGroupingCharacter()); + assertThat(base.getGroupingCharacter()).isNull(); + assertThat(test.getGroupingCharacter()).isEqualTo((Character) '_'); } @Test void test_withGroupingCharacter_same() { MoneyAmountStyle base = MoneyAmountStyle.ASCII_DECIMAL_POINT_GROUP3_COMMA; - assertEquals((Character) ',', base.getGroupingCharacter()); + assertThat(base.getGroupingCharacter()).isEqualTo((Character) ','); MoneyAmountStyle test = base.withGroupingCharacter(','); - assertSame(base, test); + assertThat(test).isSameAs(base); } @Test void test_withGroupingCharacter_sameNull() { MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING; - assertNull(base.getGroupingCharacter()); + assertThat(base.getGroupingCharacter()).isNull(); MoneyAmountStyle test = base.withGroupingCharacter(null); - assertSame(base, test); + assertThat(test).isSameAs(base); } //----------------------------------------------------------------------- @Test void test_withGroupingStyle() { MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING; - assertEquals(GroupingStyle.FULL, base.getGroupingStyle()); + assertThat(base.getGroupingStyle()).isEqualTo(GroupingStyle.FULL); MoneyAmountStyle test = base.withGroupingStyle(GroupingStyle.BEFORE_DECIMAL_POINT); - assertEquals(GroupingStyle.FULL, base.getGroupingStyle()); - assertEquals(GroupingStyle.BEFORE_DECIMAL_POINT, test.getGroupingStyle()); + assertThat(base.getGroupingStyle()).isEqualTo(GroupingStyle.FULL); + assertThat(test.getGroupingStyle()).isEqualTo(GroupingStyle.BEFORE_DECIMAL_POINT); } @Test void test_withGroupingStyle_same() { MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING; - assertEquals(GroupingStyle.FULL, base.getGroupingStyle()); + assertThat(base.getGroupingStyle()).isEqualTo(GroupingStyle.FULL); MoneyAmountStyle test = base.withGroupingStyle(GroupingStyle.FULL); - assertSame(base, test); + assertThat(test).isSameAs(base); } //----------------------------------------------------------------------- @Test void test_withGroupingSize() { MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING; - assertNull(base.getGroupingSize()); + assertThat(base.getGroupingSize()).isNull(); MoneyAmountStyle test = base.withGroupingSize(6); - assertNull(base.getGroupingSize()); - assertEquals((Integer) 6, test.getGroupingSize()); + assertThat(base.getGroupingSize()).isNull(); + assertThat(test.getGroupingSize()).isEqualTo((Integer) 6); } @Test void test_withGroupingSize_same() { MoneyAmountStyle base = MoneyAmountStyle.ASCII_DECIMAL_POINT_GROUP3_COMMA; - assertEquals((Integer) 3, base.getGroupingSize()); + assertThat(base.getGroupingSize()).isEqualTo((Integer) 3); MoneyAmountStyle test = base.withGroupingSize(3); - assertSame(base, test); + assertThat(test).isSameAs(base); } @Test void test_withGroupingSize_sameNull() { MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING; - assertNull(base.getGroupingSize()); + assertThat(base.getGroupingSize()).isNull(); MoneyAmountStyle test = base.withGroupingSize(null); - assertSame(base, test); + assertThat(test).isSameAs(base); } @Test void test_withGroupingSize_negative() { MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING; - assertThrows(IllegalArgumentException.class, () -> { - base.withGroupingSize(-1); - }); + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> base.withGroupingSize(-1)); } //----------------------------------------------------------------------- @Test void test_withForcedDecimalPoint() { MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING; - assertFalse(base.isForcedDecimalPoint()); + assertThat(base.isForcedDecimalPoint()).isFalse(); MoneyAmountStyle test = base.withForcedDecimalPoint(true); - assertFalse(base.isForcedDecimalPoint()); - assertTrue(test.isForcedDecimalPoint()); + assertThat(base.isForcedDecimalPoint()).isFalse(); + assertThat(test.isForcedDecimalPoint()).isTrue(); } @Test void test_withForcedDecimalPoint_same() { MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING; - assertFalse(base.isForcedDecimalPoint()); + assertThat(base.isForcedDecimalPoint()).isFalse(); MoneyAmountStyle test = base.withForcedDecimalPoint(false); - assertSame(base, test); + assertThat(test).isSameAs(base); } //----------------------------------------------------------------------- @Test void test_withAbsValue() { MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING; - assertFalse(base.isAbsValue()); + assertThat(base.isAbsValue()).isFalse(); MoneyAmountStyle test = base.withAbsValue(true); - assertFalse(base.isAbsValue()); - assertTrue(test.isAbsValue()); + assertThat(base.isAbsValue()).isFalse(); + assertThat(test.isAbsValue()).isTrue(); } @Test void test_withAbsValue_same() { MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING; - assertFalse(base.isAbsValue()); + assertThat(base.isAbsValue()).isFalse(); MoneyAmountStyle test = base.withAbsValue(false); - assertSame(base, test); + assertThat(test).isSameAs(base); } //----------------------------------------------------------------------- @@ -636,197 +631,197 @@ void test_withAbsValue_same() { @Test void test_equals_same() { MoneyAmountStyle a = MoneyAmountStyle.LOCALIZED_GROUPING; - assertTrue(a.equals(a)); + assertThat(a).isEqualTo(a); } @Test void test_equals_otherType() { MoneyAmountStyle a = MoneyAmountStyle.LOCALIZED_GROUPING; - assertFalse(a.equals(new Object())); + assertThat(new Object()).isNotEqualTo(a); } @Test void test_equals_null() { MoneyAmountStyle a = MoneyAmountStyle.LOCALIZED_GROUPING; - assertFalse(a.equals(null)); + assertThat(a).isNotEqualTo(null); } @Test void test_equals_equal_zeroChar() { MoneyAmountStyle a = MoneyAmountStyle.LOCALIZED_GROUPING.withZeroCharacter('_'); MoneyAmountStyle b = MoneyAmountStyle.LOCALIZED_GROUPING.withZeroCharacter('_'); - assertTrue(a.equals(b)); - assertTrue(b.equals(a)); - assertEquals(b.hashCode(), a.hashCode()); + assertThat(b).isEqualTo(a); + assertThat(a).isEqualTo(b); + assertThat(a.hashCode()).isEqualTo(b.hashCode()); } @Test void test_equals_notEqual_zeroChar() { MoneyAmountStyle a = MoneyAmountStyle.LOCALIZED_GROUPING; MoneyAmountStyle b = MoneyAmountStyle.LOCALIZED_GROUPING.withZeroCharacter('_'); - assertFalse(a.equals(b)); - assertFalse(b.equals(a)); + assertThat(b).isNotEqualTo(a); + assertThat(a).isNotEqualTo(b); } @Test void test_equals_equal_positiveChar() { MoneyAmountStyle a = MoneyAmountStyle.LOCALIZED_GROUPING.withPositiveSignCharacter('_'); MoneyAmountStyle b = MoneyAmountStyle.LOCALIZED_GROUPING.withPositiveSignCharacter('_'); - assertTrue(a.equals(b)); - assertTrue(b.equals(a)); - assertEquals(b.hashCode(), a.hashCode()); + assertThat(b).isEqualTo(a); + assertThat(a).isEqualTo(b); + assertThat(a.hashCode()).isEqualTo(b.hashCode()); } @Test void test_equals_notEqual_positiveChar() { MoneyAmountStyle a = MoneyAmountStyle.LOCALIZED_GROUPING; MoneyAmountStyle b = MoneyAmountStyle.LOCALIZED_GROUPING.withPositiveSignCharacter('_'); - assertFalse(a.equals(b)); - assertFalse(b.equals(a)); + assertThat(b).isNotEqualTo(a); + assertThat(a).isNotEqualTo(b); } @Test void test_equals_equal_negativeChar() { MoneyAmountStyle a = MoneyAmountStyle.LOCALIZED_GROUPING.withNegativeSignCharacter('_'); MoneyAmountStyle b = MoneyAmountStyle.LOCALIZED_GROUPING.withNegativeSignCharacter('_'); - assertTrue(a.equals(b)); - assertTrue(b.equals(a)); - assertEquals(b.hashCode(), a.hashCode()); + assertThat(b).isEqualTo(a); + assertThat(a).isEqualTo(b); + assertThat(a.hashCode()).isEqualTo(b.hashCode()); } @Test void test_equals_notEqual_negativeChar() { MoneyAmountStyle a = MoneyAmountStyle.LOCALIZED_GROUPING; MoneyAmountStyle b = MoneyAmountStyle.LOCALIZED_GROUPING.withNegativeSignCharacter('_'); - assertFalse(a.equals(b)); - assertFalse(b.equals(a)); + assertThat(b).isNotEqualTo(a); + assertThat(a).isNotEqualTo(b); } @Test void test_equals_equal_decimalPointChar() { MoneyAmountStyle a = MoneyAmountStyle.LOCALIZED_GROUPING.withDecimalPointCharacter('_'); MoneyAmountStyle b = MoneyAmountStyle.LOCALIZED_GROUPING.withDecimalPointCharacter('_'); - assertTrue(a.equals(b)); - assertTrue(b.equals(a)); - assertEquals(b.hashCode(), a.hashCode()); + assertThat(b).isEqualTo(a); + assertThat(a).isEqualTo(b); + assertThat(a.hashCode()).isEqualTo(b.hashCode()); } @Test void test_equals_notEqual_decimalPointChar() { MoneyAmountStyle a = MoneyAmountStyle.LOCALIZED_GROUPING; MoneyAmountStyle b = MoneyAmountStyle.LOCALIZED_GROUPING.withDecimalPointCharacter('_'); - assertFalse(a.equals(b)); - assertFalse(b.equals(a)); + assertThat(b).isNotEqualTo(a); + assertThat(a).isNotEqualTo(b); } @Test void test_equals_equal_groupingChar() { MoneyAmountStyle a = MoneyAmountStyle.LOCALIZED_GROUPING.withGroupingCharacter('_'); MoneyAmountStyle b = MoneyAmountStyle.LOCALIZED_GROUPING.withGroupingCharacter('_'); - assertTrue(a.equals(b)); - assertTrue(b.equals(a)); - assertEquals(b.hashCode(), a.hashCode()); + assertThat(b).isEqualTo(a); + assertThat(a).isEqualTo(b); + assertThat(a.hashCode()).isEqualTo(b.hashCode()); } @Test void test_equals_notEqual_groupingChar() { MoneyAmountStyle a = MoneyAmountStyle.LOCALIZED_GROUPING; MoneyAmountStyle b = MoneyAmountStyle.LOCALIZED_GROUPING.withGroupingCharacter('_'); - assertFalse(a.equals(b)); - assertFalse(b.equals(a)); + assertThat(b).isNotEqualTo(a); + assertThat(a).isNotEqualTo(b); } @Test 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); - assertTrue(a.equals(b)); - assertTrue(b.equals(a)); - assertEquals(b.hashCode(), a.hashCode()); + assertThat(b).isEqualTo(a); + assertThat(a).isEqualTo(b); + assertThat(a.hashCode()).isEqualTo(b.hashCode()); } @Test void test_equals_notEqual_groupingStyle() { MoneyAmountStyle a = MoneyAmountStyle.LOCALIZED_GROUPING.withGroupingStyle(GroupingStyle.BEFORE_DECIMAL_POINT); MoneyAmountStyle b = MoneyAmountStyle.LOCALIZED_GROUPING.withGroupingStyle(GroupingStyle.NONE); - assertFalse(a.equals(b)); - assertFalse(b.equals(a)); + assertThat(b).isNotEqualTo(a); + assertThat(a).isNotEqualTo(b); } @Test void test_equals_equal_groupingSize() { MoneyAmountStyle a = MoneyAmountStyle.LOCALIZED_GROUPING.withGroupingSize(4); MoneyAmountStyle b = MoneyAmountStyle.LOCALIZED_GROUPING.withGroupingSize(4); - assertTrue(a.equals(b)); - assertTrue(b.equals(a)); - assertEquals(b.hashCode(), a.hashCode()); + assertThat(b).isEqualTo(a); + assertThat(a).isEqualTo(b); + assertThat(a.hashCode()).isEqualTo(b.hashCode()); } @Test void test_equals_notEqual_groupingSize() { MoneyAmountStyle a = MoneyAmountStyle.LOCALIZED_GROUPING; MoneyAmountStyle b = MoneyAmountStyle.LOCALIZED_GROUPING.withGroupingSize(4); - assertFalse(a.equals(b)); - assertFalse(b.equals(a)); + assertThat(b).isNotEqualTo(a); + assertThat(a).isNotEqualTo(b); } @Test void test_equals_equal_forcedDecimalPoint_false() { MoneyAmountStyle a = MoneyAmountStyle.LOCALIZED_GROUPING.withForcedDecimalPoint(true).withForcedDecimalPoint(false); MoneyAmountStyle b = MoneyAmountStyle.LOCALIZED_GROUPING.withForcedDecimalPoint(true).withForcedDecimalPoint(false); - assertTrue(a.equals(b)); - assertTrue(b.equals(a)); - assertEquals(b.hashCode(), a.hashCode()); + assertThat(b).isEqualTo(a); + assertThat(a).isEqualTo(b); + assertThat(a.hashCode()).isEqualTo(b.hashCode()); } @Test void test_equals_equal_forcedDecimalPoint_true() { MoneyAmountStyle a = MoneyAmountStyle.LOCALIZED_GROUPING.withForcedDecimalPoint(true); MoneyAmountStyle b = MoneyAmountStyle.LOCALIZED_GROUPING.withForcedDecimalPoint(true); - assertTrue(a.equals(b)); - assertTrue(b.equals(a)); - assertEquals(b.hashCode(), a.hashCode()); + assertThat(b).isEqualTo(a); + assertThat(a).isEqualTo(b); + assertThat(a.hashCode()).isEqualTo(b.hashCode()); } @Test void test_equals_notEqual_forcedDecimalPoint() { MoneyAmountStyle a = MoneyAmountStyle.LOCALIZED_GROUPING; MoneyAmountStyle b = MoneyAmountStyle.LOCALIZED_GROUPING.withForcedDecimalPoint(true); - assertFalse(a.equals(b)); - assertFalse(b.equals(a)); + assertThat(b).isNotEqualTo(a); + assertThat(a).isNotEqualTo(b); } @Test void test_equals_equal_absValue_false() { MoneyAmountStyle a = MoneyAmountStyle.LOCALIZED_GROUPING.withAbsValue(true).withAbsValue(false); MoneyAmountStyle b = MoneyAmountStyle.LOCALIZED_GROUPING.withAbsValue(true).withAbsValue(false); - assertTrue(a.equals(b)); - assertTrue(b.equals(a)); - assertEquals(b.hashCode(), a.hashCode()); + assertThat(b).isEqualTo(a); + assertThat(a).isEqualTo(b); + assertThat(a.hashCode()).isEqualTo(b.hashCode()); } @Test void test_equals_equal_absValue_true() { MoneyAmountStyle a = MoneyAmountStyle.LOCALIZED_GROUPING.withAbsValue(true); MoneyAmountStyle b = MoneyAmountStyle.LOCALIZED_GROUPING.withAbsValue(true); - assertTrue(a.equals(b)); - assertTrue(b.equals(a)); - assertEquals(b.hashCode(), a.hashCode()); + assertThat(b).isEqualTo(a); + assertThat(a).isEqualTo(b); + assertThat(a.hashCode()).isEqualTo(b.hashCode()); } @Test void test_equals_notEqual_absValue() { MoneyAmountStyle a = MoneyAmountStyle.LOCALIZED_GROUPING; MoneyAmountStyle b = MoneyAmountStyle.LOCALIZED_GROUPING.withAbsValue(true); - assertFalse(a.equals(b)); - assertFalse(b.equals(a)); + assertThat(b).isNotEqualTo(a); + assertThat(a).isNotEqualTo(b); } //----------------------------------------------------------------------- @Test void test_toString() { MoneyAmountStyle test = MoneyAmountStyle.LOCALIZED_GROUPING; - assertTrue(test.toString().startsWith("MoneyAmountStyle")); + assertThat(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 b4681ae..81cda0f 100644 --- a/src/test/java/org/joda/money/format/TestMoneyFormatter.java +++ b/src/test/java/org/joda/money/format/TestMoneyFormatter.java @@ -15,11 +15,8 @@ */ package org.joda.money.format; -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 static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -101,7 +98,7 @@ void test_serialization() throws Exception { ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); MoneyFormatter input = (MoneyFormatter) ois.readObject(); Money value = MONEY_GBP_12_34; - assertEquals(a.print(value), input.print(value)); + assertThat(input.print(value)).isEqualTo(a.print(value)); } } @@ -110,21 +107,20 @@ void test_serialization() throws Exception { //----------------------------------------------------------------------- @Test void test_getLocale() { - assertEquals(TEST_GB_LOCALE, iPrintTest.getLocale()); + assertThat(iPrintTest.getLocale()).isEqualTo(TEST_GB_LOCALE); } @Test void test_withLocale() { MoneyFormatter test = iPrintTest.withLocale(TEST_FR_LOCALE); - assertEquals(TEST_GB_LOCALE, iPrintTest.getLocale()); - assertEquals(TEST_FR_LOCALE, test.getLocale()); + assertThat(iPrintTest.getLocale()).isEqualTo(TEST_GB_LOCALE); + assertThat(test.getLocale()).isEqualTo(TEST_FR_LOCALE); } @Test void test_withLocale_nullLocale() { - assertThrows(NullPointerException.class, () -> { - iPrintTest.withLocale((Locale) null); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> iPrintTest.withLocale((Locale) null)); } //----------------------------------------------------------------------- @@ -132,21 +128,19 @@ void test_withLocale_nullLocale() { //----------------------------------------------------------------------- @Test void test_print_BigMoneyProvider() { - assertEquals("GBP hello", iPrintTest.print(MONEY_GBP_12_34)); + assertThat(iPrintTest.print(MONEY_GBP_12_34)).isEqualTo("GBP hello"); } @Test void test_print_BigMoneyProvider_cannotPrint() { - assertThrows(UnsupportedOperationException.class, () -> { - iCannotPrint.print(MONEY_GBP_12_34); - }); + assertThatExceptionOfType(UnsupportedOperationException.class) + .isThrownBy(() -> iCannotPrint.print(MONEY_GBP_12_34)); } @Test void test_print_BigMoneyProvider_nullBigMoneyProvider() { - assertThrows(NullPointerException.class, () -> { - iPrintTest.print((BigMoneyProvider) null); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> iPrintTest.print((BigMoneyProvider) null)); } //----------------------------------------------------------------------- @@ -156,41 +150,33 @@ void test_print_BigMoneyProvider_nullBigMoneyProvider() { void test_print_AppendableBigMoneyProvider() { StringBuilder buf = new StringBuilder(); iPrintTest.print(buf, MONEY_GBP_12_34); - assertEquals("GBP hello", buf.toString()); + assertThat(buf).hasToString("GBP hello"); } @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; - } - }); + Appendable appendable = new IOAppendable(); + assertThatExceptionOfType(MoneyFormatException.class) + .isThrownBy(() -> iPrintTest.print(appendable, MONEY_GBP_12_34)) + .withCauseInstanceOf(IOException.class); } @Test void test_print_AppendableBigMoneyProvider_cannotPrint() { - assertThrows(UnsupportedOperationException.class, () -> { - iCannotPrint.print(new StringBuilder(), MONEY_GBP_12_34); - }); + assertThatExceptionOfType(UnsupportedOperationException.class) + .isThrownBy(() -> iCannotPrint.print(new StringBuilder(), MONEY_GBP_12_34)); } @Test void test_print_AppendableBigMoneyProvider_nullAppendable() { - assertThrows(NullPointerException.class, () -> { - iPrintTest.print((Appendable) null, MONEY_GBP_12_34); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> iPrintTest.print((Appendable) null, MONEY_GBP_12_34)); } @Test void test_print_AppendableBigMoneyProvider_nullBigMoneyProvider() { - assertThrows(NullPointerException.class, () -> { - iPrintTest.print(new StringBuilder(), (BigMoneyProvider) null); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> iPrintTest.print(new StringBuilder(), (BigMoneyProvider) null)); } //----------------------------------------------------------------------- @@ -200,36 +186,32 @@ void test_print_AppendableBigMoneyProvider_nullBigMoneyProvider() { void test_printIO_AppendableBigMoneyProvider() throws IOException { StringBuilder buf = new StringBuilder(); iPrintTest.printIO(buf, MONEY_GBP_12_34); - assertEquals("GBP hello", buf.toString()); + assertThat(buf).hasToString("GBP hello"); } @Test void test_printIO_AppendableBigMoneyProvider_IOException() { Appendable appendable = new IOAppendable(); - assertThrows(IOException.class, () -> { - iPrintTest.printIO(appendable, MONEY_GBP_12_34); - }); + assertThatExceptionOfType(IOException.class) + .isThrownBy(() -> iPrintTest.printIO(appendable, MONEY_GBP_12_34)); } @Test void test_printIO_AppendableBigMoneyProvider_cannotPrint() { - assertThrows(UnsupportedOperationException.class, () -> { - iCannotPrint.printIO(new StringBuilder(), MONEY_GBP_12_34); - }); + assertThatExceptionOfType(UnsupportedOperationException.class) + .isThrownBy(() -> iCannotPrint.printIO(new StringBuilder(), MONEY_GBP_12_34)); } @Test void test_printIO_AppendableBigMoneyProvider_nullAppendable() { - assertThrows(NullPointerException.class, () -> { - iPrintTest.printIO((Appendable) null, MONEY_GBP_12_34); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> iPrintTest.printIO((Appendable) null, MONEY_GBP_12_34)); } @Test void test_printIO_AppendableBigMoneyProvider_nullBigMoneyProvider() { - assertThrows(NullPointerException.class, () -> { - iPrintTest.printIO(new StringBuilder(), (BigMoneyProvider) null); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> iPrintTest.printIO(new StringBuilder(), (BigMoneyProvider) null)); } //----------------------------------------------------------------------- @@ -239,64 +221,58 @@ void test_printIO_AppendableBigMoneyProvider_nullBigMoneyProvider() { void test_parseBigMoney_CharSequence() { CharSequence input = new StringBuilder("12.34 GBP"); BigMoney test = iParseTest.parseBigMoney(input); - assertEquals(MONEY_GBP_12_34.toBigMoney(), test); + assertThat(test).isEqualTo(MONEY_GBP_12_34.toBigMoney()); } @Test void test_parseBigMoney_CharSequence_invalidCurrency() { - assertThrows(MoneyFormatException.class, () -> { - iParseTest.parseBigMoney("12.34 GBX"); - }); + assertThatExceptionOfType(MoneyFormatException.class) + .isThrownBy(() -> iParseTest.parseBigMoney("12.34 GBX")); } @Test void test_parseBigMoney_CharSequence_notFullyParsed() { - assertThrows(MoneyFormatException.class, () -> { - iParseTest.parseBigMoney("12.34 GBP X"); - }); + assertThatExceptionOfType(MoneyFormatException.class) + .isThrownBy(() -> iParseTest.parseBigMoney("12.34 GBP X")); } @Test void test_parseBigMoney_CharSequence_incomplete() { - assertThrows(MoneyFormatException.class, () -> { - iParseTest.parseBigMoney("12.34 GBP "); - }); + assertThatExceptionOfType(MoneyFormatException.class) + .isThrownBy(() -> iParseTest.parseBigMoney("12.34 GBP ")); } @Test void test_parseBigMoney_CharSequence_incompleteLongText() { - assertThrows(MoneyFormatException.class, () -> { - iParseTest.parseBigMoney("12.34 GBP ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAB"); - }); + assertThatExceptionOfType(MoneyFormatException.class) + .isThrownBy( + () -> iParseTest + .parseBigMoney("12.34 GBP ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAB")); } @Test void test_parseBigMoney_CharSequence_incompleteEmptyParser() { - assertThrows(MoneyFormatException.class, () -> { - iCannotPrint.parseBigMoney("12.34 GBP"); - }); + assertThatExceptionOfType(MoneyFormatException.class) + .isThrownBy(() -> iCannotPrint.parseBigMoney("12.34 GBP")); } @Test void test_parseBigMoney_CharSequence_missingCurrency() { MoneyFormatter f = new MoneyFormatterBuilder().appendAmount().toFormatter(); - assertThrows(MoneyFormatException.class, () -> { - f.parseBigMoney("12.34"); - }); + assertThatExceptionOfType(MoneyFormatException.class) + .isThrownBy(() -> f.parseBigMoney("12.34")); } @Test void test_parseBigMoney_CharSequence_cannotParse() { - assertThrows(UnsupportedOperationException.class, () -> { - iCannotParse.parseBigMoney(new StringBuilder()); - }); + assertThatExceptionOfType(UnsupportedOperationException.class) + .isThrownBy(() -> iCannotParse.parseBigMoney(new StringBuilder())); } @Test void test_parseBigMoney_CharSequence_nullCharSequence() { - assertThrows(NullPointerException.class, () -> { - iParseTest.parseBigMoney((CharSequence) null); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> iParseTest.parseBigMoney((CharSequence) null)); } //----------------------------------------------------------------------- @@ -306,42 +282,37 @@ void test_parseBigMoney_CharSequence_nullCharSequence() { void test_parseMoney_CharSequence() { CharSequence input = new StringBuilder("12.34 GBP"); Money test = iParseTest.parseMoney(input); - assertEquals(MONEY_GBP_12_34, test); + assertThat(test).isEqualTo(MONEY_GBP_12_34); } @Test void test_parseMoney_CharSequence_invalidCurrency() { - assertThrows(MoneyFormatException.class, () -> { - iParseTest.parseMoney("12.34 GBX"); - }); + assertThatExceptionOfType(MoneyFormatException.class) + .isThrownBy(() -> iParseTest.parseMoney("12.34 GBX")); } @Test void test_parseMoney_CharSequence_notFullyParsed() { - assertThrows(MoneyFormatException.class, () -> { - iParseTest.parseMoney("12.34 GBP X"); - }); + assertThatExceptionOfType(MoneyFormatException.class) + .isThrownBy(() -> iParseTest.parseMoney("12.34 GBP X")); } @Test void test_parseMoney_CharSequence_incomplete() { - assertThrows(MoneyFormatException.class, () -> { - iCannotPrint.parseMoney("12.34 GBP"); - }); + assertThatExceptionOfType(MoneyFormatException.class) + .isThrownBy(() -> iCannotPrint.parseMoney("12.34 GBP")); } @Test void test_parseMoney_CharSequence_cannotParse() { - assertThrows(UnsupportedOperationException.class, () -> { - iCannotParse.parseMoney(new StringBuilder()); - }); + assertThatExceptionOfType(UnsupportedOperationException.class) + .isThrownBy(() -> iCannotParse.parseMoney(new StringBuilder())); } @Test void test_parseMoney_CharSequence_nullCharSequence() { - assertThrows(NullPointerException.class, () -> { - iParseTest.parseMoney((CharSequence) null); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> iParseTest.parseMoney((CharSequence) null)); } //----------------------------------------------------------------------- @@ -384,33 +355,33 @@ void test_parse_CharSequenceInt( CharSequence input = new StringBuilder(str); MoneyParseContext test = iParseTest.parse(input, 0); - assertEquals(amount, test.getAmount()); - assertEquals(currency, test.getCurrency()); - assertEquals(index, test.getIndex()); - assertEquals(errorIndex, test.getErrorIndex()); - assertEquals(str, test.getText().toString()); - assertEquals(str.length(), test.getTextLength()); - assertEquals(error, test.isError()); - assertEquals(fullyParsed, test.isFullyParsed()); - assertEquals(complete, test.isComplete()); + assertThat(test.getAmount()).isEqualTo(amount); + assertThat(test.getCurrency()).isEqualTo(currency); + assertThat(test.getIndex()).isEqualTo(index); + assertThat(test.getErrorIndex()).isEqualTo(errorIndex); + assertThat(test.getText()).hasToString(str); + assertThat(test.getTextLength()).isEqualTo(str.length()); + assertThat(test.isError()).isEqualTo(error); + assertThat(test.isFullyParsed()).isEqualTo(fullyParsed); + assertThat(test.isComplete()).isEqualTo(complete); ParsePosition pp = new ParsePosition(index); pp.setErrorIndex(errorIndex); - assertEquals(pp, test.toParsePosition()); + assertThat(test.toParsePosition()).isEqualTo(pp); } @Test void test_parse_CharSequenceInt_incomplete() { // this parser does nothing MoneyParseContext test = iCannotPrint.parse("12.34 GBP", 0); - 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()); - assertFalse(test.isError()); - assertFalse(test.isFullyParsed()); - assertFalse(test.isComplete()); + assertThat(test.getAmount()).isNull(); + assertThat(test.getCurrency()).isNull(); + assertThat(test.getIndex()).isEqualTo(0); + assertThat(test.getErrorIndex()).isEqualTo(-1); + assertThat(test.getText()).hasToString("12.34 GBP"); + assertThat(test.getTextLength()).isEqualTo(9); + assertThat(test.isError()).isFalse(); + assertThat(test.isFullyParsed()).isFalse(); + assertThat(test.isComplete()).isFalse(); } @Test @@ -418,15 +389,15 @@ void test_parse_CharSequenceInt_continueAfterDoubleDecimal() { MoneyFormatter f = new MoneyFormatterBuilder() .appendAmountLocalized().appendLiteral(".").appendCurrencyCode().toFormatter(); MoneyParseContext test = f.parse("12..GBP", 0); - assertEquals(BigDecimal.valueOf(12), test.getAmount()); - assertEquals(CurrencyUnit.of("GBP"), test.getCurrency()); - assertEquals(7, test.getIndex()); - assertEquals(-1, test.getErrorIndex()); - assertEquals("12..GBP", test.getText().toString()); - assertEquals(7, test.getTextLength()); - assertFalse(test.isError()); - assertTrue(test.isFullyParsed()); - assertTrue(test.isComplete()); + assertThat(test.getAmount()).isEqualTo(BigDecimal.valueOf(12)); + assertThat(test.getCurrency()).isEqualTo(CurrencyUnit.of("GBP")); + assertThat(test.getIndex()).isEqualTo(7); + assertThat(test.getErrorIndex()).isEqualTo(-1); + assertThat(test.getText()).hasToString("12..GBP"); + assertThat(test.getTextLength()).isEqualTo(7); + assertThat(test.isError()).isFalse(); + assertThat(test.isFullyParsed()).isTrue(); + assertThat(test.isComplete()).isTrue(); } @Test @@ -434,15 +405,15 @@ void test_parse_CharSequenceInt_continueAfterSingleComma() { MoneyFormatter f = new MoneyFormatterBuilder() .appendAmountLocalized().appendLiteral(",").appendCurrencyCode().toFormatter(); MoneyParseContext test = f.parse("12,GBP", 0); - assertEquals(BigDecimal.valueOf(12), test.getAmount()); - assertEquals(CurrencyUnit.of("GBP"), test.getCurrency()); - assertEquals(6, test.getIndex()); - assertEquals(-1, test.getErrorIndex()); - assertEquals("12,GBP", test.getText().toString()); - assertEquals(6, test.getTextLength()); - assertFalse(test.isError()); - assertTrue(test.isFullyParsed()); - assertTrue(test.isComplete()); + assertThat(test.getAmount()).isEqualTo(BigDecimal.valueOf(12)); + assertThat(test.getCurrency()).isEqualTo(CurrencyUnit.of("GBP")); + assertThat(test.getIndex()).isEqualTo(6); + assertThat(test.getErrorIndex()).isEqualTo(-1); + assertThat(test.getText()).hasToString("12,GBP"); + assertThat(test.getTextLength()).isEqualTo(6); + assertThat(test.isError()).isFalse(); + assertThat(test.isFullyParsed()).isTrue(); + assertThat(test.isComplete()).isTrue(); } @Test @@ -450,43 +421,39 @@ void test_parse_CharSequenceInt_continueAfterDoubleComma() { MoneyFormatter f = new MoneyFormatterBuilder() .appendAmountLocalized().appendLiteral(",,").appendCurrencyCode().toFormatter(); MoneyParseContext test = f.parse("12,,GBP", 0); - assertEquals(BigDecimal.valueOf(12), test.getAmount()); - assertEquals(CurrencyUnit.of("GBP"), test.getCurrency()); - assertEquals(7, test.getIndex()); - assertEquals(-1, test.getErrorIndex()); - assertEquals("12,,GBP", test.getText().toString()); - assertEquals(7, test.getTextLength()); - assertFalse(test.isError()); - assertTrue(test.isFullyParsed()); - assertTrue(test.isComplete()); + assertThat(test.getAmount()).isEqualTo(BigDecimal.valueOf(12)); + assertThat(test.getCurrency()).isEqualTo(CurrencyUnit.of("GBP")); + assertThat(test.getIndex()).isEqualTo(7); + assertThat(test.getErrorIndex()).isEqualTo(-1); + assertThat(test.getText()).hasToString("12,,GBP"); + assertThat(test.getTextLength()).isEqualTo(7); + assertThat(test.isError()).isFalse(); + assertThat(test.isFullyParsed()).isTrue(); + assertThat(test.isComplete()).isTrue(); } @Test void test_parse_CharSequenceInt_cannotParse() { - assertThrows(UnsupportedOperationException.class, () -> { - iCannotParse.parse(new StringBuilder(), 0); - }); + assertThatExceptionOfType(UnsupportedOperationException.class) + .isThrownBy(() -> iCannotParse.parse(new StringBuilder(), 0)); } @Test void test_parse_CharSequenceInt_nullCharSequence() { - assertThrows(NullPointerException.class, () -> { - iParseTest.parse((CharSequence) null, 0); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> iParseTest.parse((CharSequence) null, 0)); } @Test void test_parse_CharSequenceInt_startIndexTooSmall() { - assertThrows(IndexOutOfBoundsException.class, () -> { - iParseTest.parse("", -1); - }); + assertThatExceptionOfType(IndexOutOfBoundsException.class) + .isThrownBy(() -> iParseTest.parse("", -1)); } @Test void test_parse_CharSequenceInt_startIndexTooBig() { - assertThrows(IndexOutOfBoundsException.class, () -> { - iParseTest.parse("", 1); - }); + assertThatExceptionOfType(IndexOutOfBoundsException.class) + .isThrownBy(() -> iParseTest.parse("", 1)); } //----------------------------------------------------------------------- @@ -494,44 +461,39 @@ void test_parse_CharSequenceInt_startIndexTooBig() { 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")); + assertThat(f.print(MONEY_GBP_12_34)).isEqualTo("GBP BC.DE"); + assertThat(f.parseMoney("GBP BC.DE")).isEqualTo(MONEY_GBP_12_34); } @Test void test_parseMoney_notFullyParsed() { - assertThrows(MoneyFormatException.class, () -> { - iParseTest.parseMoney("GBP hello notfullyparsed"); - }); + assertThatExceptionOfType(MoneyFormatException.class) + .isThrownBy(() -> iParseTest.parseMoney("GBP hello notfullyparsed")); } @Test void test_parseMoney_noAmount() { - assertThrows(MoneyFormatException.class, () -> { - iParseTest.parseMoney("GBP hello"); - }); + assertThatExceptionOfType(MoneyFormatException.class) + .isThrownBy(() -> iParseTest.parseMoney("GBP hello")); } @Test void test_parseBigMoney_notFullyParsed() { - assertThrows(MoneyFormatException.class, () -> { - iParseTest.parseBigMoney("GBP hello notfullyparsed"); - }); + assertThatExceptionOfType(MoneyFormatException.class) + .isThrownBy(() -> iParseTest.parseBigMoney("GBP hello notfullyparsed")); } @Test void test_parseBigMoney_noAmount() { - assertThrows(MoneyFormatException.class, () -> { - iParseTest.parseBigMoney("GBP hello"); - }); + assertThatExceptionOfType(MoneyFormatException.class) + .isThrownBy(() -> iParseTest.parseBigMoney("GBP hello")); } @Test void test_parse_notFullyParsed() { - assertThrows(MoneyFormatException.class, () -> { - MoneyParseContext context = iParseTest.parse("GBP hello notfullyparsed", 1); - context.toBigMoney(); - }); + MoneyParseContext context = iParseTest.parse("GBP hello notfullyparsed", 1); + assertThatExceptionOfType(MoneyFormatException.class) + .isThrownBy(() -> context.toBigMoney()); } //----------------------------------------------------------------------- @@ -539,7 +501,7 @@ void test_parse_notFullyParsed() { //----------------------------------------------------------------------- @Test void test_toString() { - assertEquals("${code}' hello'", iPrintTest.toString()); + assertThat(iPrintTest.toString()).isEqualTo("${code}' hello'"); } @Test @@ -565,7 +527,7 @@ public String toString() { } }; MoneyFormatter f = new MoneyFormatterBuilder().append(printer, parser).toFormatter(); - assertEquals("A:B", f.toString()); + assertThat(f).hasToString("A:B"); } //----------------------------------------------------------------------- diff --git a/src/test/java/org/joda/money/format/TestMoneyFormatterBuilder.java b/src/test/java/org/joda/money/format/TestMoneyFormatterBuilder.java index 56c586b..a2ca64a 100644 --- a/src/test/java/org/joda/money/format/TestMoneyFormatterBuilder.java +++ b/src/test/java/org/joda/money/format/TestMoneyFormatterBuilder.java @@ -15,11 +15,8 @@ */ package org.joda.money.format; -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 static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType; import java.io.IOException; import java.math.BigDecimal; @@ -79,8 +76,8 @@ void afterMethod() { @Test void test_empty() { MoneyFormatter test = iBuilder.toFormatter(); - assertEquals("", test.print(GBP_2_34)); - assertEquals("", test.toString()); + assertThat(test.print(GBP_2_34)).isEmpty(); + assertThat(test).hasToString(""); } //----------------------------------------------------------------------- @@ -88,8 +85,8 @@ void test_empty() { void test_appendCurrencyCode_print() { iBuilder.appendCurrencyCode(); MoneyFormatter test = iBuilder.toFormatter(); - assertEquals("GBP", test.print(GBP_2_34)); - assertEquals("${code}", test.toString()); + assertThat(test.print(GBP_2_34)).isEqualTo("GBP"); + assertThat(test).hasToString("${code}"); } @Test @@ -97,11 +94,11 @@ void test_appendCurrencyCode_parse_ok() { iBuilder.appendCurrencyCode(); MoneyFormatter test = iBuilder.toFormatter(); MoneyParseContext parsed = test.parse("GBP", 0); - assertFalse(parsed.isError()); - assertEquals(3, parsed.getIndex()); - assertEquals(-1, parsed.getErrorIndex()); - assertNull(parsed.getAmount()); - assertEquals(CurrencyUnit.GBP, parsed.getCurrency()); + assertThat(parsed.isError()).isFalse(); + assertThat(parsed.getIndex()).isEqualTo(3); + assertThat(parsed.getErrorIndex()).isEqualTo(-1); + assertThat(parsed.getAmount()).isNull(); + assertThat(parsed.getCurrency()).isEqualTo(CurrencyUnit.GBP); } @Test @@ -109,11 +106,11 @@ void test_appendCurrencyCode_parse_tooShort() { iBuilder.appendCurrencyCode(); MoneyFormatter test = iBuilder.toFormatter(); MoneyParseContext parsed = test.parse("GB", 0); - assertTrue(parsed.isError()); - assertEquals(0, parsed.getIndex()); - assertEquals(0, parsed.getErrorIndex()); - assertNull(parsed.getAmount()); - assertNull(parsed.getCurrency()); + assertThat(parsed.isError()).isTrue(); + assertThat(parsed.getIndex()).isEqualTo(0); + assertThat(parsed.getErrorIndex()).isEqualTo(0); + assertThat(parsed.getAmount()).isNull(); + assertThat(parsed.getCurrency()).isNull(); } @Test @@ -121,11 +118,11 @@ void test_appendCurrencyCode_parse_empty() { iBuilder.appendCurrencyCode(); MoneyFormatter test = iBuilder.toFormatter(); MoneyParseContext parsed = test.parse("", 0); - assertTrue(parsed.isError()); - assertEquals(0, parsed.getIndex()); - assertEquals(0, parsed.getErrorIndex()); - assertNull(parsed.getAmount()); - assertNull(parsed.getCurrency()); + assertThat(parsed.isError()).isTrue(); + assertThat(parsed.getIndex()).isEqualTo(0); + assertThat(parsed.getErrorIndex()).isEqualTo(0); + assertThat(parsed.getAmount()).isNull(); + assertThat(parsed.getCurrency()).isNull(); } //----------------------------------------------------------------------- @@ -133,8 +130,8 @@ void test_appendCurrencyCode_parse_empty() { void test_appendCurrencyNumeric3Code_print() { iBuilder.appendCurrencyNumeric3Code(); MoneyFormatter test = iBuilder.toFormatter(); - assertEquals("826", test.print(GBP_2_34)); - assertEquals("${numeric3Code}", test.toString()); + assertThat(test.print(GBP_2_34)).isEqualTo("826"); + assertThat(test).hasToString("${numeric3Code}"); } @Test @@ -142,11 +139,11 @@ void test_appendCurrencyNumeric3Code_parse_ok() { iBuilder.appendCurrencyNumeric3Code(); MoneyFormatter test = iBuilder.toFormatter(); MoneyParseContext parsed = test.parse("826A", 0); - assertFalse(parsed.isError()); - assertEquals(3, parsed.getIndex()); - assertEquals(-1, parsed.getErrorIndex()); - assertNull(parsed.getAmount()); - assertEquals(CurrencyUnit.GBP, parsed.getCurrency()); + assertThat(parsed.isError()).isFalse(); + assertThat(parsed.getIndex()).isEqualTo(3); + assertThat(parsed.getErrorIndex()).isEqualTo(-1); + assertThat(parsed.getAmount()).isNull(); + assertThat(parsed.getCurrency()).isEqualTo(CurrencyUnit.GBP); } @Test @@ -154,11 +151,11 @@ void test_appendCurrencyNumeric3Code_parse_tooShort() { iBuilder.appendCurrencyNumeric3Code(); MoneyFormatter test = iBuilder.toFormatter(); MoneyParseContext parsed = test.parse("82", 0); - assertTrue(parsed.isError()); - assertEquals(0, parsed.getIndex()); - assertEquals(0, parsed.getErrorIndex()); - assertNull(parsed.getAmount()); - assertNull(parsed.getCurrency()); + assertThat(parsed.isError()).isTrue(); + assertThat(parsed.getIndex()).isEqualTo(0); + assertThat(parsed.getErrorIndex()).isEqualTo(0); + assertThat(parsed.getAmount()).isNull(); + assertThat(parsed.getCurrency()).isNull(); } @Test @@ -166,11 +163,11 @@ void test_appendCurrencyNumeric3Code_parse_badCurrency() { iBuilder.appendCurrencyNumeric3Code(); MoneyFormatter test = iBuilder.toFormatter(); MoneyParseContext parsed = test.parse("991A", 0); - assertTrue(parsed.isError()); - assertEquals(0, parsed.getIndex()); - assertEquals(0, parsed.getErrorIndex()); - assertNull(parsed.getAmount()); - assertNull(parsed.getCurrency()); + assertThat(parsed.isError()).isTrue(); + assertThat(parsed.getIndex()).isEqualTo(0); + assertThat(parsed.getErrorIndex()).isEqualTo(0); + assertThat(parsed.getAmount()).isNull(); + assertThat(parsed.getCurrency()).isNull(); } @Test @@ -178,11 +175,11 @@ void test_appendCurrencyNumeric3Code_parse_empty() { iBuilder.appendCurrencyNumeric3Code(); MoneyFormatter test = iBuilder.toFormatter(); MoneyParseContext parsed = test.parse("", 0); - assertTrue(parsed.isError()); - assertEquals(0, parsed.getIndex()); - assertEquals(0, parsed.getErrorIndex()); - assertNull(parsed.getAmount()); - assertNull(parsed.getCurrency()); + assertThat(parsed.isError()).isTrue(); + assertThat(parsed.getIndex()).isEqualTo(0); + assertThat(parsed.getErrorIndex()).isEqualTo(0); + assertThat(parsed.getAmount()).isNull(); + assertThat(parsed.getCurrency()).isNull(); } //----------------------------------------------------------------------- @@ -190,8 +187,8 @@ void test_appendCurrencyNumeric3Code_parse_empty() { void test_appendCurrencyNumericCode_print() { iBuilder.appendCurrencyNumericCode(); MoneyFormatter test = iBuilder.toFormatter(); - assertEquals("826", test.print(GBP_2_34)); - assertEquals("${numericCode}", test.toString()); + assertThat(test.print(GBP_2_34)).isEqualTo("826"); + assertThat(test).hasToString("${numericCode}"); } @Test @@ -199,11 +196,11 @@ void test_appendCurrencyNumericCode_parse_ok() { iBuilder.appendCurrencyNumericCode(); MoneyFormatter test = iBuilder.toFormatter(); MoneyParseContext parsed = test.parse("826A", 0); - assertFalse(parsed.isError()); - assertEquals(3, parsed.getIndex()); - assertEquals(-1, parsed.getErrorIndex()); - assertNull(parsed.getAmount()); - assertEquals(CurrencyUnit.GBP, parsed.getCurrency()); + assertThat(parsed.isError()).isFalse(); + assertThat(parsed.getIndex()).isEqualTo(3); + assertThat(parsed.getErrorIndex()).isEqualTo(-1); + assertThat(parsed.getAmount()).isNull(); + assertThat(parsed.getCurrency()).isEqualTo(CurrencyUnit.GBP); } @Test @@ -211,11 +208,11 @@ void test_appendCurrencyNumericCode_parse_ok_padded() { iBuilder.appendCurrencyNumericCode(); MoneyFormatter test = iBuilder.toFormatter(); MoneyParseContext parsed = test.parse("008A", 0); - assertFalse(parsed.isError()); - assertEquals(3, parsed.getIndex()); - assertEquals(-1, parsed.getErrorIndex()); - assertNull(parsed.getAmount()); - assertEquals("ALL", parsed.getCurrency().getCode()); + assertThat(parsed.isError()).isFalse(); + assertThat(parsed.getIndex()).isEqualTo(3); + assertThat(parsed.getErrorIndex()).isEqualTo(-1); + assertThat(parsed.getAmount()).isNull(); + assertThat(parsed.getCurrency().getCode()).isEqualTo("ALL"); } @Test @@ -223,11 +220,11 @@ void test_appendCurrencyNumericCode_parse_ok_notPadded1() { iBuilder.appendCurrencyNumericCode(); MoneyFormatter test = iBuilder.toFormatter(); MoneyParseContext parsed = test.parse("8A", 0); - assertFalse(parsed.isError()); - assertEquals(1, parsed.getIndex()); - assertEquals(-1, parsed.getErrorIndex()); - assertNull(parsed.getAmount()); - assertEquals("ALL", parsed.getCurrency().getCode()); + assertThat(parsed.isError()).isFalse(); + assertThat(parsed.getIndex()).isEqualTo(1); + assertThat(parsed.getErrorIndex()).isEqualTo(-1); + assertThat(parsed.getAmount()).isNull(); + assertThat(parsed.getCurrency().getCode()).isEqualTo("ALL"); } @Test @@ -235,11 +232,11 @@ void test_appendCurrencyNumericCode_parse_ok_notPadded2() { iBuilder.appendCurrencyNumericCode(); MoneyFormatter test = iBuilder.toFormatter(); MoneyParseContext parsed = test.parse("51 ", 0); - assertFalse(parsed.isError()); - assertEquals(2, parsed.getIndex()); - assertEquals(-1, parsed.getErrorIndex()); - assertNull(parsed.getAmount()); - assertEquals("AMD", parsed.getCurrency().getCode()); + assertThat(parsed.isError()).isFalse(); + assertThat(parsed.getIndex()).isEqualTo(2); + assertThat(parsed.getErrorIndex()).isEqualTo(-1); + assertThat(parsed.getAmount()).isNull(); + assertThat(parsed.getCurrency().getCode()).isEqualTo("AMD"); } @Test @@ -247,11 +244,11 @@ void test_appendCurrencyNumericCode_parse_tooShort() { iBuilder.appendCurrencyNumericCode(); MoneyFormatter test = iBuilder.toFormatter(); MoneyParseContext parsed = test.parse("", 0); - assertTrue(parsed.isError()); - assertEquals(0, parsed.getIndex()); - assertEquals(0, parsed.getErrorIndex()); - assertNull(parsed.getAmount()); - assertNull(parsed.getCurrency()); + assertThat(parsed.isError()).isTrue(); + assertThat(parsed.getIndex()).isEqualTo(0); + assertThat(parsed.getErrorIndex()).isEqualTo(0); + assertThat(parsed.getAmount()).isNull(); + assertThat(parsed.getCurrency()).isNull(); } @Test @@ -259,11 +256,11 @@ void test_appendCurrencyNumericCode_parse_badCurrency() { iBuilder.appendCurrencyNumericCode(); MoneyFormatter test = iBuilder.toFormatter(); MoneyParseContext parsed = test.parse("991A", 0); - assertTrue(parsed.isError()); - assertEquals(0, parsed.getIndex()); - assertEquals(0, parsed.getErrorIndex()); - assertNull(parsed.getAmount()); - assertNull(parsed.getCurrency()); + assertThat(parsed.isError()).isTrue(); + assertThat(parsed.getIndex()).isEqualTo(0); + assertThat(parsed.getErrorIndex()).isEqualTo(0); + assertThat(parsed.getAmount()).isNull(); + assertThat(parsed.getCurrency()).isNull(); } @Test @@ -271,11 +268,11 @@ void test_appendCurrencyNumericCode_parse_empty() { iBuilder.appendCurrencyNumericCode(); MoneyFormatter test = iBuilder.toFormatter(); MoneyParseContext parsed = test.parse("", 0); - assertTrue(parsed.isError()); - assertEquals(0, parsed.getIndex()); - assertEquals(0, parsed.getErrorIndex()); - assertNull(parsed.getAmount()); - assertNull(parsed.getCurrency()); + assertThat(parsed.isError()).isTrue(); + assertThat(parsed.getIndex()).isEqualTo(0); + assertThat(parsed.getErrorIndex()).isEqualTo(0); + assertThat(parsed.getAmount()).isNull(); + assertThat(parsed.getCurrency()).isNull(); } //----------------------------------------------------------------------- @@ -283,15 +280,15 @@ void test_appendCurrencyNumericCode_parse_empty() { void test_appendCurrencySymbolLocalized_print() { iBuilder.appendCurrencySymbolLocalized(); MoneyFormatter test = iBuilder.toFormatter(); - assertEquals("\u00a3", test.print(GBP_2_34)); - assertEquals("${symbolLocalized}", test.toString()); + assertThat(test.print(GBP_2_34)).isEqualTo("\u00a3"); + assertThat(test).hasToString("${symbolLocalized}"); } @Test void test_appendCurrencySymbolLocalized_parse() { iBuilder.appendCurrencySymbolLocalized(); MoneyFormatter test = iBuilder.toFormatter(); - assertFalse(test.isParser()); + assertThat(test.isParser()).isFalse(); } //----------------------------------------------------------------------- @@ -299,24 +296,24 @@ void test_appendCurrencySymbolLocalized_parse() { void test_appendLiteral_print() { iBuilder.appendLiteral("Hello"); MoneyFormatter test = iBuilder.toFormatter(); - assertEquals("Hello", test.print(GBP_2_34)); - assertEquals("'Hello'", test.toString()); + assertThat(test.print(GBP_2_34)).isEqualTo("Hello"); + assertThat(test).hasToString("'Hello'"); } @Test void test_appendLiteral_print_empty() { iBuilder.appendLiteral(""); MoneyFormatter test = iBuilder.toFormatter(); - assertEquals("", test.print(GBP_2_34)); - assertEquals("", test.toString()); + assertThat(test.print(GBP_2_34)).isEmpty(); + assertThat(test).hasToString(""); } @Test void test_appendLiteral_print_null() { iBuilder.appendLiteral((CharSequence) null); MoneyFormatter test = iBuilder.toFormatter(); - assertEquals("", test.print(GBP_2_34)); - assertEquals("", test.toString()); + assertThat(test.print(GBP_2_34)).isEmpty(); + assertThat(test).hasToString(""); } @Test @@ -324,11 +321,11 @@ void test_appendLiteral_parse_ok() { iBuilder.appendLiteral("Hello"); MoneyFormatter test = iBuilder.toFormatter(); MoneyParseContext parsed = test.parse("HelloWorld", 0); - assertFalse(parsed.isError()); - assertEquals(5, parsed.getIndex()); - assertEquals(-1, parsed.getErrorIndex()); - assertNull(parsed.getAmount()); - assertNull(parsed.getCurrency()); + assertThat(parsed.isError()).isFalse(); + assertThat(parsed.getIndex()).isEqualTo(5); + assertThat(parsed.getErrorIndex()).isEqualTo(-1); + assertThat(parsed.getAmount()).isNull(); + assertThat(parsed.getCurrency()).isNull(); } @Test @@ -336,11 +333,11 @@ void test_appendLiteral_parse_tooShort() { iBuilder.appendLiteral("Hello"); MoneyFormatter test = iBuilder.toFormatter(); MoneyParseContext parsed = test.parse("Hell", 0); - assertTrue(parsed.isError()); - assertEquals(0, parsed.getIndex()); - assertEquals(0, parsed.getErrorIndex()); - assertNull(parsed.getAmount()); - assertNull(parsed.getCurrency()); + assertThat(parsed.isError()).isTrue(); + assertThat(parsed.getIndex()).isEqualTo(0); + assertThat(parsed.getErrorIndex()).isEqualTo(0); + assertThat(parsed.getAmount()).isNull(); + assertThat(parsed.getCurrency()).isNull(); } @Test @@ -348,11 +345,11 @@ void test_appendLiteral_parse_noMatch() { iBuilder.appendLiteral("Hello"); MoneyFormatter test = iBuilder.toFormatter(); MoneyParseContext parsed = test.parse("Helol", 0); - assertTrue(parsed.isError()); - assertEquals(0, parsed.getIndex()); - assertEquals(0, parsed.getErrorIndex()); - assertNull(parsed.getAmount()); - assertNull(parsed.getCurrency()); + assertThat(parsed.isError()).isTrue(); + assertThat(parsed.getIndex()).isEqualTo(0); + assertThat(parsed.getErrorIndex()).isEqualTo(0); + assertThat(parsed.getAmount()).isNull(); + assertThat(parsed.getCurrency()).isNull(); } //----------------------------------------------------------------------- @@ -374,24 +371,24 @@ public static Object[][] data_appendAmount() { void test_appendAmount(BigMoneyProvider money, String expected) { iBuilder.appendAmount(); MoneyFormatter test = iBuilder.toFormatter(); - assertEquals(expected, test.print(money)); - assertEquals("${amount}", test.toString()); + assertThat(test.print(money)).isEqualTo(expected); + assertThat(test).hasToString("${amount}"); } @Test 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)); - assertEquals("${amount}", test.toString()); + assertThat(test.print(GBP_1234_56789)).isEqualTo("1,234.567,89"); + assertThat(test).hasToString("${amount}"); } @Test void test_appendAmount_JPY_2345() { iBuilder.appendAmount(); MoneyFormatter test = iBuilder.toFormatter(); - assertEquals("2,345", test.print(JPY_2345)); - assertEquals("${amount}", test.toString()); + assertThat(test.print(JPY_2345)).isEqualTo("2,345"); + assertThat(test).hasToString("${amount}"); } @Test @@ -399,7 +396,7 @@ void test_appendAmount_3dp_BHD() { iBuilder.appendAmount(); MoneyFormatter test = iBuilder.toFormatter(); Money money = Money.of(CurrencyUnit.of("BHD"), 6345345.735d); - assertEquals("6,345,345.735", test.print(money)); + assertThat(test.print(money)).isEqualTo("6,345,345.735"); } //----------------------------------------------------------------------- @@ -420,32 +417,31 @@ public static Object[][] data_appendAmountLocalized() { void test_appendAmountLocalized(BigMoneyProvider money, String expected) { iBuilder.appendAmountLocalized(); MoneyFormatter test = iBuilder.toFormatter(Locale.FRANCE); - assertEquals(expected, test.print(money)); - assertEquals("${amount}", test.toString()); + assertThat(test.print(money)).isEqualTo(expected); + assertThat(test).hasToString("${amount}"); } @Test 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)); - assertEquals("${amount}", test.toString()); + assertThat(test.print(GBP_1234_56789)).isEqualTo("1,234.567,89"); + assertThat(test).hasToString("${amount}"); } @Test void test_appendAmountLocalized_JPY_2345() { iBuilder.appendAmountLocalized(); MoneyFormatter test = iBuilder.toFormatter(Locale.FRANCE); - assertEquals("2" + FR_GROUP + "345", test.print(JPY_2345)); - assertEquals("${amount}", test.toString()); + assertThat(test.print(JPY_2345)).isEqualTo("2" + FR_GROUP + "345"); + assertThat(test).hasToString("${amount}"); } //----------------------------------------------------------------------- @Test void test_appendAmount_MoneyAmountStyle_null() { - assertThrows(NullPointerException.class, () -> { - iBuilder.appendAmount((MoneyAmountStyle) null); - }); + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> iBuilder.appendAmount((MoneyAmountStyle) null)); } public static Object[][] data_appendAmount_MoneyAmountStyle() { @@ -626,11 +622,11 @@ void test_appendAmount_MoneyAmountStyle_GBP( iBuilder.appendAmount(style); MoneyFormatter test = iBuilder.toFormatter(); BigMoney money = BigMoney.of(GBP, new BigDecimal(amount)); - assertEquals(expected, test.print(money)); + assertThat(test.print(money)).isEqualTo(expected); if (!style.isAbsValue()) { - assertEquals(money.getAmount(), test.parse(expected, 0).getAmount()); + assertThat(test.parse(expected, 0).getAmount()).isEqualTo(money.getAmount()); } else { - assertEquals(money.getAmount().abs(), test.parse(expected, 0).getAmount()); + assertThat(test.parse(expected, 0).getAmount()).isEqualTo(money.getAmount().abs()); } } @@ -644,11 +640,11 @@ void test_appendAmount_MoneyAmountStyle_JPY( iBuilder.appendAmount(style); MoneyFormatter test = iBuilder.toFormatter(); BigMoney money = BigMoney.of(JPY, new BigDecimal(amount)); - assertEquals(expected, test.print(money)); + assertThat(test.print(money)).isEqualTo(expected); if (!style.isAbsValue()) { - assertEquals(money.getAmount(), test.parse(expected, 0).getAmount()); + assertThat(test.parse(expected, 0).getAmount()).isEqualTo(money.getAmount()); } else { - assertEquals(money.getAmount().abs(), test.parse(expected, 0).getAmount()); + assertThat(test.parse(expected, 0).getAmount()).isEqualTo(money.getAmount().abs()); } } @@ -662,11 +658,11 @@ void test_appendAmount_MoneyAmountStyle_BHD( iBuilder.appendAmount(style); MoneyFormatter test = iBuilder.toFormatter(); BigMoney money = BigMoney.of(BHD, new BigDecimal(amount)); - assertEquals(expected, test.print(money)); + assertThat(test.print(money)).isEqualTo(expected); if (!style.isAbsValue()) { - assertEquals(money.getAmount(), test.parse(expected, 0).getAmount()); + assertThat(test.parse(expected, 0).getAmount()).isEqualTo(money.getAmount()); } else { - assertEquals(money.getAmount().abs(), test.parse(expected, 0).getAmount()); + assertThat(test.parse(expected, 0).getAmount()).isEqualTo(money.getAmount().abs()); } } @@ -678,7 +674,7 @@ void test_appendAmount_MoneyAmountStyle_JPY_issue49() { .appendAmount(style) .toFormatter() .withLocale(Locale.JAPAN); - assertEquals("12", formatter.print(money)); + assertThat(formatter.print(money)).isEqualTo("12"); } //----------------------------------------------------------------------- @@ -702,8 +698,8 @@ void test_appendAmount_parseExtendedGroupingSize(BigMoneyProvider money, String MoneyFormatter test = new MoneyFormatterBuilder() .appendAmount(MoneyAmountStyle.ASCII_DECIMAL_POINT_GROUP3_COMMA.withExtendedGroupingSize(2)) .toFormatter(); - assertEquals(expected, test.print(money)); - assertEquals("${amount}", test.toString()); + assertThat(test.print(money)).isEqualTo(expected); + assertThat(test).hasToString("${amount}"); } //----------------------------------------------------------------------- @@ -716,7 +712,7 @@ void test_appendAmount_parseExcessGrouping() { .appendAmount(MoneyAmountStyle.ASCII_DECIMAL_POINT_GROUP3_COMMA) .toFormatter(); BigMoney money = f.parseBigMoney("GBP 12,1,2,3,.,45,6,7"); - assertEquals(expected, money); + assertThat(money).isEqualTo(expected); } //----------------------------------------------------------------------- @@ -731,10 +727,10 @@ public void print(MoneyPrintContext context, Appendable appendable, BigMoney mon }; iBuilder.append(printer, null); MoneyFormatter test = iBuilder.toFormatter(); - assertTrue(test.isPrinter()); - assertFalse(test.isParser()); - assertEquals("HELLO", test.print(JPY_2345)); - assertTrue(test.toString().startsWith("org.joda.money.format.TestMoneyFormatterBuilder$")); + assertThat(test.isPrinter()).isTrue(); + assertThat(test.isParser()).isFalse(); + assertThat(test.print(JPY_2345)).isEqualTo("HELLO"); + assertThat(test.toString()).startsWith("org.joda.money.format.TestMoneyFormatterBuilder$"); } @Test @@ -749,19 +745,19 @@ public void parse(MoneyParseContext context) { }; iBuilder.append(null, parser); MoneyFormatter test = iBuilder.toFormatter(); - assertFalse(test.isPrinter()); - assertTrue(test.isParser()); - assertEquals(JPY_2345, test.parseMoney("")); - assertTrue(test.toString().startsWith("org.joda.money.format.TestMoneyFormatterBuilder$")); + assertThat(test.isPrinter()).isFalse(); + assertThat(test.isParser()).isTrue(); + assertThat(test.parseMoney("")).isEqualTo(JPY_2345); + assertThat(test.toString()).startsWith("org.joda.money.format.TestMoneyFormatterBuilder$"); } @Test void test_append_MoneyPrinter_nullMoneyPrinter_nullMoneyParser() { iBuilder.append((MoneyPrinter) null, (MoneyParser) null); MoneyFormatter test = iBuilder.toFormatter(); - assertFalse(test.isPrinter()); - assertFalse(test.isParser()); - assertEquals("", test.toString()); + assertThat(test.isPrinter()).isFalse(); + assertThat(test.isParser()).isFalse(); + assertThat(test).hasToString(""); } //----------------------------------------------------------------------- @@ -769,7 +765,7 @@ void test_append_MoneyPrinter_nullMoneyPrinter_nullMoneyParser() { 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)); + assertThat(f2.print(GBP_2345_67)).isEqualTo("GBP 2,345.67"); } //----------------------------------------------------------------------- @@ -788,18 +784,17 @@ void test_appendSigned_PN() { .appendLiteral(")") .toFormatter(); MoneyFormatter f = new MoneyFormatterBuilder().appendSigned(pos, neg).toFormatter(); - assertEquals( - "PositiveZeroNegative(${code}' '${amount},${code}' '${amount},'('${code}' '${amount}')')", - f.toString()); - assertEquals("GBP 234.56", f.print(GBP_234_56)); - assertEquals("GBP 0.00", f.print(Money.zero(GBP))); - assertEquals("(GBP 234.56)", f.print(GBP_MINUS_234_56)); - assertEquals(GBP_234_56, f.parseMoney("GBP 234.56")); - assertEquals(Money.zero(GBP), f.parseMoney("GBP 0")); - assertEquals(GBP_MINUS_234_56, f.parseMoney("(GBP 234.56)")); + assertThat(f) + .hasToString("PositiveZeroNegative(${code}' '${amount},${code}' '${amount},'('${code}' '${amount}')')"); + assertThat(f.print(GBP_234_56)).isEqualTo("GBP 234.56"); + assertThat(f.print(Money.zero(GBP))).isEqualTo("GBP 0.00"); + assertThat(f.print(GBP_MINUS_234_56)).isEqualTo("(GBP 234.56)"); + assertThat(f.parseMoney("GBP 234.56")).isEqualTo(GBP_234_56); + assertThat(f.parseMoney("GBP 0")).isEqualTo(Money.zero(GBP)); + assertThat(f.parseMoney("(GBP 234.56)")).isEqualTo(GBP_MINUS_234_56); MoneyParseContext context = f.parse("X", 0); - assertEquals(0, context.getIndex()); - assertEquals(0, context.getErrorIndex()); + assertThat(context.getIndex()).isEqualTo(0); + assertThat(context.getErrorIndex()).isEqualTo(0); } //----------------------------------------------------------------------- @@ -822,14 +817,14 @@ void test_appendSigned_PZN() { .appendLiteral(")") .toFormatter(); MoneyFormatter f = new MoneyFormatterBuilder().appendSigned(pos, zro, neg).toFormatter(); - assertEquals("GBP 234.56", f.print(GBP_234_56)); - assertEquals("GBP -", f.print(Money.zero(GBP))); - assertEquals("(GBP 234.56)", f.print(GBP_MINUS_234_56)); - assertEquals(GBP_234_56, f.parseMoney("GBP 234.56")); - assertEquals(GBP_MINUS_234_56, f.parseMoney("GBP -234.56")); - assertEquals(Money.zero(GBP), f.parseMoney("GBP -")); - assertEquals(GBP_MINUS_234_56, f.parseMoney("(GBP 234.56)")); - assertEquals(GBP_MINUS_234_56, f.parseMoney("(GBP -234.56)")); + assertThat(f.print(GBP_234_56)).isEqualTo("GBP 234.56"); + assertThat(f.print(Money.zero(GBP))).isEqualTo("GBP -"); + assertThat(f.print(GBP_MINUS_234_56)).isEqualTo("(GBP 234.56)"); + assertThat(f.parseMoney("GBP 234.56")).isEqualTo(GBP_234_56); + assertThat(f.parseMoney("GBP -234.56")).isEqualTo(GBP_MINUS_234_56); + assertThat(f.parseMoney("GBP -")).isEqualTo(Money.zero(GBP)); + assertThat(f.parseMoney("(GBP 234.56)")).isEqualTo(GBP_MINUS_234_56); + assertThat(f.parseMoney("(GBP -234.56)")).isEqualTo(GBP_MINUS_234_56); } @Test @@ -848,26 +843,26 @@ void test_appendSigned_PZN_edgeCases() { .toFormatter(); MoneyFormatter f = new MoneyFormatterBuilder() .appendCurrencyCode().appendLiteral(" ").appendSigned(pos, zro, neg).toFormatter(); - assertEquals("GBP 234.56", f.print(GBP_234_56)); - assertEquals("GBP 0.00 (zero)", f.print(BigMoney.zero(GBP).withScale(2))); - assertEquals("GBP (234.56)", f.print(GBP_MINUS_234_56)); - assertEquals(GBP_234_56.toBigMoney(), f.parseBigMoney("GBP 234.56")); - assertEquals(BigMoney.zero(GBP).withScale(2), f.parseBigMoney("GBP 0.00 (zero)")); - assertEquals(BigMoney.zero(GBP), f.parseBigMoney("GBP 1.23 (zero)")); - assertEquals(GBP_MINUS_234_56.toBigMoney(), f.parseBigMoney("GBP (234.56)")); + assertThat(f.print(GBP_234_56)).isEqualTo("GBP 234.56"); + assertThat(f.print(BigMoney.zero(GBP).withScale(2))).isEqualTo("GBP 0.00 (zero)"); + assertThat(f.print(GBP_MINUS_234_56)).isEqualTo("GBP (234.56)"); + assertThat(f.parseBigMoney("GBP 234.56")).isEqualTo(GBP_234_56.toBigMoney()); + assertThat(f.parseBigMoney("GBP 0.00 (zero)")).isEqualTo(BigMoney.zero(GBP).withScale(2)); + assertThat(f.parseBigMoney("GBP 1.23 (zero)")).isEqualTo(BigMoney.zero(GBP)); + assertThat(f.parseBigMoney("GBP (234.56)")).isEqualTo(GBP_MINUS_234_56.toBigMoney()); } //----------------------------------------------------------------------- @Test void test_toFormatter_defaultLocale() { MoneyFormatter test = iBuilder.toFormatter(); - assertEquals(TEST_GB_LOCALE, test.getLocale()); + assertThat(test.getLocale()).isEqualTo(TEST_GB_LOCALE); } @Test void test_toFormatter_Locale() { MoneyFormatter test = iBuilder.toFormatter(TEST_FR_LOCALE); - assertEquals(TEST_FR_LOCALE, test.getLocale()); + assertThat(test.getLocale()).isEqualTo(TEST_FR_LOCALE); } } diff --git a/src/test/java/org/joda/money/format/TestMoneyFormatterException.java b/src/test/java/org/joda/money/format/TestMoneyFormatterException.java index 58d07b6..58f6992 100644 --- a/src/test/java/org/joda/money/format/TestMoneyFormatterException.java +++ b/src/test/java/org/joda/money/format/TestMoneyFormatterException.java @@ -15,8 +15,8 @@ */ package org.joda.money.format; -import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; -import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.assertj.core.api.Assertions.assertThatNoException; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType; import java.io.IOException; @@ -30,13 +30,15 @@ class TestMoneyFormatterException { @Test void test_MoneyFormatException_IOException_notRethrown() { MoneyFormatException test = new MoneyFormatException("Error", new IOException("Inner")); - assertThrows(IOException.class, () -> test.rethrowIOException()); + assertThatExceptionOfType(IOException.class) + .isThrownBy(() -> test.rethrowIOException()); } @Test void test_MoneyFormatException_nonIOException_notRethrown() throws IOException { MoneyFormatException test = new MoneyFormatException("Error", new IllegalStateException("Inner")); - assertDoesNotThrow(() -> test.rethrowIOException()); + assertThatNoException() + .isThrownBy(() -> 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 dca6be2..0f2d271 100644 --- a/src/test/java/org/joda/money/format/TestMoneyParseContext.java +++ b/src/test/java/org/joda/money/format/TestMoneyParseContext.java @@ -15,10 +15,8 @@ */ package org.joda.money.format; -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.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType; import java.math.BigDecimal; import java.text.ParsePosition; @@ -35,55 +33,55 @@ class TestMoneyParseContext { @Test void test_initialState() { MoneyParseContext test = new MoneyParseContext(Locale.FRANCE, "GBP 123", 0); - assertNull(test.getAmount()); - assertNull(test.getCurrency()); - assertEquals(0, test.getIndex()); - assertEquals(-1, test.getErrorIndex()); - assertEquals("GBP 123", test.getText().toString()); - assertEquals(7, test.getTextLength()); - assertFalse(test.isError()); - assertFalse(test.isFullyParsed()); - assertFalse(test.isComplete()); + assertThat(test.getAmount()).isNull(); + assertThat(test.getCurrency()).isNull(); + assertThat(test.getIndex()).isEqualTo(0); + assertThat(test.getErrorIndex()).isEqualTo(-1); + assertThat(test.getText()).hasToString("GBP 123"); + assertThat(test.getTextLength()).isEqualTo(7); + assertThat(test.isError()).isFalse(); + assertThat(test.isFullyParsed()).isFalse(); + assertThat(test.isComplete()).isFalse(); ParsePosition pp = new ParsePosition(0); pp.setErrorIndex(-1); - assertEquals(pp, test.toParsePosition()); + assertThat(test.toParsePosition()).isEqualTo(pp); } @Test void test_setIndex() { MoneyParseContext test = new MoneyParseContext(Locale.FRANCE, "GBP 123", 0); - assertEquals(0, test.getIndex()); + assertThat(test.getIndex()).isEqualTo(0); test.setIndex(2); - assertEquals(2, test.getIndex()); + assertThat(test.getIndex()).isEqualTo(2); } @Test void test_setErrorIndex() { MoneyParseContext test = new MoneyParseContext(Locale.FRANCE, "GBP 123", 0); - assertEquals(-1, test.getErrorIndex()); + assertThat(test.getErrorIndex()).isEqualTo(-1); test.setErrorIndex(3); - assertEquals(3, test.getErrorIndex()); + assertThat(test.getErrorIndex()).isEqualTo(3); } @Test void test_setError() { MoneyParseContext test = new MoneyParseContext(Locale.FRANCE, "GBP 123", 0); - assertEquals(0, test.getIndex()); - assertEquals(-1, test.getErrorIndex()); + assertThat(test.getIndex()).isEqualTo(0); + assertThat(test.getErrorIndex()).isEqualTo(-1); test.setError(); - assertEquals(0, test.getIndex()); - assertEquals(0, test.getErrorIndex()); + assertThat(test.getIndex()).isEqualTo(0); + assertThat(test.getErrorIndex()).isEqualTo(0); } @Test void test_setError_withIndex() { MoneyParseContext test = new MoneyParseContext(Locale.FRANCE, "GBP 123", 0); - assertEquals(0, test.getIndex()); - assertEquals(-1, test.getErrorIndex()); + assertThat(test.getIndex()).isEqualTo(0); + assertThat(test.getErrorIndex()).isEqualTo(-1); test.setIndex(2); test.setError(); - assertEquals(2, test.getIndex()); - assertEquals(2, test.getErrorIndex()); + assertThat(test.getIndex()).isEqualTo(2); + assertThat(test.getErrorIndex()).isEqualTo(2); } //----------------------------------------------------------------------- @@ -91,56 +89,52 @@ void test_setError_withIndex() { void test_isComplete_noCurrency() { MoneyParseContext test = new MoneyParseContext(Locale.FRANCE, "GBP 123", 0); test.setAmount(BigDecimal.TEN); - assertFalse(test.isComplete()); + assertThat(test.isComplete()).isFalse(); } @Test void test_isComplete_noAmount() { MoneyParseContext test = new MoneyParseContext(Locale.FRANCE, "GBP 123", 0); test.setCurrency(CurrencyUnit.GBP); - assertFalse(test.isComplete()); + assertThat(test.isComplete()).isFalse(); } @Test void test_toBigMoney_noCurrency() { MoneyParseContext test = new MoneyParseContext(Locale.FRANCE, "GBP 123", 0); test.setAmount(BigDecimal.TEN); - assertThrows(MoneyFormatException.class, () -> { - test.toBigMoney(); - }); + assertThatExceptionOfType(MoneyFormatException.class) + .isThrownBy(() -> test.toBigMoney()); } @Test void test_toBigMoney_noAmount() { MoneyParseContext test = new MoneyParseContext(Locale.FRANCE, "GBP 123", 0); test.setCurrency(CurrencyUnit.GBP); - assertThrows(MoneyFormatException.class, () -> { - test.toBigMoney(); - }); + assertThatExceptionOfType(MoneyFormatException.class) + .isThrownBy(() -> test.toBigMoney()); } //----------------------------------------------------------------------- @Test 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)); + assertThat(test.getTextSubstring(0, 2)).isEqualTo("GB"); + assertThat(test.getTextSubstring(5, 7)).isEqualTo("23"); } @Test void test_getTextSubstring_beforeStart() { MoneyParseContext test = new MoneyParseContext(Locale.FRANCE, "GBP 123", 0); - assertThrows(IndexOutOfBoundsException.class, () -> { - test.getTextSubstring(-1, 2); - }); + assertThatExceptionOfType(IndexOutOfBoundsException.class) + .isThrownBy(() -> test.getTextSubstring(-1, 2)); } @Test void test_getTextSubstring_afterEnd() { MoneyParseContext test = new MoneyParseContext(Locale.FRANCE, "GBP 123", 0); - assertThrows(IndexOutOfBoundsException.class, () -> { - test.getTextSubstring(0, 8); - }); + assertThatExceptionOfType(IndexOutOfBoundsException.class) + .isThrownBy(() -> test.getTextSubstring(0, 8)); } }