From 99ec0ddbce2a7bcf55c52b3fc5ccebb3d6fca887 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Mon, 19 Aug 2024 12:31:32 +0100 Subject: [PATCH] Use modern Java language features --- src/main/java/org/joda/money/BigMoney.java | 251 +++--- .../java/org/joda/money/BigMoneyProvider.java | 4 +- .../joda/money/CurrencyMismatchException.java | 6 +- .../java/org/joda/money/CurrencyUnit.java | 82 +- .../joda/money/CurrencyUnitDataProvider.java | 2 +- .../DefaultCurrencyUnitDataProvider.java | 32 +- .../joda/money/IllegalCurrencyException.java | 2 +- src/main/java/org/joda/money/Money.java | 150 ++-- src/main/java/org/joda/money/MoneyUtils.java | 26 +- src/main/java/org/joda/money/Ser.java | 46 +- .../money/format/AmountPrinterParser.java | 54 +- .../money/format/LiteralPrinterParser.java | 2 +- .../joda/money/format/MoneyAmountStyle.java | 86 +- .../money/format/MoneyFormatException.java | 4 +- .../org/joda/money/format/MoneyFormatter.java | 46 +- .../money/format/MoneyFormatterBuilder.java | 60 +- .../joda/money/format/MoneyParseContext.java | 48 +- .../org/joda/money/format/MoneyParser.java | 4 +- .../joda/money/format/MoneyPrintContext.java | 6 +- .../org/joda/money/format/MoneyPrinter.java | 4 +- .../joda/money/format/MultiPrinterParser.java | 18 +- .../money/format/SignedPrinterParser.java | 10 +- .../java/org/joda/money/TestBigMoney.java | 818 +++++++++--------- .../money/TestCurrencyMismatchException.java | 8 +- .../java/org/joda/money/TestCurrencyUnit.java | 238 +++-- .../joda/money/TestCurrencyUnitExtension.java | 16 +- .../money/TestIllegalCurrencyException.java | 4 +- src/test/java/org/joda/money/TestMoney.java | 623 +++++++------ .../joda/money/TestMoneyUtils_BigMoney.java | 3 +- .../org/joda/money/TestStringConvert.java | 13 +- .../money/format/TestMoneyAmountStyle.java | 274 +++--- .../joda/money/format/TestMoneyFormatter.java | 122 ++- .../format/TestMoneyFormatterBuilder.java | 205 +++-- .../format/TestMoneyFormatterException.java | 4 +- .../money/format/TestMoneyParseContext.java | 26 +- 35 files changed, 1609 insertions(+), 1688 deletions(-) diff --git a/src/main/java/org/joda/money/BigMoney.java b/src/main/java/org/joda/money/BigMoney.java index c5d0a68..c6510fa 100644 --- a/src/main/java/org/joda/money/BigMoney.java +++ b/src/main/java/org/joda/money/BigMoney.java @@ -78,9 +78,9 @@ public final class BigMoney implements BigMoneyProvider, Comparable monies) { MoneyUtils.checkNotNull(monies, "Money iterator must not be null"); Iterator it = monies.iterator(); - if (it.hasNext() == false) { + if (!it.hasNext()) { throw new IllegalArgumentException("Money iterator must not be empty"); } - BigMoney total = of(it.next()); + var total = of(it.next()); MoneyUtils.checkNotNull(total, "Money iterator must not contain null entries"); while (it.hasNext()) { total = total.plus(it.next()); @@ -325,7 +325,7 @@ public static BigMoney total(Iterable monies) { * The amounts are added as though using {@link #plus(BigMoneyProvider)} starting * from zero in the specified currency. * All amounts must be in the same currency. - * + * * @param currency the currency to total in, not null * @param monies the monetary values to total, no null elements, not null * @return the total, never null @@ -342,7 +342,7 @@ public static BigMoney total(CurrencyUnit currency, BigMoneyProvider... monies) * The amounts are added as though using {@link #plus(BigMoneyProvider)} starting * from zero in the specified currency. * All amounts must be in the same currency. - * + * * @param currency the currency to total in, not null * @param monies the monetary values to total, no null elements, not null * @return the total, never null @@ -377,13 +377,13 @@ public static BigMoney parse(String moneyStr) { if (moneyStr.length() < 4) { throw new IllegalArgumentException("Money '" + moneyStr + "' cannot be parsed"); } - String currStr = moneyStr.substring(0, 3); - int amountStart = 3; + var currStr = moneyStr.substring(0, 3); + var amountStart = 3; while (amountStart < moneyStr.length() && moneyStr.charAt(amountStart) == ' ') { amountStart++; } - String amountStr = moneyStr.substring(amountStart); - if (PARSE_REGEX.matcher(amountStr).matches() == false) { + var amountStr = moneyStr.substring(amountStart); + if (!PARSE_REGEX.matcher(amountStr).matches()) { throw new IllegalArgumentException("Money amount '" + moneyStr + "' cannot be parsed"); } return BigMoney.of(CurrencyUnit.of(currStr), new BigDecimal(amountStr)); @@ -401,7 +401,7 @@ private BigMoney() { /** * Constructor, creating a new monetary instance. - * + * * @param currency the currency to use, not null * @param amount the amount of money, not null */ @@ -414,7 +414,7 @@ private BigMoney() { /** * Block malicious data streams. - * + * * @param ois the input stream, not null * @throws InvalidObjectException if an error occurs */ @@ -424,7 +424,7 @@ private void readObject(ObjectInputStream ois) throws InvalidObjectException { /** * Uses a serialization delegate. - * + * * @return the replacing object, never null */ private Object writeReplace() { @@ -436,7 +436,7 @@ private Object writeReplace() { * Returns a new {@code BigMoney}, returning {@code this} if possible. *

* This instance is immutable and unaffected by this method. - * + * * @param newAmount the new amount to use, not null * @return the new instance, never null */ @@ -450,7 +450,7 @@ private BigMoney with(BigDecimal newAmount) { //----------------------------------------------------------------------- /** * Gets the currency. - * + * * @return the currency, never null */ public CurrencyUnit getCurrencyUnit() { @@ -465,7 +465,7 @@ public CurrencyUnit getCurrencyUnit() { * from this instance. No currency conversion or alteration to the scale occurs. *

* This instance is immutable and unaffected by this method. - * + * * @param currency the currency to use, not null * @return the new instance with the input currency set, never null */ @@ -486,7 +486,7 @@ public BigMoney withCurrencyUnit(CurrencyUnit currency) { * Negative numbers represent the opposite. * For example, a scale of 2 means that the money will have two decimal places * such as 'USD 43.25'. The scale of will not be negative. - * + * * @return the scale in use * @see #withScale */ @@ -499,7 +499,7 @@ public int getScale() { *

* Each currency has a default scale, such as 2 for USD and 0 for JPY. * This method checks if the current scale matches the default scale. - * + * * @return true if the scale equals the current default scale */ public boolean isCurrencyScale() { @@ -518,7 +518,7 @@ public boolean isCurrencyScale() { * A negative scale may be passed in, but the result will have a minimum scale of zero. *

* This instance is immutable and unaffected by this method. - * + * * @param scale the scale to use * @return the new instance with the input amount set, never null * @throws ArithmeticException if the rounding fails @@ -537,7 +537,7 @@ public BigMoney withScale(int scale) { * A negative scale may be passed in, but the result will have a minimum scale of zero. *

* This instance is immutable and unaffected by this method. - * + * * @param scale the scale to use * @param roundingMode the rounding mode to use, not null * @return the new instance with the input amount set, never null @@ -562,7 +562,7 @@ public BigMoney withScale(int scale, RoundingMode roundingMode) { * scale less than or equal to the new scale. *

* This instance is immutable and unaffected by this method. - * + * * @return the new instance with the input amount set, never null * @throws ArithmeticException if the rounding fails */ @@ -578,7 +578,7 @@ public BigMoney withCurrencyScale() { * For example, scaling 'USD 43.271' will yield 'USD 43.27' as USD has a scale of 2. *

* This instance is immutable and unaffected by this method. - * + * * @param roundingMode the rounding mode to use, not null * @return the new instance with the input amount set, never null * @throws ArithmeticException if the rounding fails @@ -593,7 +593,7 @@ public BigMoney withCurrencyScale(RoundingMode roundingMode) { *

* This returns the value of the money as a {@code BigDecimal}. * The scale will be the scale of this money. - * + * * @return the amount, never null */ public BigDecimal getAmount() { @@ -610,7 +610,7 @@ public BigDecimal getAmount() { * This is returned as a {@code BigDecimal} rather than a {@code BigInteger}. * This is to allow further calculations to be performed on the result. * Should you need a {@code BigInteger}, simply call {@link BigDecimal#toBigInteger()}. - * + * * @return the major units part of the amount, never null */ public BigDecimal getAmountMajor() { @@ -623,7 +623,7 @@ public BigDecimal getAmountMajor() { * This returns the monetary amount in terms of the major units of the currency, * truncating the amount if necessary. * For example, 'EUR 2.35' will return 2, and 'BHD -1.345' will return -1. - * + * * @return the major units part of the amount * @throws ArithmeticException if the amount is too large for a {@code long} */ @@ -637,7 +637,7 @@ public long getAmountMajorLong() { * This returns the monetary amount in terms of the major units of the currency, * truncating the amount if necessary. * For example, 'EUR 2.35' will return 2, and 'BHD -1.345' will return -1. - * + * * @return the major units part of the amount * @throws ArithmeticException if the amount is too large for an {@code int} */ @@ -655,11 +655,11 @@ public int getAmountMajorInt() { * This is returned as a {@code BigDecimal} rather than a {@code BigInteger}. * This is to allow further calculations to be performed on the result. * Should you need a {@code BigInteger}, simply call {@link BigDecimal#toBigInteger()}. - * + * * @return the minor units part of the amount, never null */ public BigDecimal getAmountMinor() { - int cdp = getCurrencyUnit().getDecimalPlaces(); + var cdp = getCurrencyUnit().getDecimalPlaces(); return amount.setScale(cdp, RoundingMode.DOWN).movePointRight(cdp); } @@ -669,7 +669,7 @@ public BigDecimal getAmountMinor() { * This returns the monetary amount in terms of the minor units of the currency, * truncating the amount if necessary. * For example, 'EUR 2.35' will return 235, and 'BHD -1.345' will return -1345. - * + * * @return the minor units part of the amount * @throws ArithmeticException if the amount is too large for a {@code long} */ @@ -683,7 +683,7 @@ public long getAmountMinorLong() { * This returns the monetary amount in terms of the minor units of the currency, * truncating the amount if necessary. * For example, 'EUR 2.35' will return 235, and 'BHD -1.345' will return -1345. - * + * * @return the minor units part of the amount * @throws ArithmeticException if the amount is too large for an {@code int} */ @@ -700,11 +700,11 @@ public int getAmountMinorInt() { * For example, EUR has a scale of 2, so the minor part is always between 0 and 99 * for positive amounts, and 0 and -99 for negative amounts. * Thus 'EUR 2.35' will return 35, and 'EUR -1.34' will return -34. - * + * * @return the minor part of the amount, negative if the amount is negative */ public int getMinorPart() { - int cdp = getCurrencyUnit().getDecimalPlaces(); + var cdp = getCurrencyUnit().getDecimalPlaces(); return amount.setScale(cdp, RoundingMode.DOWN) .remainder(BigDecimal.ONE) .movePointRight(cdp).intValueExact(); @@ -713,7 +713,7 @@ public int getMinorPart() { //----------------------------------------------------------------------- /** * Checks if the amount is zero. - * + * * @return true if the amount is zero */ public boolean isZero() { @@ -722,7 +722,7 @@ public boolean isZero() { /** * Checks if the amount is greater than zero. - * + * * @return true if the amount is greater than zero */ public boolean isPositive() { @@ -731,7 +731,7 @@ public boolean isPositive() { /** * Checks if the amount is zero or greater. - * + * * @return true if the amount is zero or greater */ public boolean isPositiveOrZero() { @@ -740,7 +740,7 @@ public boolean isPositiveOrZero() { /** * Checks if the amount is less than zero. - * + * * @return true if the amount is less than zero */ public boolean isNegative() { @@ -749,7 +749,7 @@ public boolean isNegative() { /** * Checks if the amount is zero or less. - * + * * @return true if the amount is zero or less */ public boolean isNegativeOrZero() { @@ -764,7 +764,7 @@ public boolean isNegativeOrZero() { * The scale of the returned instance will be that of the specified BigDecimal. *

* This instance is immutable and unaffected by this method. - * + * * @param amount the monetary amount to set in the returned instance, not null * @return the new instance with the input amount set, never null */ @@ -790,7 +790,7 @@ public BigMoney withAmount(BigDecimal amount) { * The scale of the money will be that of the BigDecimal produced. *

* This instance is immutable and unaffected by this method. - * + * * @param amount the monetary amount to set in the returned instance * @return the new instance with the input amount set, never null */ @@ -801,13 +801,13 @@ public BigMoney withAmount(double amount) { //----------------------------------------------------------------------- /** * Validates that the currency of this money and the specified money match. - * + * * @param moneyProvider the money to check, not null * @throws CurrencyMismatchException if the currencies differ */ private BigMoney checkCurrencyEqual(BigMoneyProvider moneyProvider) { - BigMoney money = of(moneyProvider); - if (isSameCurrency(money) == false) { + var money = of(moneyProvider); + if (!isSameCurrency(money)) { throw new CurrencyMismatchException(getCurrencyUnit(), money.getCurrencyUnit()); } return money; @@ -822,15 +822,15 @@ private BigMoney checkCurrencyEqual(BigMoneyProvider moneyProvider) { * The amounts must be in the same currency. *

* This instance is immutable and unaffected by this method. - * + * * @param moniesToAdd the monetary values to add, no null elements, not null * @return the new instance with the input amounts added, never null * @throws CurrencyMismatchException if the currencies differ */ public BigMoney plus(Iterable moniesToAdd) { - BigDecimal total = amount; + var total = amount; for (BigMoneyProvider moneyProvider : moniesToAdd) { - BigMoney money = checkCurrencyEqual(moneyProvider); + var money = checkCurrencyEqual(moneyProvider); total = total.add(money.amount); } return with(total); @@ -848,13 +848,13 @@ public BigMoney plus(Iterable moniesToAdd) { * For example, 'USD 25.95' plus 'USD 3.021' gives 'USD 28.971'. *

* This instance is immutable and unaffected by this method. - * + * * @param moneyToAdd the monetary value to add, not null * @return the new instance with the input amount added, never null * @throws CurrencyMismatchException if the currencies differ */ public BigMoney plus(BigMoneyProvider moneyToAdd) { - BigMoney toAdd = checkCurrencyEqual(moneyToAdd); + var toAdd = checkCurrencyEqual(moneyToAdd); return plus(toAdd.getAmount()); } @@ -868,7 +868,7 @@ public BigMoney plus(BigMoneyProvider moneyToAdd) { * For example, 'USD 25.95' plus '3.021' gives 'USD 28.971'. *

* This instance is immutable and unaffected by this method. - * + * * @param amountToAdd the monetary value to add, not null * @return the new instance with the input amount added, never null */ @@ -877,7 +877,7 @@ public BigMoney plus(BigDecimal amountToAdd) { if (amountToAdd.compareTo(BigDecimal.ZERO) == 0) { return this; } - BigDecimal newAmount = amount.add(amountToAdd); + var newAmount = amount.add(amountToAdd); return BigMoney.of(currency, newAmount); } @@ -897,7 +897,7 @@ public BigMoney plus(BigDecimal amountToAdd) { * For example, the literal '1.45d' will be converted to '1.45'. *

* This instance is immutable and unaffected by this method. - * + * * @param amountToAdd the monetary value to add, not null * @return the new instance with the input amount added, never null */ @@ -905,7 +905,7 @@ public BigMoney plus(double amountToAdd) { if (amountToAdd == 0) { return this; } - BigDecimal newAmount = amount.add(BigDecimal.valueOf(amountToAdd)); + var newAmount = amount.add(BigDecimal.valueOf(amountToAdd)); return BigMoney.of(currency, newAmount); } @@ -920,7 +920,7 @@ public BigMoney plus(double amountToAdd) { * For example, 'USD 23.45' plus '138' gives 'USD 161.45'. *

* This instance is immutable and unaffected by this method. - * + * * @param amountToAdd the monetary value to add, not null * @return the new instance with the input amount added, never null */ @@ -928,7 +928,7 @@ public BigMoney plusMajor(long amountToAdd) { if (amountToAdd == 0) { return this; } - BigDecimal newAmount = amount.add(BigDecimal.valueOf(amountToAdd)); + var newAmount = amount.add(BigDecimal.valueOf(amountToAdd)); return BigMoney.of(currency, newAmount); } @@ -943,7 +943,7 @@ public BigMoney plusMajor(long amountToAdd) { * For example, 'USD 23.45' plus '138' gives 'USD 24.83'. *

* This instance is immutable and unaffected by this method. - * + * * @param amountToAdd the monetary value to add, not null * @return the new instance with the input amount added, never null */ @@ -951,7 +951,7 @@ public BigMoney plusMinor(long amountToAdd) { if (amountToAdd == 0) { return this; } - BigDecimal newAmount = amount.add(BigDecimal.valueOf(amountToAdd, currency.getDecimalPlaces())); + var newAmount = amount.add(BigDecimal.valueOf(amountToAdd, currency.getDecimalPlaces())); return BigMoney.of(currency, newAmount); } @@ -964,13 +964,13 @@ public BigMoney plusMinor(long amountToAdd) { * For example,'USD 25.95' plus 'USD 3.021' gives 'USD 28.97' with most rounding modes. *

* This instance is immutable and unaffected by this method. - * + * * @param moneyToAdd the monetary value to add, not null * @param roundingMode the rounding mode to use to adjust the scale, not null * @return the new instance with the input amount added, never null */ public BigMoney plusRetainScale(BigMoneyProvider moneyToAdd, RoundingMode roundingMode) { - BigMoney toAdd = checkCurrencyEqual(moneyToAdd); + var toAdd = checkCurrencyEqual(moneyToAdd); return plusRetainScale(toAdd.getAmount(), roundingMode); } @@ -982,7 +982,7 @@ public BigMoney plusRetainScale(BigMoneyProvider moneyToAdd, RoundingMode roundi * For example,'USD 25.95' plus '3.021' gives 'USD 28.97' with most rounding modes. *

* This instance is immutable and unaffected by this method. - * + * * @param amountToAdd the monetary value to add, not null * @param roundingMode the rounding mode to use to adjust the scale, not null * @return the new instance with the input amount added, never null @@ -992,7 +992,7 @@ public BigMoney plusRetainScale(BigDecimal amountToAdd, RoundingMode roundingMod if (amountToAdd.compareTo(BigDecimal.ZERO) == 0) { return this; } - BigDecimal newAmount = amount.add(amountToAdd); + var newAmount = amount.add(amountToAdd); newAmount = newAmount.setScale(getScale(), roundingMode); return BigMoney.of(currency, newAmount); } @@ -1011,7 +1011,7 @@ public BigMoney plusRetainScale(BigDecimal amountToAdd, RoundingMode roundingMod * For example, the literal '1.45d' will be converted to '1.45'. *

* This instance is immutable and unaffected by this method. - * + * * @param amountToAdd the monetary value to add, not null * @param roundingMode the rounding mode to use to adjust the scale, not null * @return the new instance with the input amount added, never null @@ -1020,7 +1020,7 @@ public BigMoney plusRetainScale(double amountToAdd, RoundingMode roundingMode) { if (amountToAdd == 0) { return this; } - BigDecimal newAmount = amount.add(BigDecimal.valueOf(amountToAdd)); + var newAmount = amount.add(BigDecimal.valueOf(amountToAdd)); newAmount = newAmount.setScale(getScale(), roundingMode); return BigMoney.of(currency, newAmount); } @@ -1034,15 +1034,15 @@ public BigMoney plusRetainScale(double amountToAdd, RoundingMode roundingMode) { * The amounts must be in the same currency. *

* This instance is immutable and unaffected by this method. - * + * * @param moniesToSubtract the monetary values to subtract, no null elements, not null * @return the new instance with the input amounts subtracted, never null * @throws CurrencyMismatchException if the currencies differ */ public BigMoney minus(Iterable moniesToSubtract) { - BigDecimal total = amount; + var total = amount; for (BigMoneyProvider moneyProvider : moniesToSubtract) { - BigMoney money = checkCurrencyEqual(moneyProvider); + var money = checkCurrencyEqual(moneyProvider); total = total.subtract(money.amount); } return with(total); @@ -1060,13 +1060,13 @@ public BigMoney minus(Iterable moniesToSubtract) { * For example,'USD 25.95' minus 'USD 3.021' gives 'USD 22.929'. *

* This instance is immutable and unaffected by this method. - * + * * @param moneyToSubtract the monetary value to subtract, not null * @return the new instance with the input amount subtracted, never null * @throws CurrencyMismatchException if the currencies differ */ public BigMoney minus(BigMoneyProvider moneyToSubtract) { - BigMoney toSubtract = checkCurrencyEqual(moneyToSubtract); + var toSubtract = checkCurrencyEqual(moneyToSubtract); return minus(toSubtract.getAmount()); } @@ -1080,7 +1080,7 @@ public BigMoney minus(BigMoneyProvider moneyToSubtract) { * For example,'USD 25.95' minus '3.021' gives 'USD 22.929'. *

* This instance is immutable and unaffected by this method. - * + * * @param amountToSubtract the monetary value to subtract, not null * @return the new instance with the input amount subtracted, never null */ @@ -1089,7 +1089,7 @@ public BigMoney minus(BigDecimal amountToSubtract) { if (amountToSubtract.compareTo(BigDecimal.ZERO) == 0) { return this; } - BigDecimal newAmount = amount.subtract(amountToSubtract); + var newAmount = amount.subtract(amountToSubtract); return BigMoney.of(currency, newAmount); } @@ -1109,7 +1109,7 @@ public BigMoney minus(BigDecimal amountToSubtract) { * For example, the literal '1.45d' will be converted to '1.45'. *

* This instance is immutable and unaffected by this method. - * + * * @param amountToSubtract the monetary value to subtract, not null * @return the new instance with the input amount subtracted, never null */ @@ -1117,7 +1117,7 @@ public BigMoney minus(double amountToSubtract) { if (amountToSubtract == 0) { return this; } - BigDecimal newAmount = amount.subtract(BigDecimal.valueOf(amountToSubtract)); + var newAmount = amount.subtract(BigDecimal.valueOf(amountToSubtract)); return BigMoney.of(currency, newAmount); } @@ -1132,7 +1132,7 @@ public BigMoney minus(double amountToSubtract) { * For example, 'USD 23.45' minus '138' gives 'USD -114.55'. *

* This instance is immutable and unaffected by this method. - * + * * @param amountToSubtract the monetary value to subtract, not null * @return the new instance with the input amount subtracted, never null */ @@ -1140,7 +1140,7 @@ public BigMoney minusMajor(long amountToSubtract) { if (amountToSubtract == 0) { return this; } - BigDecimal newAmount = amount.subtract(BigDecimal.valueOf(amountToSubtract)); + var newAmount = amount.subtract(BigDecimal.valueOf(amountToSubtract)); return BigMoney.of(currency, newAmount); } @@ -1155,7 +1155,7 @@ public BigMoney minusMajor(long amountToSubtract) { * For example, USD 23.45 minus '138' gives 'USD 22.07'. *

* This instance is immutable and unaffected by this method. - * + * * @param amountToSubtract the monetary value to subtract, not null * @return the new instance with the input amount subtracted, never null */ @@ -1163,7 +1163,7 @@ public BigMoney minusMinor(long amountToSubtract) { if (amountToSubtract == 0) { return this; } - BigDecimal newAmount = amount.subtract(BigDecimal.valueOf(amountToSubtract, currency.getDecimalPlaces())); + var newAmount = amount.subtract(BigDecimal.valueOf(amountToSubtract, currency.getDecimalPlaces())); return BigMoney.of(currency, newAmount); } @@ -1176,13 +1176,13 @@ public BigMoney minusMinor(long amountToSubtract) { * For example,'USD 25.95' minus 'USD 3.029' gives 'USD 22.92 with most rounding modes. *

* This instance is immutable and unaffected by this method. - * + * * @param moneyToSubtract the monetary value to add, not null * @param roundingMode the rounding mode to use to adjust the scale, not null * @return the new instance with the input amount subtracted, never null */ public BigMoney minusRetainScale(BigMoneyProvider moneyToSubtract, RoundingMode roundingMode) { - BigMoney toSubtract = checkCurrencyEqual(moneyToSubtract); + var toSubtract = checkCurrencyEqual(moneyToSubtract); return minusRetainScale(toSubtract.getAmount(), roundingMode); } @@ -1194,7 +1194,7 @@ public BigMoney minusRetainScale(BigMoneyProvider moneyToSubtract, RoundingMode * For example,'USD 25.95' minus '3.029' gives 'USD 22.92' with most rounding modes. *

* This instance is immutable and unaffected by this method. - * + * * @param amountToSubtract the monetary value to add, not null * @param roundingMode the rounding mode to use to adjust the scale, not null * @return the new instance with the input amount subtracted, never null @@ -1204,7 +1204,7 @@ public BigMoney minusRetainScale(BigDecimal amountToSubtract, RoundingMode round if (amountToSubtract.compareTo(BigDecimal.ZERO) == 0) { return this; } - BigDecimal newAmount = amount.subtract(amountToSubtract); + var newAmount = amount.subtract(amountToSubtract); newAmount = newAmount.setScale(getScale(), roundingMode); return BigMoney.of(currency, newAmount); } @@ -1223,7 +1223,7 @@ public BigMoney minusRetainScale(BigDecimal amountToSubtract, RoundingMode round * For example, the literal '1.45d' will be converted to '1.45'. *

* This instance is immutable and unaffected by this method. - * + * * @param amountToSubtract the monetary value to add, not null * @param roundingMode the rounding mode to use to adjust the scale, not null * @return the new instance with the input amount subtracted, never null @@ -1232,7 +1232,7 @@ public BigMoney minusRetainScale(double amountToSubtract, RoundingMode roundingM if (amountToSubtract == 0) { return this; } - BigDecimal newAmount = amount.subtract(BigDecimal.valueOf(amountToSubtract)); + var newAmount = amount.subtract(BigDecimal.valueOf(amountToSubtract)); newAmount = newAmount.setScale(getScale(), roundingMode); return BigMoney.of(currency, newAmount); } @@ -1246,7 +1246,7 @@ public BigMoney minusRetainScale(double amountToSubtract, RoundingMode roundingM * For example, 'USD 1.13' multiplied by '2.5' gives 'USD 2.825'. *

* This instance is immutable and unaffected by this method. - * + * * @param valueToMultiplyBy the scalar value to multiply by, not null * @return the new multiplied instance, never null */ @@ -1255,7 +1255,7 @@ public BigMoney multipliedBy(BigDecimal valueToMultiplyBy) { if (valueToMultiplyBy.compareTo(BigDecimal.ONE) == 0) { return this; } - BigDecimal newAmount = amount.multiply(valueToMultiplyBy); + var newAmount = amount.multiply(valueToMultiplyBy); return BigMoney.of(currency, newAmount); } @@ -1273,7 +1273,7 @@ public BigMoney multipliedBy(BigDecimal valueToMultiplyBy) { * For example, the literal '1.45d' will be converted to '1.45'. *

* This instance is immutable and unaffected by this method. - * + * * @param valueToMultiplyBy the scalar value to multiply by, not null * @return the new multiplied instance, never null */ @@ -1281,7 +1281,7 @@ public BigMoney multipliedBy(double valueToMultiplyBy) { if (valueToMultiplyBy == 1) { return this; } - BigDecimal newAmount = amount.multiply(BigDecimal.valueOf(valueToMultiplyBy)); + var newAmount = amount.multiply(BigDecimal.valueOf(valueToMultiplyBy)); return BigMoney.of(currency, newAmount); } @@ -1293,7 +1293,7 @@ public BigMoney multipliedBy(double valueToMultiplyBy) { * For example, 'USD 1.13' multiplied by '2' gives 'USD 2.26'. *

* This instance is immutable and unaffected by this method. - * + * * @param valueToMultiplyBy the scalar value to multiply by, not null * @return the new multiplied instance, never null */ @@ -1301,7 +1301,7 @@ public BigMoney multipliedBy(long valueToMultiplyBy) { if (valueToMultiplyBy == 1) { return this; } - BigDecimal newAmount = amount.multiply(BigDecimal.valueOf(valueToMultiplyBy)); + var newAmount = amount.multiply(BigDecimal.valueOf(valueToMultiplyBy)); return BigMoney.of(currency, newAmount); } @@ -1315,7 +1315,7 @@ public BigMoney multipliedBy(long valueToMultiplyBy) { * For example, 'USD 1.13' multiplied by '2.5' and rounding down gives 'USD 2.82'. *

* This instance is immutable and unaffected by this method. - * + * * @param valueToMultiplyBy the scalar value to multiply by, not null * @param roundingMode the rounding mode to use to bring the decimal places back in line, not null * @return the new multiplied instance, never null @@ -1327,7 +1327,7 @@ public BigMoney multiplyRetainScale(BigDecimal valueToMultiplyBy, RoundingMode r if (valueToMultiplyBy.compareTo(BigDecimal.ONE) == 0) { return this; } - BigDecimal newAmount = amount.multiply(valueToMultiplyBy); + var newAmount = amount.multiply(valueToMultiplyBy); newAmount = newAmount.setScale(getScale(), roundingMode); return BigMoney.of(currency, newAmount); } @@ -1347,7 +1347,7 @@ public BigMoney multiplyRetainScale(BigDecimal valueToMultiplyBy, RoundingMode r * For example, the literal '1.45d' will be converted to '1.45'. *

* This instance is immutable and unaffected by this method. - * + * * @param valueToMultiplyBy the scalar value to multiply by, not null * @param roundingMode the rounding mode to use to bring the decimal places back in line, not null * @return the new multiplied instance, never null @@ -1367,7 +1367,7 @@ public BigMoney multiplyRetainScale(double valueToMultiplyBy, RoundingMode round * (amount rounded down from 0.452). *

* This instance is immutable and unaffected by this method. - * + * * @param valueToDivideBy the scalar value to divide by, not null * @param roundingMode the rounding mode to use, not null * @return the new divided instance, never null @@ -1380,7 +1380,7 @@ public BigMoney dividedBy(BigDecimal valueToDivideBy, RoundingMode roundingMode) if (valueToDivideBy.compareTo(BigDecimal.ONE) == 0) { return this; } - BigDecimal newAmount = amount.divide(valueToDivideBy, roundingMode); + var newAmount = amount.divide(valueToDivideBy, roundingMode); return BigMoney.of(currency, newAmount); } @@ -1399,7 +1399,7 @@ public BigMoney dividedBy(BigDecimal valueToDivideBy, RoundingMode roundingMode) * For example, the literal '1.45d' will be converted to '1.45'. *

* This instance is immutable and unaffected by this method. - * + * * @param valueToDivideBy the scalar value to divide by, not null * @param roundingMode the rounding mode to use, not null * @return the new divided instance, never null @@ -1411,7 +1411,7 @@ public BigMoney dividedBy(double valueToDivideBy, RoundingMode roundingMode) { if (valueToDivideBy == 1) { return this; } - BigDecimal newAmount = amount.divide(BigDecimal.valueOf(valueToDivideBy), roundingMode); + var newAmount = amount.divide(BigDecimal.valueOf(valueToDivideBy), roundingMode); return BigMoney.of(currency, newAmount); } @@ -1424,7 +1424,7 @@ public BigMoney dividedBy(double valueToDivideBy, RoundingMode roundingMode) { * (amount rounded down from 0.565). *

* This instance is immutable and unaffected by this method. - * + * * @param valueToDivideBy the scalar value to divide by, not null * @param roundingMode the rounding mode to use, not null * @return the new divided instance, never null @@ -1434,7 +1434,7 @@ public BigMoney dividedBy(long valueToDivideBy, RoundingMode roundingMode) { if (valueToDivideBy == 1) { return this; } - BigDecimal newAmount = amount.divide(BigDecimal.valueOf(valueToDivideBy), roundingMode); + var newAmount = amount.divide(BigDecimal.valueOf(valueToDivideBy), roundingMode); return BigMoney.of(currency, newAmount); } @@ -1443,7 +1443,7 @@ public BigMoney dividedBy(long valueToDivideBy, RoundingMode roundingMode) { * Returns a copy of this monetary value with the amount negated. *

* This instance is immutable and unaffected by this method. - * + * * @return the new instance with the amount negated, never null */ public BigMoney negated() { @@ -1457,7 +1457,7 @@ public BigMoney negated() { * Returns a copy of this monetary value with a positive amount. *

* This instance is immutable and unaffected by this method. - * + * * @return the new instance with the amount converted to be positive, never null */ public BigMoney abs() { @@ -1480,7 +1480,7 @@ public BigMoney abs() { *

  • Rounding 'EUR 45.23' to a scale of 3 has no effect (the scale is not increased). * * This instance is immutable and unaffected by this method. - * + * * @param scale the new scale * @param roundingMode the rounding mode to use, not null * @return the new instance with the amount converted to be positive, never null @@ -1491,8 +1491,8 @@ public BigMoney rounded(int scale, RoundingMode roundingMode) { if (scale >= getScale()) { return this; } - int currentScale = amount.scale(); - BigDecimal newAmount = amount.setScale(scale, roundingMode).setScale(currentScale); + var currentScale = amount.scale(); + var newAmount = amount.setScale(scale, roundingMode).setScale(currentScale); return BigMoney.of(currency, newAmount); } @@ -1506,7 +1506,7 @@ public BigMoney rounded(int scale, RoundingMode roundingMode) { * adjusted to the scale of the new currency using {@link #withCurrencyScale()}. *

    * This instance is immutable and unaffected by this method. - * + * * @param currency the new currency, not null * @param conversionMultipler the conversion factor between the currencies, not null * @return the new multiplied instance, never null @@ -1525,7 +1525,7 @@ public BigMoney convertedTo(CurrencyUnit currency, BigDecimal conversionMultiple if (conversionMultipler.compareTo(BigDecimal.ZERO) < 0) { throw new IllegalArgumentException("Cannot convert using a negative conversion multiplier"); } - BigDecimal newAmount = amount.multiply(conversionMultipler); + var newAmount = amount.multiply(conversionMultipler); return BigMoney.of(currency, newAmount); } @@ -1538,7 +1538,7 @@ public BigMoney convertedTo(CurrencyUnit currency, BigDecimal conversionMultiple * be in a different currency. *

    * This instance is immutable and unaffected by this method. - * + * * @param currency the new currency, not null * @param conversionMultipler the conversion factor between the currencies, not null * @param roundingMode the rounding mode to use to bring the decimal places back in line, not null @@ -1555,7 +1555,7 @@ public BigMoney convertRetainScale(CurrencyUnit currency, BigDecimal conversionM /** * Implements the {@code BigMoneyProvider} interface, trivially * returning {@code this}. - * + * * @return the money instance, never null */ @Override @@ -1566,7 +1566,7 @@ public BigMoney toBigMoney() { /** * Converts this money to an instance of {@code Money} without rounding. * If the scale of this money exceeds the currency scale an exception will be thrown. - * + * * @return the money instance, never null * @throws ArithmeticException if the rounding fails */ @@ -1576,7 +1576,7 @@ public Money toMoney() { /** * Converts this money to an instance of {@code Money}. - * + * * @param roundingMode the rounding mode to use, not null * @return the money instance, never null * @throws ArithmeticException if the rounding fails @@ -1588,7 +1588,7 @@ public Money toMoney(RoundingMode roundingMode) { //----------------------------------------------------------------------- /** * Checks if this instance and the specified instance have the same currency. - * + * * @param money the money to check, not null * @return true if they have the same currency */ @@ -1600,15 +1600,15 @@ public boolean isSameCurrency(BigMoneyProvider money) { /** * Compares this monetary value to another. * The compared values must be in the same currency. - * + * * @param other the other monetary value, not null * @return -1 if this is less than , 0 if equal, 1 if greater than * @throws CurrencyMismatchException if the currencies differ */ @Override public int compareTo(BigMoneyProvider other) { - BigMoney otherMoney = of(other); - if (currency.equals(otherMoney.currency) == false) { + var otherMoney = of(other); + if (!currency.equals(otherMoney.currency)) { throw new CurrencyMismatchException(getCurrencyUnit(), otherMoney.getCurrencyUnit()); } return amount.compareTo(otherMoney.amount); @@ -1621,7 +1621,7 @@ public int compareTo(BigMoneyProvider other) { * Thus, 'USD 30.00' and 'USD 30' are equal. *

    * The compared values must be in the same currency. - * + * * @param other the other monetary value, not null * @return true if this is equal to the specified monetary value * @throws CurrencyMismatchException if the currencies differ @@ -1634,7 +1634,7 @@ public boolean isEqual(BigMoneyProvider other) { /** * Checks if this monetary value is greater than another. * The compared values must be in the same currency. - * + * * @param other the other monetary value, not null * @return true if this is greater than the specified monetary value * @throws CurrencyMismatchException if the currencies differ @@ -1646,7 +1646,7 @@ public boolean isGreaterThan(BigMoneyProvider other) { /** * Checks if this monetary value is greater than or equal to another. * The compared values must be in the same currency. - * + * * @param other the other monetary value, not null * @return true if this is greater than or equal to the specified monetary value * @throws CurrencyMismatchException if the currencies differ @@ -1658,7 +1658,7 @@ public boolean isGreaterThanOrEqual(BigMoneyProvider other) { /** * Checks if this monetary value is less than another. * The compared values must be in the same currency. - * + * * @param other the other monetary value, not null * @return true if this is less than the specified monetary value * @throws CurrencyMismatchException if the currencies differ @@ -1670,7 +1670,7 @@ public boolean isLessThan(BigMoneyProvider other) { /** * Checks if this monetary value is less or equal to than another. * The compared values must be in the same currency. - * + * * @param other the other monetary value, not null * @return true if this is less than or equal to the specified monetary value * @throws CurrencyMismatchException if the currencies differ @@ -1687,7 +1687,7 @@ public boolean isLessThanOrEqual(BigMoneyProvider other) { * Thus, 'USD 30.00' and 'USD 30' are not equal. *

    * The compared values must be in the same currency. - * + * * @param other the other object, null returns false * @return true if this instance equals the other instance * @see #isEqual @@ -1697,8 +1697,7 @@ public boolean equals(Object other) { if (this == other) { return true; } - if (other instanceof BigMoney) { - BigMoney otherMoney = (BigMoney) other; + if (other instanceof BigMoney otherMoney) { return currency.equals(otherMoney.getCurrencyUnit()) && amount.equals(otherMoney.amount); } @@ -1707,7 +1706,7 @@ public boolean equals(Object other) { /** * Returns a hash code for this monetary value. - * + * * @return a suitable hash code */ @Override @@ -1721,7 +1720,7 @@ public int hashCode() { *

    * The format is the 3 letter ISO currency code, followed by a space, * followed by the amount as per {@link BigDecimal#toPlainString()}. - * + * * @return the string representation of this monetary value, never null */ @Override diff --git a/src/main/java/org/joda/money/BigMoneyProvider.java b/src/main/java/org/joda/money/BigMoneyProvider.java index 9cb2838..6085262 100644 --- a/src/main/java/org/joda/money/BigMoneyProvider.java +++ b/src/main/java/org/joda/money/BigMoneyProvider.java @@ -41,10 +41,10 @@ public interface BigMoneyProvider { * preference to calling this method directly. It is also recommended that the * converted {@code BigMoney} is cached in a local variable instead of * performing the conversion multiple times. - * + * * @return the converted money instance, never null * @throws RuntimeException if conversion is not possible */ - BigMoney toBigMoney(); + public abstract BigMoney toBigMoney(); } diff --git a/src/main/java/org/joda/money/CurrencyMismatchException.java b/src/main/java/org/joda/money/CurrencyMismatchException.java index 01c69be..d766502 100644 --- a/src/main/java/org/joda/money/CurrencyMismatchException.java +++ b/src/main/java/org/joda/money/CurrencyMismatchException.java @@ -35,7 +35,7 @@ public class CurrencyMismatchException extends IllegalArgumentException { /** * Constructor. - * + * * @param firstCurrency the first currency, may be null * @param secondCurrency the second currency, not null */ @@ -50,7 +50,7 @@ public CurrencyMismatchException(CurrencyUnit firstCurrency, CurrencyUnit second //----------------------------------------------------------------------- /** * Gets the first currency at fault. - * + * * @return the currency at fault, may be null */ public CurrencyUnit getFirstCurrency() { @@ -59,7 +59,7 @@ public CurrencyUnit getFirstCurrency() { /** * Gets the second currency at fault. - * + * * @return the currency at fault, may be null */ public CurrencyUnit getSecondCurrency() { diff --git a/src/main/java/org/joda/money/CurrencyUnit.java b/src/main/java/org/joda/money/CurrencyUnit.java index a9cc6a2..d2b720b 100644 --- a/src/main/java/org/joda/money/CurrencyUnit.java +++ b/src/main/java/org/joda/money/CurrencyUnit.java @@ -60,20 +60,20 @@ public final class CurrencyUnit implements Comparable, Serializabl /** * Map of registered currencies by text code. */ - private static final ConcurrentMap currenciesByCode = new ConcurrentSkipListMap(); + private static final ConcurrentMap currenciesByCode = new ConcurrentSkipListMap<>(); /** * Map of registered currencies by numeric code. */ - private static final ConcurrentMap currenciesByNumericCode = new ConcurrentHashMap(); + private static final ConcurrentMap currenciesByNumericCode = new ConcurrentHashMap<>(); /** * Map of registered currencies by country. */ - private static final ConcurrentMap currenciesByCountry = new ConcurrentSkipListMap(); + private static final ConcurrentMap currenciesByCountry = new ConcurrentSkipListMap<>(); static { // load one data provider by system property try { try { - String clsName = System.getProperty( + var clsName = System.getProperty( "org.joda.money.CurrencyUnitDataProvider", "org.joda.money.DefaultCurrencyUnitDataProvider"); Class cls = @@ -207,7 +207,7 @@ public static synchronized CurrencyUnit registerCurrency( if (currencyCode.length() != 3) { throw new IllegalArgumentException("Invalid string code, must be length 3"); } - if (CODE.matcher(currencyCode).matches() == false) { + if (!CODE.matcher(currencyCode).matches()) { throw new IllegalArgumentException("Invalid string code, must be ASCII upper-case letters"); } if (numericCurrencyCode < -1 || numericCurrencyCode > 999) { @@ -218,7 +218,7 @@ public static synchronized CurrencyUnit registerCurrency( } MoneyUtils.checkNotNull(countryCodes, "Country codes must not be null"); - CurrencyUnit currency = new CurrencyUnit(currencyCode, (short) numericCurrencyCode, (short) decimalPlaces); + var currency = new CurrencyUnit(currencyCode, (short) numericCurrencyCode, (short) decimalPlaces); if (force) { currenciesByCode.remove(currencyCode); currenciesByNumericCode.remove(numericCurrencyCode); @@ -354,7 +354,7 @@ public static CurrencyUnit of(Currency currency) { @FromString public static CurrencyUnit of(String currencyCode) { MoneyUtils.checkNotNull(currencyCode, "Currency code must not be null"); - CurrencyUnit currency = currenciesByCode.get(currencyCode); + var currency = currenciesByCode.get(currencyCode); if (currency == null) { throw new IllegalCurrencyException("Unknown currency '" + currencyCode + '\''); } @@ -373,21 +373,17 @@ public static CurrencyUnit of(String currencyCode) { */ public static CurrencyUnit ofNumericCode(String numericCurrencyCode) { MoneyUtils.checkNotNull(numericCurrencyCode, "Currency code must not be null"); - switch (numericCurrencyCode.length()) { - case 1: - return ofNumericCode(numericCurrencyCode.charAt(0) - '0'); - case 2: - return ofNumericCode( - (numericCurrencyCode.charAt(0) - '0') * 10 + - numericCurrencyCode.charAt(1) - '0'); - case 3: - return ofNumericCode( - (numericCurrencyCode.charAt(0) - '0') * 100 + - (numericCurrencyCode.charAt(1) - '0') * 10 + - numericCurrencyCode.charAt(2) - '0'); - default: - throw new IllegalCurrencyException("Unknown currency '" + numericCurrencyCode + '\''); - } + return switch (numericCurrencyCode.length()) { + case 1 -> ofNumericCode(numericCurrencyCode.charAt(0) - '0'); + case 2 -> ofNumericCode( + (numericCurrencyCode.charAt(0) - '0') * 10 + + numericCurrencyCode.charAt(1) - '0'); + case 3 -> ofNumericCode( + (numericCurrencyCode.charAt(0) - '0') * 100 + + (numericCurrencyCode.charAt(1) - '0') * 10 + + numericCurrencyCode.charAt(2) - '0'); + default -> throw new IllegalCurrencyException("Unknown currency '" + numericCurrencyCode + '\''); + }; } /** @@ -400,7 +396,7 @@ public static CurrencyUnit ofNumericCode(String numericCurrencyCode) { * @throws IllegalCurrencyException if the currency is unknown */ public static CurrencyUnit ofNumericCode(int numericCurrencyCode) { - CurrencyUnit currency = currenciesByNumericCode.get(numericCurrencyCode); + var currency = currenciesByNumericCode.get(numericCurrencyCode); if (currency == null) { throw new IllegalCurrencyException("Unknown currency '" + numericCurrencyCode + '\''); } @@ -418,7 +414,7 @@ public static CurrencyUnit ofNumericCode(int numericCurrencyCode) { */ public static CurrencyUnit of(Locale locale) { MoneyUtils.checkNotNull(locale, "Locale must not be null"); - CurrencyUnit currency = currenciesByCountry.get(locale.getCountry()); + var currency = currenciesByCountry.get(locale.getCountry()); if (currency == null) { throw new IllegalCurrencyException("No currency found for locale '" + locale + '\''); } @@ -437,7 +433,7 @@ public static CurrencyUnit of(Locale locale) { */ public static CurrencyUnit ofCountry(String countryCode) { MoneyUtils.checkNotNull(countryCode, "Country code must not be null"); - CurrencyUnit currency = currenciesByCountry.get(countryCode); + var currency = currenciesByCountry.get(countryCode); if (currency == null) { throw new IllegalCurrencyException("No currency found for country '" + countryCode + '\''); } @@ -447,7 +443,7 @@ public static CurrencyUnit ofCountry(String countryCode) { //----------------------------------------------------------------------- /** * Constructor, creating a new currency instance. - * + * * @param code the three-letter currency code, not null * @param numericCode the numeric currency code, from 0 to 999, -1 if none * @param decimalPlaces the decimal places, not null @@ -461,7 +457,7 @@ public static CurrencyUnit ofCountry(String countryCode) { /** * Block malicious data streams. - * + * * @param ois the input stream, not null * @throws InvalidObjectException if an error occurs */ @@ -471,7 +467,7 @@ private void readObject(ObjectInputStream ois) throws InvalidObjectException { /** * Uses a serialization delegate. - * + * * @return the replacing object, never null */ private Object writeReplace() { @@ -483,7 +479,7 @@ private Object writeReplace() { * Gets the ISO-4217 three-letter currency code. *

    * Each currency is uniquely identified by a three-letter upper-case code, based on ISO-4217. - * + * * @return the three-letter upper-case currency code, never null */ public String getCode() { @@ -494,7 +490,7 @@ public String getCode() { * Gets the ISO-4217 numeric currency code. *

    * The numeric code is an alternative to the standard string-based code. - * + * * @return the numeric currency code, -1 if no numeric code */ public int getNumericCode() { @@ -506,14 +502,14 @@ public int getNumericCode() { *

    * This formats the numeric code as a three digit string prefixed by zeroes if necessary. * If there is no valid code, then an empty string is returned. - * + * * @return the three digit numeric currency code, empty is no code, never null */ public String getNumeric3Code() { if (numericCode < 0) { return ""; } - String str = Integer.toString(numericCode); + var str = Integer.toString(numericCode); if (str.length() == 1) { return "00" + str; } @@ -529,11 +525,11 @@ public String getNumeric3Code() { * A currency is typically valid in one or more countries. * The codes are typically defined by ISO-3166. * An empty set indicates that no the currency is not associated with a country code. - * + * * @return the country codes, may be empty, not null */ public Set getCountryCodes() { - Set countryCodes = new HashSet(); + Set countryCodes = new HashSet<>(); for (Entry entry : currenciesByCountry.entrySet()) { if (this.equals(entry.getValue())) { countryCodes.add(entry.getKey()); @@ -549,7 +545,7 @@ public Set getCountryCodes() { * Different currencies have different numbers of decimal places by default. * For example, 'GBP' has 2 decimal places, but 'JPY' has zero. * Pseudo-currencies will return zero. - * + * * @return the decimal places, from 0 to 9 (normally 0, 2 or 3) */ public int getDecimalPlaces() { @@ -558,7 +554,7 @@ public int getDecimalPlaces() { /** * Checks if this is a pseudo-currency. - * + * * @return true if this is a pseudo-currency */ public boolean isPseudoCurrency() { @@ -573,7 +569,7 @@ public boolean isPseudoCurrency() { * is returned. *

    * This method matches the API of {@link Currency}. - * + * * @return the JDK currency instance, never null */ public String getSymbol() { @@ -595,7 +591,7 @@ public String getSymbol() { * is returned. *

    * This method matches the API of {@link Currency}. - * + * * @param locale the locale to get the symbol for, not null * @return the JDK currency instance, never null */ @@ -617,7 +613,7 @@ public String getSymbol(Locale locale) { * Gets the JDK currency instance equivalent to this currency. *

    * This attempts to convert a {@code CurrencyUnit} to a JDK {@code Currency}. - * + * * @return the JDK currency instance, never null * @throws IllegalArgumentException if no matching currency exists in the JDK */ @@ -628,7 +624,7 @@ public Currency toCurrency() { //----------------------------------------------------------------------- /** * Compares this currency to another by alphabetical comparison of the code. - * + * * @param other the other currency, not null * @return negative if earlier alphabetically, 0 if equal, positive if greater alphabetically */ @@ -641,7 +637,7 @@ public int compareTo(CurrencyUnit other) { * Checks if this currency equals another currency. *

    * The comparison checks the 3 letter currency code. - * + * * @param obj the other currency, null returns false * @return true if equal */ @@ -658,7 +654,7 @@ public boolean equals(Object obj) { /** * Returns a suitable hash code for the currency. - * + * * @return the hash code */ @Override @@ -669,7 +665,7 @@ public int hashCode() { //----------------------------------------------------------------------- /** * Gets the currency code as a string. - * + * * @return the currency code, never null */ @Override diff --git a/src/main/java/org/joda/money/CurrencyUnitDataProvider.java b/src/main/java/org/joda/money/CurrencyUnitDataProvider.java index 8e5eda0..fa940ba 100644 --- a/src/main/java/org/joda/money/CurrencyUnitDataProvider.java +++ b/src/main/java/org/joda/money/CurrencyUnitDataProvider.java @@ -22,7 +22,7 @@ public abstract class CurrencyUnitDataProvider { /** * Registers all the currencies known by this provider. - * + * * @throws Exception if an error occurs */ protected abstract void registerCurrencies() throws Exception; diff --git a/src/main/java/org/joda/money/DefaultCurrencyUnitDataProvider.java b/src/main/java/org/joda/money/DefaultCurrencyUnitDataProvider.java index 1d74bb0..2142afa 100644 --- a/src/main/java/org/joda/money/DefaultCurrencyUnitDataProvider.java +++ b/src/main/java/org/joda/money/DefaultCurrencyUnitDataProvider.java @@ -17,13 +17,9 @@ import java.io.BufferedReader; import java.io.FileNotFoundException; -import java.io.InputStream; import java.io.InputStreamReader; -import java.net.URL; import java.util.ArrayList; -import java.util.Enumeration; import java.util.List; -import java.util.regex.Matcher; import java.util.regex.Pattern; /** @@ -48,7 +44,7 @@ class DefaultCurrencyUnitDataProvider extends CurrencyUnitDataProvider { /** * Registers all the currencies known by this provider. - * + * * @throws Exception if an error occurs */ @Override @@ -61,11 +57,11 @@ protected void registerCurrencies() throws Exception { // loads a file private List loadFromFile(String fileName) throws Exception { - try (InputStream in = getClass().getResourceAsStream(fileName)) { + try (var in = getClass().getResourceAsStream(fileName)) { if (in == null) { throw new FileNotFoundException("Data file " + fileName + " not found"); } - try (BufferedReader reader = new BufferedReader(new InputStreamReader(in, "UTF-8"))) { + try (var reader = new BufferedReader(new InputStreamReader(in, "UTF-8"))) { String line; List content = new ArrayList<>(); while ((line = reader.readLine()) != null) { @@ -79,11 +75,11 @@ private List loadFromFile(String fileName) throws Exception { // loads a file private List loadFromFiles(String fileName) throws Exception { List content = new ArrayList<>(); - Enumeration en = getClass().getClassLoader().getResources(fileName); + var en = getClass().getClassLoader().getResources(fileName); while (en.hasMoreElements()) { - URL url = (URL) en.nextElement(); - try (InputStream in = url.openStream()) { - try (BufferedReader reader = new BufferedReader(new InputStreamReader(in, "UTF-8"))) { + var url = en.nextElement(); + try (var in = url.openStream()) { + try (var reader = new BufferedReader(new InputStreamReader(in, "UTF-8"))) { String line; while ((line = reader.readLine()) != null) { content.add(line); @@ -97,11 +93,11 @@ private List loadFromFiles(String fileName) throws Exception { // parse the currencies private void parseCurrencies(List content) throws Exception { for (String line : content) { - Matcher matcher = CURRENCY_REGEX_LINE.matcher(line); + var matcher = CURRENCY_REGEX_LINE.matcher(line); if (matcher.matches()) { - String currencyCode = matcher.group(1); - int numericCode = Integer.parseInt(matcher.group(2)); - int digits = Integer.parseInt(matcher.group(3)); + var currencyCode = matcher.group(1); + var numericCode = Integer.parseInt(matcher.group(2)); + var digits = Integer.parseInt(matcher.group(3)); registerCurrency(currencyCode, numericCode, digits); } } @@ -110,10 +106,10 @@ private void parseCurrencies(List content) throws Exception { // parse the countries private void parseCountries(List content) throws Exception { for (String line : content) { - Matcher matcher = COUNTRY_REGEX_LINE.matcher(line); + var matcher = COUNTRY_REGEX_LINE.matcher(line); if (matcher.matches()) { - String countryCode = matcher.group(1); - String currencyCode = matcher.group(2); + var countryCode = matcher.group(1); + var currencyCode = matcher.group(2); registerCountry(countryCode, currencyCode); } } diff --git a/src/main/java/org/joda/money/IllegalCurrencyException.java b/src/main/java/org/joda/money/IllegalCurrencyException.java index 8d46698..3604bc2 100644 --- a/src/main/java/org/joda/money/IllegalCurrencyException.java +++ b/src/main/java/org/joda/money/IllegalCurrencyException.java @@ -30,7 +30,7 @@ public class IllegalCurrencyException extends IllegalArgumentException { /** * Constructor. - * + * * @param message the message, may be null */ public IllegalCurrencyException(String message) { diff --git a/src/main/java/org/joda/money/Money.java b/src/main/java/org/joda/money/Money.java index 3e554cf..e46bff2 100644 --- a/src/main/java/org/joda/money/Money.java +++ b/src/main/java/org/joda/money/Money.java @@ -21,7 +21,6 @@ import java.math.BigDecimal; import java.math.RoundingMode; import java.util.Arrays; -import java.util.Iterator; import org.joda.convert.FromString; import org.joda.convert.ToString; @@ -94,7 +93,7 @@ public static Money of(CurrencyUnit currency, BigDecimal amount, RoundingMode ro MoneyUtils.checkNotNull(currency, "CurrencyUnit must not be null"); MoneyUtils.checkNotNull(amount, "Amount must not be null"); MoneyUtils.checkNotNull(roundingMode, "RoundingMode must not be null"); - BigDecimal scaledAmount = amount.setScale(currency.getDecimalPlaces(), roundingMode); + var scaledAmount = amount.setScale(currency.getDecimalPlaces(), roundingMode); return new Money(BigMoney.of(currency, scaledAmount)); } @@ -191,7 +190,7 @@ public static Money ofMinor(CurrencyUnit currency, long amountMinor) { */ public static Money zero(CurrencyUnit currency) { MoneyUtils.checkNotNull(currency, "Currency must not be null"); - BigDecimal bd = BigDecimal.valueOf(0, currency.getDecimalPlaces()); + var bd = BigDecimal.valueOf(0, currency.getDecimalPlaces()); return new Money(BigMoney.of(currency, bd)); } @@ -237,7 +236,7 @@ public static Money of(BigMoneyProvider moneyProvider, RoundingMode roundingMode * The array must contain at least one monetary value. * Subsequent amounts are added as though using {@link #plus(Money)}. * All amounts must be in the same currency. - * + * * @param monies the monetary values to total, not empty, no null elements, not null * @return the total, never null * @throws IllegalArgumentException if the array is empty @@ -248,9 +247,9 @@ public static Money total(Money... monies) { if (monies.length == 0) { throw new IllegalArgumentException("Money array must not be empty"); } - Money total = monies[0]; + var total = monies[0]; MoneyUtils.checkNotNull(total, "Money arary must not contain null entries"); - for (int i = 1; i < monies.length; i++) { + for (var i = 1; i < monies.length; i++) { total = total.plus(monies[i]); } return total; @@ -262,7 +261,7 @@ public static Money total(Money... monies) { * The iterable must provide at least one monetary value. * Subsequent amounts are added as though using {@link #plus(Money)}. * All amounts must be in the same currency. - * + * * @param monies the monetary values to total, not empty, no null elements, not null * @return the total, never null * @throws IllegalArgumentException if the iterable is empty @@ -270,11 +269,11 @@ public static Money total(Money... monies) { */ public static Money total(Iterable monies) { MoneyUtils.checkNotNull(monies, "Money iterator must not be null"); - Iterator it = monies.iterator(); - if (it.hasNext() == false) { + var it = monies.iterator(); + if (!it.hasNext()) { throw new IllegalArgumentException("Money iterator must not be empty"); } - Money total = it.next(); + var total = it.next(); MoneyUtils.checkNotNull(total, "Money iterator must not contain null entries"); while (it.hasNext()) { total = total.plus(it.next()); @@ -289,7 +288,7 @@ public static Money total(Iterable monies) { * The amounts are added as though using {@link #plus(Money)} starting * from zero in the specified currency. * All amounts must be in the same currency. - * + * * @param currency the currency to total in, not null * @param monies the monetary values to total, no null elements, not null * @return the total, never null @@ -306,7 +305,7 @@ public static Money total(CurrencyUnit currency, Money... monies) { * The amounts are added as though using {@link #plus(Money)} starting * from zero in the specified currency. * All amounts must be in the same currency. - * + * * @param currency the currency to total in, not null * @param monies the monetary values to total, no null elements, not null * @return the total, never null @@ -351,7 +350,7 @@ private Money() { /** * Constructor, creating a new monetary instance. - * + * * @param money the underlying money, not null */ Money(BigMoney money) { @@ -362,7 +361,7 @@ private Money() { /** * Block malicious data streams. - * + * * @param ois the input stream, not null * @throws InvalidObjectException if an error occurs */ @@ -372,7 +371,7 @@ private void readObject(ObjectInputStream ois) throws InvalidObjectException { /** * Uses a serialization delegate. - * + * * @return the replacing object, never null */ private Object writeReplace() { @@ -384,7 +383,7 @@ private Object writeReplace() { * Returns a new {@code Money}, returning {@code this} if possible. *

    * This instance is immutable and unaffected by this method. - * + * * @param newInstance the new money to use, not null * @return the new instance, never null */ @@ -398,7 +397,7 @@ private Money with(BigMoney newInstance) { //----------------------------------------------------------------------- /** * Gets the currency. - * + * * @return the currency, never null */ public CurrencyUnit getCurrencyUnit() { @@ -414,7 +413,7 @@ public CurrencyUnit getCurrencyUnit() { * that rounding would be required, then an exception is thrown. *

    * This instance is immutable and unaffected by this method. - * + * * @param currency the currency to use, not null * @return the new instance with the input currency set, never null * @throws ArithmeticException if the scale of the new currency is less than @@ -432,7 +431,7 @@ public Money withCurrencyUnit(CurrencyUnit currency) { * currencies, then the amount may be rounded. *

    * This instance is immutable and unaffected by this method. - * + * * @param currency the currency to use, not null * @param roundingMode the rounding mode to use to bring the decimal places back in line, not null * @return the new instance with the input currency set, never null @@ -452,7 +451,7 @@ public Money withCurrencyUnit(CurrencyUnit currency, RoundingMode roundingMode) * such as 'USD 43.25'. *

    * For {@code Money}, the scale is fixed and always matches that of the currency. - * + * * @return the scale in use, typically 2 but could be 0, 1 and 3 */ public int getScale() { @@ -465,7 +464,7 @@ public int getScale() { *

    * This returns the value of the money as a {@code BigDecimal}. * The scale will be the scale of this money. - * + * * @return the amount, never null */ public BigDecimal getAmount() { @@ -482,7 +481,7 @@ public BigDecimal getAmount() { * This is returned as a {@code BigDecimal} rather than a {@code BigInteger}. * This is to allow further calculations to be performed on the result. * Should you need a {@code BigInteger}, simply call {@link BigDecimal#toBigInteger()}. - * + * * @return the major units part of the amount, never null */ public BigDecimal getAmountMajor() { @@ -495,7 +494,7 @@ public BigDecimal getAmountMajor() { * This returns the monetary amount in terms of the major units of the currency, * truncating the amount if necessary. * For example, 'EUR 2.35' will return 2, and 'BHD -1.345' will return -1. - * + * * @return the major units part of the amount * @throws ArithmeticException if the amount is too large for a {@code long} */ @@ -509,7 +508,7 @@ public long getAmountMajorLong() { * This returns the monetary amount in terms of the major units of the currency, * truncating the amount if necessary. * For example, 'EUR 2.35' will return 2, and 'BHD -1.345' will return -1. - * + * * @return the major units part of the amount * @throws ArithmeticException if the amount is too large for an {@code int} */ @@ -527,7 +526,7 @@ public int getAmountMajorInt() { * This is returned as a {@code BigDecimal} rather than a {@code BigInteger}. * This is to allow further calculations to be performed on the result. * Should you need a {@code BigInteger}, simply call {@link BigDecimal#toBigInteger()}. - * + * * @return the minor units part of the amount, never null */ public BigDecimal getAmountMinor() { @@ -540,7 +539,7 @@ public BigDecimal getAmountMinor() { * This returns the monetary amount in terms of the minor units of the currency, * truncating the amount if necessary. * For example, 'EUR 2.35' will return 235, and 'BHD -1.345' will return -1345. - * + * * @return the minor units part of the amount * @throws ArithmeticException if the amount is too large for a {@code long} */ @@ -554,7 +553,7 @@ public long getAmountMinorLong() { * This returns the monetary amount in terms of the minor units of the currency, * truncating the amount if necessary. * For example, 'EUR 2.35' will return 235, and 'BHD -1.345' will return -1345. - * + * * @return the minor units part of the amount * @throws ArithmeticException if the amount is too large for an {@code int} */ @@ -571,7 +570,7 @@ public int getAmountMinorInt() { * For example, EUR has a scale of 2, so the minor part is always between 0 and 99 * for positive amounts, and 0 and -99 for negative amounts. * Thus 'EUR 2.35' will return 35, and 'EUR -1.34' will return -34. - * + * * @return the minor part of the amount, negative if the amount is negative */ public int getMinorPart() { @@ -581,7 +580,7 @@ public int getMinorPart() { //----------------------------------------------------------------------- /** * Checks if the amount is zero. - * + * * @return true if the amount is zero */ public boolean isZero() { @@ -590,7 +589,7 @@ public boolean isZero() { /** * Checks if the amount is greater than zero. - * + * * @return true if the amount is greater than zero */ public boolean isPositive() { @@ -599,7 +598,7 @@ public boolean isPositive() { /** * Checks if the amount is zero or greater. - * + * * @return true if the amount is zero or greater */ public boolean isPositiveOrZero() { @@ -608,7 +607,7 @@ public boolean isPositiveOrZero() { /** * Checks if the amount is less than zero. - * + * * @return true if the amount is less than zero */ public boolean isNegative() { @@ -617,7 +616,7 @@ public boolean isNegative() { /** * Checks if the amount is zero or less. - * + * * @return true if the amount is zero or less */ public boolean isNegativeOrZero() { @@ -633,7 +632,7 @@ public boolean isNegativeOrZero() { * scale compatible with the currency. *

    * This instance is immutable and unaffected by this method. - * + * * @param amount the monetary amount to set in the returned instance, not null * @return the new instance with the input amount set, never null * @throws ArithmeticException if the scale of the amount is too large @@ -650,7 +649,7 @@ public Money withAmount(BigDecimal amount) { * it will be rounded using the specified mode. *

    * This instance is immutable and unaffected by this method. - * + * * @param amount the monetary amount to set in the returned instance, not null * @param roundingMode the rounding mode to adjust the scale, not null * @return the new instance with the input amount set, never null @@ -674,7 +673,7 @@ public Money withAmount(BigDecimal amount, RoundingMode roundingMode) { * For example, the literal '1.45d' will be converted to '1.45'. *

    * This instance is immutable and unaffected by this method. - * + * * @param amount the monetary amount to set in the returned instance, not null * @return the new instance with the input amount set, never null * @throws ArithmeticException if the scale of the amount is too large @@ -698,7 +697,7 @@ public Money withAmount(double amount) { * For example, the literal '1.45d' will be converted to '1.45'. *

    * This instance is immutable and unaffected by this method. - * + * * @param amount the monetary amount to set in the returned instance, not null * @param roundingMode the rounding mode to adjust the scale, not null * @return the new instance with the input amount set, never null @@ -715,7 +714,7 @@ public Money withAmount(double amount, RoundingMode roundingMode) { * The amounts must be in the same currency. *

    * This instance is immutable and unaffected by this method. - * + * * @param moniesToAdd the monetary values to add, no null elements, not null * @return the new instance with the input amounts added, never null * @throws CurrencyMismatchException if the currencies differ @@ -735,7 +734,7 @@ public Money plus(Iterable moniesToAdd) { * For example,'USD 25.95' plus 'USD 3.02' will 'USD 28.97'. *

    * This instance is immutable and unaffected by this method. - * + * * @param moneyToAdd the monetary value to add, not null * @return the new instance with the input amount added, never null * @throws CurrencyMismatchException if the currencies differ @@ -752,7 +751,7 @@ public Money plus(Money moneyToAdd) { * scale compatible with the currency. *

    * This instance is immutable and unaffected by this method. - * + * * @param amountToAdd the monetary value to add, not null * @return the new instance with the input amount added, never null * @throws ArithmeticException if the scale of the amount is too large @@ -769,7 +768,7 @@ public Money plus(BigDecimal amountToAdd) { * rounding mode will be used to adjust the result. *

    * This instance is immutable and unaffected by this method. - * + * * @param amountToAdd the monetary value to add, not null * @param roundingMode the rounding mode to use, not null * @return the new instance with the input amount added, never null @@ -792,7 +791,7 @@ public Money plus(BigDecimal amountToAdd, RoundingMode roundingMode) { * For example, the literal '1.45d' will be converted to '1.45'. *

    * This instance is immutable and unaffected by this method. - * + * * @param amountToAdd the monetary value to add, not null * @return the new instance with the input amount added, never null * @throws ArithmeticException if the scale of the amount is too large @@ -815,7 +814,7 @@ public Money plus(double amountToAdd) { * For example, the literal '1.45d' will be converted to '1.45'. *

    * This instance is immutable and unaffected by this method. - * + * * @param amountToAdd the monetary value to add, not null * @param roundingMode the rounding mode to use, not null * @return the new instance with the input amount added, never null @@ -831,7 +830,7 @@ public Money plus(double amountToAdd, RoundingMode roundingMode) { * For example, USD 23.45 plus 138 gives USD 161.45. *

    * This instance is immutable and unaffected by this method. - * + * * @param amountToAdd the monetary value to add, not null * @return the new instance with the input amount added, never null */ @@ -846,7 +845,7 @@ public Money plusMajor(long amountToAdd) { * For example, USD 23.45 plus 138 gives USD 24.83. *

    * This instance is immutable and unaffected by this method. - * + * * @param amountToAdd the monetary value to add, not null * @return the new instance with the input amount added, never null */ @@ -862,7 +861,7 @@ public Money plusMinor(long amountToAdd) { * The amounts must be in the same currency. *

    * This instance is immutable and unaffected by this method. - * + * * @param moniesToSubtract the monetary values to subtract, no null elements, not null * @return the new instance with the input amounts subtracted, never null * @throws CurrencyMismatchException if the currencies differ @@ -882,7 +881,7 @@ public Money minus(Iterable moniesToSubtract) { * For example,'USD 25.95' minus 'USD 3.02' will 'USD 22.93'. *

    * This instance is immutable and unaffected by this method. - * + * * @param moneyToSubtract the monetary value to subtract, not null * @return the new instance with the input amount subtracted, never null * @throws CurrencyMismatchException if the currencies differ @@ -899,7 +898,7 @@ public Money minus(Money moneyToSubtract) { * scale compatible with the currency. *

    * This instance is immutable and unaffected by this method. - * + * * @param amountToSubtract the monetary value to subtract, not null * @return the new instance with the input amount subtracted, never null * @throws ArithmeticException if the scale of the amount is too large @@ -916,7 +915,7 @@ public Money minus(BigDecimal amountToSubtract) { * rounding mode will be used to adjust the result. *

    * This instance is immutable and unaffected by this method. - * + * * @param amountToSubtract the monetary value to subtract, not null * @param roundingMode the rounding mode to use, not null * @return the new instance with the input amount subtracted, never null @@ -939,7 +938,7 @@ public Money minus(BigDecimal amountToSubtract, RoundingMode roundingMode) { * For example, the literal '1.45d' will be converted to '1.45'. *

    * This instance is immutable and unaffected by this method. - * + * * @param amountToSubtract the monetary value to subtract, not null * @return the new instance with the input amount subtracted, never null * @throws ArithmeticException if the scale of the amount is too large @@ -962,7 +961,7 @@ public Money minus(double amountToSubtract) { * For example, the literal '1.45d' will be converted to '1.45'. *

    * This instance is immutable and unaffected by this method. - * + * * @param amountToSubtract the monetary value to subtract, not null * @param roundingMode the rounding mode to use, not null * @return the new instance with the input amount subtracted, never null @@ -978,7 +977,7 @@ public Money minus(double amountToSubtract, RoundingMode roundingMode) { * For example, USD 23.45 minus 138 gives USD -114.55. *

    * This instance is immutable and unaffected by this method. - * + * * @param amountToSubtract the monetary value to subtract, not null * @return the new instance with the input amount subtracted, never null */ @@ -993,7 +992,7 @@ public Money minusMajor(long amountToSubtract) { * For example, USD 23.45 minus 138 gives USD 22.07. *

    * This instance is immutable and unaffected by this method. - * + * * @param amountToSubtract the monetary value to subtract, not null * @return the new instance with the input amount subtracted, never null */ @@ -1009,7 +1008,7 @@ public Money minusMinor(long amountToSubtract) { * the result is rounded as specified. *

    * This instance is immutable and unaffected by this method. - * + * * @param valueToMultiplyBy the scalar value to multiply by, not null * @param roundingMode the rounding mode to use to bring the decimal places back in line, not null * @return the new multiplied instance, never null @@ -1032,7 +1031,7 @@ public Money multipliedBy(BigDecimal valueToMultiplyBy, RoundingMode roundingMod * For example, the literal '1.45d' will be converted to '1.45'. *

    * This instance is immutable and unaffected by this method. - * + * * @param valueToMultiplyBy the scalar value to multiply by, not null * @param roundingMode the rounding mode to use to bring the decimal places back in line, not null * @return the new multiplied instance, never null @@ -1048,7 +1047,7 @@ public Money multipliedBy(double valueToMultiplyBy, RoundingMode roundingMode) { * This takes this amount and multiplies it by the specified value. *

    * This instance is immutable and unaffected by this method. - * + * * @param valueToMultiplyBy the scalar value to multiply by, not null * @return the new multiplied instance, never null */ @@ -1064,7 +1063,7 @@ public Money multipliedBy(long valueToMultiplyBy) { * the result is rounded as specified. *

    * This instance is immutable and unaffected by this method. - * + * * @param valueToDivideBy the scalar value to divide by, not null * @param roundingMode the rounding mode to use, not null * @return the new divided instance, never null @@ -1088,7 +1087,7 @@ public Money dividedBy(BigDecimal valueToDivideBy, RoundingMode roundingMode) { * For example, the literal '1.45d' will be converted to '1.45'. *

    * This instance is immutable and unaffected by this method. - * + * * @param valueToDivideBy the scalar value to divide by, not null * @param roundingMode the rounding mode to use, not null * @return the new divided instance, never null @@ -1106,7 +1105,7 @@ public Money dividedBy(double valueToDivideBy, RoundingMode roundingMode) { * the result is rounded as specified. *

    * This instance is immutable and unaffected by this method. - * + * * @param valueToDivideBy the scalar value to divide by, not null * @param roundingMode the rounding mode to use, not null * @return the new divided instance, never null @@ -1122,7 +1121,7 @@ public Money dividedBy(long valueToDivideBy, RoundingMode roundingMode) { * Returns a copy of this monetary value with the amount negated. *

    * This instance is immutable and unaffected by this method. - * + * * @return the new instance with the amount negated, never null */ public Money negated() { @@ -1133,7 +1132,7 @@ public Money negated() { * Returns a copy of this monetary value with a positive amount. *

    * This instance is immutable and unaffected by this method. - * + * * @return the new instance with the amount converted to be positive, never null */ public Money abs() { @@ -1156,7 +1155,7 @@ public Money abs() { * *

    * This instance is immutable and unaffected by this method. - * + * * @param scale the new scale * @param roundingMode the rounding mode to use, not null * @return the new instance with the amount converted to be positive, never null @@ -1173,7 +1172,7 @@ public Money rounded(int scale, RoundingMode roundingMode) { * the decimal places in the result. *

    * This instance is immutable and unaffected by this method. - * + * * @param currency the new currency, not null * @param conversionMultipler the conversion factor between the currencies, not null * @param roundingMode the rounding mode to use to bring the decimal places back in line, not null @@ -1190,7 +1189,7 @@ public Money convertedTo(CurrencyUnit currency, BigDecimal conversionMultipler, /** * Implements the {@code BigMoneyProvider} interface, returning a * {@code BigMoney} instance with the same currency, amount and scale. - * + * * @return the money instance, never null */ @Override @@ -1201,7 +1200,7 @@ public BigMoney toBigMoney() { //----------------------------------------------------------------------- /** * Checks if this instance and the specified instance have the same currency. - * + * * @param other the money to check, not null * @return true if they have the same currency */ @@ -1216,7 +1215,7 @@ public boolean isSameCurrency(BigMoneyProvider other) { * This allows {@code Money} to be compared to any {@code BigMoneyProvider}. * Scale is ignored in the comparison. * The compared values must be in the same currency. - * + * * @param other the other monetary value, not null * @return -1 if this is less than , 0 if equal, 1 if greater than * @throws CurrencyMismatchException if the currencies differ @@ -1232,7 +1231,7 @@ public int compareTo(BigMoneyProvider other) { * This allows {@code Money} to be compared to any {@code BigMoneyProvider}. * Scale is ignored, so 'USD 30.00' and 'USD 30' are equal. * The compared values must be in the same currency. - * + * * @param other the other monetary value, not null * @return true is this is greater than the specified monetary value * @throws CurrencyMismatchException if the currencies differ @@ -1248,7 +1247,7 @@ public boolean isEqual(BigMoneyProvider other) { * This allows {@code Money} to be compared to any {@code BigMoneyProvider}. * Scale is ignored in the comparison. * The compared values must be in the same currency. - * + * * @param other the other monetary value, not null * @return true is this is greater than the specified monetary value * @throws CurrencyMismatchException if the currencies differ @@ -1263,7 +1262,7 @@ public boolean isGreaterThan(BigMoneyProvider other) { * This allows {@code Money} to be compared to any {@code BigMoneyProvider}. * Scale is ignored in the comparison. * The compared values must be in the same currency. - * + * * @param other the other monetary value, not null * @return true is this is greater than or equal to the specified monetary value * @throws CurrencyMismatchException if the currencies differ @@ -1278,7 +1277,7 @@ public boolean isGreaterThanOrEqual(BigMoneyProvider other) { * This allows {@code Money} to be compared to any {@code BigMoneyProvider}. * Scale is ignored in the comparison. * The compared values must be in the same currency. - * + * * @param other the other monetary value, not null * @return true is this is less than the specified monetary value * @throws CurrencyMismatchException if the currencies differ @@ -1293,7 +1292,7 @@ public boolean isLessThan(BigMoneyProvider other) { * This allows {@code Money} to be compared to any {@code BigMoneyProvider}. * Scale is ignored in the comparison. * The compared values must be in the same currency. - * + * * @param other the other monetary value, not null * @return true is this is less than or equal to the specified monetary value * @throws CurrencyMismatchException if the currencies differ @@ -1308,7 +1307,7 @@ public boolean isLessThanOrEqual(BigMoneyProvider other) { *

    * The comparison takes into account the scale. * The compared values must be in the same currency. - * + * * @param other the other object to compare to, not null * @return true if this instance equals the other instance */ @@ -1317,8 +1316,7 @@ public boolean equals(Object other) { if (this == other) { return true; } - if (other instanceof Money) { - Money otherMoney = (Money) other; + if (other instanceof Money otherMoney) { return money.equals(otherMoney.money); } return false; @@ -1326,7 +1324,7 @@ public boolean equals(Object other) { /** * Returns a hash code for this monetary value. - * + * * @return a suitable hash code */ @Override @@ -1340,7 +1338,7 @@ public int hashCode() { *

    * The format is the 3 letter ISO currency code, followed by a space, * followed by the amount as per {@link BigDecimal#toPlainString()}. - * + * * @return the string representation of this monetary value, never null */ @Override diff --git a/src/main/java/org/joda/money/MoneyUtils.java b/src/main/java/org/joda/money/MoneyUtils.java index a1315c0..2d442e6 100644 --- a/src/main/java/org/joda/money/MoneyUtils.java +++ b/src/main/java/org/joda/money/MoneyUtils.java @@ -46,7 +46,7 @@ private MoneyUtils() { * Checks if the monetary value is zero, treating null as zero. *

    * This method accepts any implementation of {@code BigMoneyProvider}. - * + * * @param moneyProvider the money to check, null returns zero * @return true if the money is null or zero */ @@ -58,7 +58,7 @@ public static boolean isZero(BigMoneyProvider moneyProvider) { * Checks if the monetary value is positive and non-zero, treating null as zero. *

    * This method accepts any implementation of {@code BigMoneyProvider}. - * + * * @param moneyProvider the money to check, null returns false * @return true if the money is non-null and positive */ @@ -70,7 +70,7 @@ public static boolean isPositive(BigMoneyProvider moneyProvider) { * Checks if the monetary value is positive or zero, treating null as zero. *

    * This method accepts any implementation of {@code BigMoneyProvider}. - * + * * @param moneyProvider the money to check, null returns true * @return true if the money is null, zero or positive */ @@ -82,7 +82,7 @@ public static boolean isPositiveOrZero(BigMoneyProvider moneyProvider) { * Checks if the monetary value is negative and non-zero, treating null as zero. *

    * This method accepts any implementation of {@code BigMoneyProvider}. - * + * * @param moneyProvider the money to check, null returns false * @return true if the money is non-null and negative */ @@ -94,7 +94,7 @@ public static boolean isNegative(BigMoneyProvider moneyProvider) { * Checks if the monetary value is negative or zero, treating null as zero. *

    * This method accepts any implementation of {@code BigMoneyProvider}. - * + * * @param moneyProvider the money to check, null returns true * @return true if the money is null, zero or negative */ @@ -108,7 +108,7 @@ public static boolean isNegativeOrZero(BigMoneyProvider moneyProvider) { *

    * This returns the greater of money1 or money2 where null is ignored. * If both input values are null, then null is returned. - * + * * @param money1 the first money instance, null returns money2 * @param money2 the first money instance, null returns money1 * @return the maximum value, null if both inputs are null @@ -129,7 +129,7 @@ public static Money max(Money money1, Money money2) { *

    * This returns the greater of money1 or money2 where null is ignored. * If both input values are null, then null is returned. - * + * * @param money1 the first money instance, null returns money2 * @param money2 the first money instance, null returns money1 * @return the minimum value, null if both inputs are null @@ -151,7 +151,7 @@ public static Money min(Money money1, Money money2) { *

    * This returns {@code money1 + money2} where null is ignored. * If both input values are null, then null is returned. - * + * * @param money1 the first money instance, null returns money2 * @param money2 the first money instance, null returns money1 * @return the total, where null is ignored, null if both inputs are null @@ -173,7 +173,7 @@ public static Money add(Money money1, Money money2) { *

    * This returns {@code money1 - money2} where null is ignored. * If both input values are null, then null is returned. - * + * * @param money1 the first money instance, null treated as zero * @param money2 the first money instance, null returns money1 * @return the total, where null is ignored, null if both inputs are null @@ -195,7 +195,7 @@ public static Money subtract(Money money1, Money money2) { *

    * This returns the greater of money1 or money2 where null is ignored. * If both input values are null, then null is returned. - * + * * @param money1 the first money instance, null returns money2 * @param money2 the first money instance, null returns money1 * @return the maximum value, null if both inputs are null @@ -216,7 +216,7 @@ public static BigMoney max(BigMoney money1, BigMoney money2) { *

    * This returns the greater of money1 or money2 where null is ignored. * If both input values are null, then null is returned. - * + * * @param money1 the first money instance, null returns money2 * @param money2 the first money instance, null returns money1 * @return the minimum value, null if both inputs are null @@ -238,7 +238,7 @@ public static BigMoney min(BigMoney money1, BigMoney money2) { *

    * This returns {@code money1 + money2} where null is ignored. * If both input values are null, then null is returned. - * + * * @param money1 the first money instance, null returns money2 * @param money2 the first money instance, null returns money1 * @return the total, where null is ignored, null if both inputs are null @@ -260,7 +260,7 @@ public static BigMoney add(BigMoney money1, BigMoney money2) { *

    * This returns {@code money1 - money2} where null is ignored. * If both input values are null, then null is returned. - * + * * @param money1 the first money instance, null treated as zero * @param money2 the first money instance, null returns money1 * @return the total, where null is ignored, null if both inputs are null diff --git a/src/main/java/org/joda/money/Ser.java b/src/main/java/org/joda/money/Ser.java index f8fec9f..c3cd8ad 100644 --- a/src/main/java/org/joda/money/Ser.java +++ b/src/main/java/org/joda/money/Ser.java @@ -52,7 +52,7 @@ public Ser() { /** * Constructor for package. - * + * * @param type the type * @param object the object */ @@ -73,28 +73,25 @@ public Ser() { public void writeExternal(ObjectOutput out) throws IOException { out.writeByte(type); switch (type) { - case BIG_MONEY: { - BigMoney obj = (BigMoney) object; + case BIG_MONEY -> { + var obj = (BigMoney) object; writeBigMoney(out, obj); - return; } - case MONEY: { - Money obj = (Money) object; + case MONEY -> { + var obj = (Money) object; writeBigMoney(out, obj.toBigMoney()); - return; } - case CURRENCY_UNIT: { - CurrencyUnit obj = (CurrencyUnit) object; + case CURRENCY_UNIT -> { + var obj = (CurrencyUnit) object; writeCurrency(out, obj); - return; } + default -> throw new InvalidClassException("Joda-Money bug: Serialization broken"); } - throw new InvalidClassException("Joda-Money bug: Serialization broken"); } private void writeBigMoney(ObjectOutput out, BigMoney obj) throws IOException { writeCurrency(out, obj.getCurrencyUnit()); - byte[] bytes = obj.getAmount().unscaledValue().toByteArray(); + var bytes = obj.getAmount().unscaledValue().toByteArray(); out.writeInt(bytes.length); out.write(bytes); out.writeInt(obj.getScale()); @@ -116,34 +113,31 @@ private void writeCurrency(ObjectOutput out, CurrencyUnit obj) throws IOExceptio public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { type = in.readByte(); switch (type) { - case BIG_MONEY: { + case BIG_MONEY -> { object = readBigMoney(in); - return; } - case MONEY: { + case MONEY -> { object = new Money(readBigMoney(in)); - return; } - case CURRENCY_UNIT: { + case CURRENCY_UNIT -> { object = readCurrency(in); - return; } + default -> throw new StreamCorruptedException("Serialization input has invalid type"); } - throw new StreamCorruptedException("Serialization input has invalid type"); } private BigMoney readBigMoney(ObjectInput in) throws IOException { - CurrencyUnit currency = readCurrency(in); - byte[] bytes = new byte[in.readInt()]; + var currency = readCurrency(in); + var bytes = new byte[in.readInt()]; in.readFully(bytes); - BigDecimal bd = new BigDecimal(new BigInteger(bytes), in.readInt()); - BigMoney bigMoney = new BigMoney(currency, bd); + var bd = new BigDecimal(new BigInteger(bytes), in.readInt()); + var bigMoney = new BigMoney(currency, bd); return bigMoney; } private CurrencyUnit readCurrency(ObjectInput in) throws IOException { - String code = in.readUTF(); - CurrencyUnit singletonCurrency = CurrencyUnit.of(code); + var code = in.readUTF(); + var singletonCurrency = CurrencyUnit.of(code); if (singletonCurrency.getNumericCode() != in.readShort()) { throw new InvalidObjectException("Deserialization found a mismatch in the numeric code for currency " + code); } @@ -155,7 +149,7 @@ private CurrencyUnit readCurrency(ObjectInput in) throws IOException { /** * Returns the object that will replace this one. - * + * * @return the read object, should never be null */ private Object readResolve() { diff --git a/src/main/java/org/joda/money/format/AmountPrinterParser.java b/src/main/java/org/joda/money/format/AmountPrinterParser.java index b20aaab..7d803bd 100644 --- a/src/main/java/org/joda/money/format/AmountPrinterParser.java +++ b/src/main/java/org/joda/money/format/AmountPrinterParser.java @@ -45,7 +45,7 @@ final class AmountPrinterParser implements MoneyPrinter, MoneyParser, Serializab //----------------------------------------------------------------------- @Override public void print(MoneyPrintContext context, Appendable appendable, BigMoney money) throws IOException { - MoneyAmountStyle activeStyle = style.localize(context.getLocale()); + var activeStyle = style.localize(context.getLocale()); String str; if (money.isNegative()) { if (!activeStyle.isAbsValue()) { @@ -55,20 +55,20 @@ public void print(MoneyPrintContext context, Appendable appendable, BigMoney mon } else { str = money.getAmount().toPlainString(); } - char zeroChar = activeStyle.getZeroCharacter(); + var zeroChar = activeStyle.getZeroCharacter(); if (zeroChar != '0') { - int diff = zeroChar - '0'; - StringBuilder zeroConvert = new StringBuilder(str); - for (int i = 0; i < str.length(); i++) { - char ch = str.charAt(i); + var diff = zeroChar - '0'; + var zeroConvert = new StringBuilder(str); + for (var i = 0; i < str.length(); i++) { + var ch = str.charAt(i); if (ch >= '0' && ch <= '9') { zeroConvert.setCharAt(i, (char) (ch + diff)); } } str = zeroConvert.toString(); } - final int decPoint = str.indexOf('.'); - final int afterDecPoint = decPoint + 1; + var decPoint = str.indexOf('.'); + var afterDecPoint = decPoint + 1; if (activeStyle.getGroupingStyle() == GroupingStyle.NONE) { if (decPoint < 0) { appendable.append(str); @@ -80,14 +80,14 @@ public void print(MoneyPrintContext context, Appendable appendable, BigMoney mon .append(activeStyle.getDecimalPointCharacter()).append(str.substring(afterDecPoint)); } } else { - int groupingSize = activeStyle.getGroupingSize(); - int extendedGroupingSize = activeStyle.getExtendedGroupingSize(); + var groupingSize = activeStyle.getGroupingSize(); + var extendedGroupingSize = activeStyle.getExtendedGroupingSize(); extendedGroupingSize = extendedGroupingSize == 0 ? groupingSize : extendedGroupingSize; - char groupingChar = activeStyle.getGroupingCharacter(); - int pre = (decPoint < 0 ? str.length() : decPoint); - int post = (decPoint < 0 ? 0 : str.length() - decPoint - 1); + var groupingChar = activeStyle.getGroupingCharacter(); + var pre = (decPoint < 0 ? str.length() : decPoint); + var post = (decPoint < 0 ? 0 : str.length() - decPoint - 1); appendable.append(str.charAt(0)); - for (int i = 1; i < pre; i++) { + for (var i = 1; i < pre; i++) { if (isPreGroupingPoint(pre - i, groupingSize, extendedGroupingSize)) { appendable.append(groupingChar); } @@ -101,7 +101,7 @@ public void print(MoneyPrintContext context, Appendable appendable, BigMoney mon appendable.append(str.substring(afterDecPoint)); } } else { - for (int i = 0; i < post; i++) { + for (var i = 0; i < post; i++) { appendable.append(str.charAt(i + afterDecPoint)); if (isPostGroupingPoint(i, post, groupingSize, extendedGroupingSize)) { appendable.append(groupingChar); @@ -119,7 +119,7 @@ private boolean isPreGroupingPoint(int remaining, int groupingSize, int extended } private boolean isPostGroupingPoint(int i, int post, int groupingSize, int extendedGroupingSize) { - boolean atEnd = (i + 1) >= post; + var atEnd = (i + 1) >= post; if (i > groupingSize) { return (i - groupingSize) % extendedGroupingSize == (extendedGroupingSize - 1) && !atEnd; } @@ -128,14 +128,14 @@ private boolean isPostGroupingPoint(int i, int post, int groupingSize, int exten @Override public void parse(MoneyParseContext context) { - final int len = context.getTextLength(); - final MoneyAmountStyle activeStyle = style.localize(context.getLocale()); - char[] buf = new char[len - context.getIndex()]; - int bufPos = 0; - boolean dpSeen = false; - int pos = context.getIndex(); + var len = context.getTextLength(); + var activeStyle = style.localize(context.getLocale()); + var buf = new char[len - context.getIndex()]; + var bufPos = 0; + var dpSeen = false; + var pos = context.getIndex(); if (pos < len) { - char ch = context.getText().charAt(pos++); + var ch = context.getText().charAt(pos++); if (ch == activeStyle.getNegativeSignCharacter()) { buf[bufPos++] = '-'; } else if (ch == activeStyle.getPositiveSignCharacter()) { @@ -150,17 +150,17 @@ public void parse(MoneyParseContext context) { return; } } - boolean lastWasGroup = false; + var lastWasGroup = false; for (; pos < len; pos++) { - char ch = context.getText().charAt(pos); + var ch = context.getText().charAt(pos); if (ch >= activeStyle.getZeroCharacter() && ch < activeStyle.getZeroCharacter() + 10) { buf[bufPos++] = (char) ('0' + ch - activeStyle.getZeroCharacter()); lastWasGroup = false; - } else if (ch == activeStyle.getDecimalPointCharacter() && dpSeen == false) { + } else if (ch == activeStyle.getDecimalPointCharacter() && !dpSeen) { buf[bufPos++] = '.'; dpSeen = true; lastWasGroup = false; - } else if (ch == activeStyle.getGroupingCharacter() && lastWasGroup == false) { + } else if (ch == activeStyle.getGroupingCharacter() && !lastWasGroup) { lastWasGroup = true; } else { break; diff --git a/src/main/java/org/joda/money/format/LiteralPrinterParser.java b/src/main/java/org/joda/money/format/LiteralPrinterParser.java index 3ee78f3..147b08e 100644 --- a/src/main/java/org/joda/money/format/LiteralPrinterParser.java +++ b/src/main/java/org/joda/money/format/LiteralPrinterParser.java @@ -49,7 +49,7 @@ public void print(MoneyPrintContext context, Appendable appendable, BigMoney mon @Override public void parse(MoneyParseContext context) { - int endPos = context.getIndex() + literal.length(); + var endPos = context.getIndex() + literal.length(); if (endPos <= context.getTextLength() && context.getTextSubstring(context.getIndex(), endPos).equals(literal)) { context.setIndex(endPos); diff --git a/src/main/java/org/joda/money/format/MoneyAmountStyle.java b/src/main/java/org/joda/money/format/MoneyAmountStyle.java index eed7e23..37f2ca3 100644 --- a/src/main/java/org/joda/money/format/MoneyAmountStyle.java +++ b/src/main/java/org/joda/money/format/MoneyAmountStyle.java @@ -106,7 +106,7 @@ public final class MoneyAmountStyle implements Serializable { /** * Cache of localized styles. */ - private static final ConcurrentMap LOCALIZED_CACHE = new ConcurrentHashMap(); + private static final ConcurrentMap LOCALIZED_CACHE = new ConcurrentHashMap<>(); /** * Serialization version. */ @@ -171,7 +171,7 @@ public static MoneyAmountStyle of(Locale locale) { //----------------------------------------------------------------------- /** * Constructor, creating a new monetary instance. - * + * * @param zeroCharacter the zero character * @param positiveCharacter the positive sign * @param negativeCharacter the negative sign @@ -218,14 +218,14 @@ private MoneyAmountStyle( *

    * The settings for the locale are pulled from {@link DecimalFormatSymbols} and * {@link DecimalFormat}. - * + * * @param locale the locale to use, not null * @return the new instance for chaining, never null */ public MoneyAmountStyle localize(Locale locale) { MoneyFormatter.checkNotNull(locale, "Locale must not be null"); - MoneyAmountStyle result = this; - MoneyAmountStyle protoStyle = null; + var result = this; + var protoStyle = (MoneyAmountStyle) null; if (zeroCharacter < 0) { protoStyle = getLocalizedStyle(locale); result = result.withZeroCharacter(protoStyle.getZeroCharacter()); @@ -265,16 +265,16 @@ public MoneyAmountStyle localize(Locale locale) { *

    * The method {@code DecimalFormatSymbols.getInstance(locale)} will be used * in order to allow the use of locales defined as extensions. - * + * * @param locale the {@link Locale} used to get the correct {@link DecimalFormatSymbols} * @return the symbols, never null */ private static MoneyAmountStyle getLocalizedStyle(Locale locale) { - MoneyAmountStyle protoStyle = LOCALIZED_CACHE.get(locale); + var protoStyle = LOCALIZED_CACHE.get(locale); if (protoStyle == null) { - DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance(locale); - NumberFormat format = NumberFormat.getCurrencyInstance(locale); - int size = (format instanceof DecimalFormat ? ((DecimalFormat) format).getGroupingSize() : 3); + var symbols = DecimalFormatSymbols.getInstance(locale); + var format = NumberFormat.getCurrencyInstance(locale); + var size = (format instanceof DecimalFormat ? ((DecimalFormat) format).getGroupingSize() : 3); size = size <= 0 ? 3 : size; protoStyle = new MoneyAmountStyle( symbols.getZeroDigit(), @@ -299,7 +299,7 @@ private static MoneyAmountStyle getLocalizedStyle(Locale locale) { * The UTF-8 standard supports a number of different numeric scripts. * Each script has the characters in order from zero to nine. * This method returns the zero character, which therefore also defines one to nine. - * + * * @return the zero character, null if to be determined by locale */ public Character getZeroCharacter() { @@ -315,12 +315,12 @@ public Character getZeroCharacter() { *

    * For English, this is a '0'. Some other scripts use different characters * for the numbers zero to nine. - * + * * @param zeroCharacter the zero character, null if to be determined by locale * @return the new instance for chaining, never null */ public MoneyAmountStyle withZeroCharacter(Character zeroCharacter) { - int zeroVal = (zeroCharacter == null ? -1 : zeroCharacter); + var zeroVal = (zeroCharacter == null ? -1 : zeroCharacter); if (zeroVal == this.zeroCharacter) { return this; } @@ -336,7 +336,7 @@ public MoneyAmountStyle withZeroCharacter(Character zeroCharacter) { * Gets the character used for the positive sign character. *

    * The standard ASCII symbol is '+'. - * + * * @return the format for positive amounts, null if to be determined by locale */ public Character getPositiveSignCharacter() { @@ -347,12 +347,12 @@ public Character getPositiveSignCharacter() { * Returns a copy of this style with the specified positive sign character. *

    * The standard ASCII symbol is '+'. - * + * * @param positiveCharacter the positive character, null if to be determined by locale * @return the new instance for chaining, never null */ public MoneyAmountStyle withPositiveSignCharacter(Character positiveCharacter) { - int positiveVal = (positiveCharacter == null ? -1 : positiveCharacter); + var positiveVal = (positiveCharacter == null ? -1 : positiveCharacter); if (positiveVal == this.positiveCharacter) { return this; } @@ -368,7 +368,7 @@ public MoneyAmountStyle withPositiveSignCharacter(Character positiveCharacter) { * Gets the character used for the negative sign character. *

    * The standard ASCII symbol is '-'. - * + * * @return the format for negative amounts, null if to be determined by locale */ public Character getNegativeSignCharacter() { @@ -379,12 +379,12 @@ public Character getNegativeSignCharacter() { * Returns a copy of this style with the specified negative sign character. *

    * The standard ASCII symbol is '-'. - * + * * @param negativeCharacter the negative character, null if to be determined by locale * @return the new instance for chaining, never null */ public MoneyAmountStyle withNegativeSignCharacter(Character negativeCharacter) { - int negativeVal = (negativeCharacter == null ? -1 : negativeCharacter); + var negativeVal = (negativeCharacter == null ? -1 : negativeCharacter); if (negativeVal == this.negativeCharacter) { return this; } @@ -398,7 +398,7 @@ public MoneyAmountStyle withNegativeSignCharacter(Character negativeCharacter) { //----------------------------------------------------------------------- /** * Gets the character used for the decimal point. - * + * * @return the decimal point character, null if to be determined by locale */ public Character getDecimalPointCharacter() { @@ -409,12 +409,12 @@ public Character getDecimalPointCharacter() { * Returns a copy of this style with the specified decimal point character. *

    * For English, this is a dot. - * + * * @param decimalPointCharacter the decimal point character, null if to be determined by locale * @return the new instance for chaining, never null */ public MoneyAmountStyle withDecimalPointCharacter(Character decimalPointCharacter) { - int dpVal = (decimalPointCharacter == null ? -1 : decimalPointCharacter); + var dpVal = (decimalPointCharacter == null ? -1 : decimalPointCharacter); if (dpVal == this.decimalPointCharacter) { return this; } @@ -428,7 +428,7 @@ public MoneyAmountStyle withDecimalPointCharacter(Character decimalPointCharacte //----------------------------------------------------------------------- /** * Gets the character used to separate groups, typically thousands. - * + * * @return the grouping character, null if to be determined by locale */ public Character getGroupingCharacter() { @@ -439,12 +439,12 @@ public Character getGroupingCharacter() { * Returns a copy of this style with the specified grouping character. *

    * For English, this is a comma. - * + * * @param groupingCharacter the grouping character, null if to be determined by locale * @return the new instance for chaining, never null */ public MoneyAmountStyle withGroupingCharacter(Character groupingCharacter) { - int groupingVal = (groupingCharacter == null ? -1 : groupingCharacter); + var groupingVal = (groupingCharacter == null ? -1 : groupingCharacter); if (groupingVal == this.groupingCharacter) { return this; } @@ -458,7 +458,7 @@ public MoneyAmountStyle withGroupingCharacter(Character groupingCharacter) { //----------------------------------------------------------------------- /** * Gets the size of each group, typically 3 for thousands. - * + * * @return the size of each group, null if to be determined by locale */ public Integer getGroupingSize() { @@ -467,14 +467,14 @@ public Integer getGroupingSize() { /** * Returns a copy of this style with the specified grouping size. - * + * * @param groupingSize the size of each group, such as 3 for thousands, * not zero or negative, null if to be determined by locale * @return the new instance for chaining, never null * @throws IllegalArgumentException if the grouping size is zero or less */ public MoneyAmountStyle withGroupingSize(Integer groupingSize) { - int sizeVal = (groupingSize == null ? -1 : groupingSize); + var sizeVal = (groupingSize == null ? -1 : groupingSize); if (groupingSize != null && sizeVal <= 0) { throw new IllegalArgumentException("Grouping size must be greater than zero"); } @@ -496,7 +496,7 @@ public MoneyAmountStyle withGroupingSize(Integer groupingSize) { * closest to the decimal point is of size 3 and other groups are of size 2. * The extended grouping size is used for groups that are not next to the decimal point. * The value zero is used to indicate that extended grouping is not needed. - * + * * @return the size of each group, null if to be determined by locale */ public Integer getExtendedGroupingSize() { @@ -505,14 +505,14 @@ public Integer getExtendedGroupingSize() { /** * Returns a copy of this style with the specified extended grouping size. - * + * * @param extendedGroupingSize the size of each group, such as 3 for thousands, * not zero or negative, null if to be determined by locale * @return the new instance for chaining, never null * @throws IllegalArgumentException if the grouping size is zero or less */ public MoneyAmountStyle withExtendedGroupingSize(Integer extendedGroupingSize) { - int sizeVal = (extendedGroupingSize == null ? -1 : extendedGroupingSize); + var sizeVal = (extendedGroupingSize == null ? -1 : extendedGroupingSize); if (extendedGroupingSize != null && sizeVal < 0) { throw new IllegalArgumentException("Extended grouping size must not be negative"); } @@ -529,7 +529,7 @@ public MoneyAmountStyle withExtendedGroupingSize(Integer extendedGroupingSize) { //----------------------------------------------------------------------- /** * Gets the style of grouping required. - * + * * @return the grouping style, not null */ public GroupingStyle getGroupingStyle() { @@ -538,7 +538,7 @@ public GroupingStyle getGroupingStyle() { /** * Returns a copy of this style with the specified grouping setting. - * + * * @param groupingStyle the grouping style, not null * @return the new instance for chaining, never null */ @@ -557,7 +557,7 @@ public MoneyAmountStyle withGroupingStyle(GroupingStyle groupingStyle) { //----------------------------------------------------------------------- /** * Gets whether to always use the decimal point, even if there is no fraction. - * + * * @return whether to force the decimal point on output */ public boolean isForcedDecimalPoint() { @@ -566,7 +566,7 @@ public boolean isForcedDecimalPoint() { /** * Returns a copy of this style with the specified decimal point setting. - * + * * @param forceDecimalPoint true to force the use of the decimal point, false to use it if required * @return the new instance for chaining, never null */ @@ -588,7 +588,7 @@ public MoneyAmountStyle withForcedDecimalPoint(boolean forceDecimalPoint) { * If this is set to true, the absolute (unsigned) value will be output. * If this is set to false, the signed value will be output. * Note that when parsing, signs are accepted. - * + * * @return true to output the absolute value, false for the signed value */ public boolean isAbsValue() { @@ -601,7 +601,7 @@ public boolean isAbsValue() { * If this is set to true, the absolute (unsigned) value will be output. * If this is set to false, the signed value will be output. * Note that when parsing, signs are accepted. - * + * * @param absValue true to output the absolute value, false for the signed value * @return the new instance for chaining, never null */ @@ -619,7 +619,7 @@ public MoneyAmountStyle withAbsValue(boolean absValue) { //----------------------------------------------------------------------- /** * Compares this style with another. - * + * * @param other the other style, null returns false * @return true if equal */ @@ -628,10 +628,10 @@ public boolean equals(Object other) { if (other == this) { return true; } - if (other instanceof MoneyAmountStyle == false) { + if (!(other instanceof MoneyAmountStyle)) { return false; } - MoneyAmountStyle otherStyle = (MoneyAmountStyle) other; + var otherStyle = (MoneyAmountStyle) other; return (zeroCharacter == otherStyle.zeroCharacter) && (positiveCharacter == otherStyle.positiveCharacter) && (negativeCharacter == otherStyle.negativeCharacter) && @@ -645,12 +645,12 @@ public boolean equals(Object other) { /** * A suitable hash code. - * + * * @return a hash code */ @Override public int hashCode() { - int hash = 13; + var hash = 13; hash += zeroCharacter * 17; hash += positiveCharacter * 17; hash += negativeCharacter * 17; @@ -666,7 +666,7 @@ public int hashCode() { //----------------------------------------------------------------------- /** * Gets a string summary of the style. - * + * * @return a string summarising the style, never null */ @Override diff --git a/src/main/java/org/joda/money/format/MoneyFormatException.java b/src/main/java/org/joda/money/format/MoneyFormatException.java index 9e16ccc..569bd11 100644 --- a/src/main/java/org/joda/money/format/MoneyFormatException.java +++ b/src/main/java/org/joda/money/format/MoneyFormatException.java @@ -29,7 +29,7 @@ public class MoneyFormatException extends RuntimeException { /** * Constructor taking a message. - * + * * @param message the message */ public MoneyFormatException(String message) { @@ -38,7 +38,7 @@ public MoneyFormatException(String message) { /** * Constructor taking a message and cause. - * + * * @param message the message * @param cause the exception cause */ diff --git a/src/main/java/org/joda/money/format/MoneyFormatter.java b/src/main/java/org/joda/money/format/MoneyFormatter.java index 09eafd7..2104c1b 100644 --- a/src/main/java/org/joda/money/format/MoneyFormatter.java +++ b/src/main/java/org/joda/money/format/MoneyFormatter.java @@ -64,7 +64,7 @@ static void checkNotNull(Object object, String message) { //----------------------------------------------------------------------- /** * Constructor, creating a new formatter. - * + * * @param locale the locale to use, not null * @param printers the printers, not null * @param parsers the parsers, not null @@ -82,7 +82,7 @@ static void checkNotNull(Object object, String message) { /** * Constructor, creating a new formatter. - * + * * @param locale the locale to use, not null * @param printerParser the printer/parser, not null */ @@ -96,7 +96,7 @@ private MoneyFormatter(Locale locale, MultiPrinterParser printerParser) { //----------------------------------------------------------------------- /** * Gets the printer/parser. - * + * * @return the printer/parser, never null */ MultiPrinterParser getPrinterParser() { @@ -106,7 +106,7 @@ MultiPrinterParser getPrinterParser() { //----------------------------------------------------------------------- /** * Gets the locale to use. - * + * * @return the locale, never null */ public Locale getLocale() { @@ -118,7 +118,7 @@ public Locale getLocale() { *

    * Changing the locale may change the style of output depending on how the * formatter has been configured. - * + * * @param locale the locale, not null * @return the new instance, never null */ @@ -133,7 +133,7 @@ public MoneyFormatter withLocale(Locale locale) { *

    * If the formatter cannot print, an UnsupportedOperationException will * be thrown from the print methods. - * + * * @return true if the formatter can print */ public boolean isPrinter() { @@ -145,7 +145,7 @@ public boolean isPrinter() { *

    * If the formatter cannot parse, an UnsupportedOperationException will * be thrown from the parse methods. - * + * * @return true if the formatter can parse */ public boolean isParser() { @@ -155,14 +155,14 @@ public boolean isParser() { //----------------------------------------------------------------------- /** * Prints a monetary value to a {@code String}. - * + * * @param moneyProvider the money to print, not null * @return the string printed using the settings of this formatter * @throws UnsupportedOperationException if the formatter is unable to print * @throws MoneyFormatException if there is a problem while printing */ public String print(BigMoneyProvider moneyProvider) { - StringBuilder buf = new StringBuilder(); + var buf = new StringBuilder(); print(buf, moneyProvider); return buf.toString(); } @@ -174,7 +174,7 @@ public String print(BigMoneyProvider moneyProvider) { * Example implementations of {@code Appendable} are {@code StringBuilder}, * {@code StringBuffer} or {@code Writer}. Note that {@code StringBuilder} * and {@code StringBuffer} never throw an {@code IOException}. - * + * * @param appendable the appendable to add to, not null * @param moneyProvider the money to print, not null * @throws UnsupportedOperationException if the formatter is unable to print @@ -195,7 +195,7 @@ public void print(Appendable appendable, BigMoneyProvider moneyProvider) { * Example implementations of {@code Appendable} are {@code StringBuilder}, * {@code StringBuffer} or {@code Writer}. Note that {@code StringBuilder} * and {@code StringBuffer} never throw an {@code IOException}. - * + * * @param appendable the appendable to add to, not null * @param moneyProvider the money to print, not null * @throws UnsupportedOperationException if the formatter is unable to print @@ -204,12 +204,12 @@ public void print(Appendable appendable, BigMoneyProvider moneyProvider) { */ public void printIO(Appendable appendable, BigMoneyProvider moneyProvider) throws IOException { checkNotNull(moneyProvider, "BigMoneyProvider must not be null"); - if (isPrinter() == false) { + if (!isPrinter()) { throw new UnsupportedOperationException("MoneyFomatter has not been configured to be able to print"); } - BigMoney money = BigMoney.of(moneyProvider); - MoneyPrintContext context = new MoneyPrintContext(locale); + var money = BigMoney.of(moneyProvider); + var context = new MoneyPrintContext(locale); printerParser.print(context, appendable, money); } @@ -220,7 +220,7 @@ public void printIO(Appendable appendable, BigMoneyProvider moneyProvider) throw * The parse must complete normally and parse the entire text (currency and amount). * If the parse completes without reading the entire length of the text, an exception is thrown. * If any other problem occurs during parsing, an exception is thrown. - * + * * @param text the text to parse, not null * @return the parsed monetary value, never null * @throws UnsupportedOperationException if the formatter is unable to parse @@ -228,12 +228,12 @@ public void printIO(Appendable appendable, BigMoneyProvider moneyProvider) throw */ public BigMoney parseBigMoney(CharSequence text) { checkNotNull(text, "Text must not be null"); - MoneyParseContext result = parse(text, 0); - if (result.isError() || result.isFullyParsed() == false || result.isComplete() == false) { - String str = (text.length() > 64 ? text.subSequence(0, 64).toString() + "..." : text.toString()); + var result = parse(text, 0); + if (result.isError() || !result.isFullyParsed() || !result.isComplete()) { + var str = (text.length() > 64 ? text.subSequence(0, 64).toString() + "..." : text.toString()); if (result.isError()) { throw new MoneyFormatException("Text could not be parsed at index " + result.getErrorIndex() + ": " + str); - } else if (result.isFullyParsed() == false) { + } else if (!result.isFullyParsed()) { throw new MoneyFormatException("Unparsed text found at index " + result.getIndex() + ": " + str); } else { throw new MoneyFormatException("Parsing did not find both currency and amount: " + str); @@ -249,7 +249,7 @@ public BigMoney parseBigMoney(CharSequence text) { * The parse must complete normally and parse the entire text (currency and amount). * If the parse completes without reading the entire length of the text, an exception is thrown. * If any other problem occurs during parsing, an exception is thrown. - * + * * @param text the text to parse, not null * @return the parsed monetary value, never null * @throws UnsupportedOperationException if the formatter is unable to parse @@ -279,10 +279,10 @@ public MoneyParseContext parse(CharSequence text, int startIndex) { if (startIndex < 0 || startIndex > text.length()) { throw new StringIndexOutOfBoundsException("Invalid start index: " + startIndex); } - if (isParser() == false) { + if (!isParser()) { throw new UnsupportedOperationException("MoneyFomatter has not been configured to be able to parse"); } - MoneyParseContext context = new MoneyParseContext(locale, text, startIndex); + var context = new MoneyParseContext(locale, text, startIndex); printerParser.parse(context); return context; } @@ -290,7 +290,7 @@ public MoneyParseContext parse(CharSequence text, int startIndex) { //----------------------------------------------------------------------- /** * Gets a string summary of the formatter. - * + * * @return a string summarising the formatter, never null */ @Override diff --git a/src/main/java/org/joda/money/format/MoneyFormatterBuilder.java b/src/main/java/org/joda/money/format/MoneyFormatterBuilder.java index 362a3a0..0d0c10f 100644 --- a/src/main/java/org/joda/money/format/MoneyFormatterBuilder.java +++ b/src/main/java/org/joda/money/format/MoneyFormatterBuilder.java @@ -55,11 +55,11 @@ public MoneyFormatterBuilder() { *

    * The format used is {@link MoneyAmountStyle#ASCII_DECIMAL_POINT_GROUP3_COMMA}. * The amount is the value itself, such as '12.34'. - * + * * @return this, for chaining, never null */ public MoneyFormatterBuilder appendAmount() { - AmountPrinterParser pp = new AmountPrinterParser(MoneyAmountStyle.ASCII_DECIMAL_POINT_GROUP3_COMMA); + var pp = new AmountPrinterParser(MoneyAmountStyle.ASCII_DECIMAL_POINT_GROUP3_COMMA); return appendInternal(pp, pp); } @@ -68,11 +68,11 @@ public MoneyFormatterBuilder appendAmount() { *

    * The format used is {@link MoneyAmountStyle#LOCALIZED_GROUPING}. * The amount is the value itself, such as '12.34'. - * + * * @return this, for chaining, never null */ public MoneyFormatterBuilder appendAmountLocalized() { - AmountPrinterParser pp = new AmountPrinterParser(MoneyAmountStyle.LOCALIZED_GROUPING); + var pp = new AmountPrinterParser(MoneyAmountStyle.LOCALIZED_GROUPING); return appendInternal(pp, pp); } @@ -85,13 +85,13 @@ public MoneyFormatterBuilder appendAmountLocalized() { * This includes the characters for positive, negative, decimal, grouping and whether * to output the absolute or signed amount. * See {@link MoneyAmountStyle} for more details. - * + * * @param style the style to use, not null * @return this, for chaining, never null */ public MoneyFormatterBuilder appendAmount(MoneyAmountStyle style) { MoneyFormatter.checkNotNull(style, "MoneyAmountStyle must not be null"); - AmountPrinterParser pp = new AmountPrinterParser(style); + var pp = new AmountPrinterParser(style); return appendInternal(pp, pp); } @@ -100,7 +100,7 @@ public MoneyFormatterBuilder appendAmount(MoneyAmountStyle style) { * Appends the currency code to the builder. *

    * The currency code is the three letter ISO code, such as 'GBP'. - * + * * @return this, for chaining, never null */ public MoneyFormatterBuilder appendCurrencyCode() { @@ -112,7 +112,7 @@ public MoneyFormatterBuilder appendCurrencyCode() { *

    * The numeric code is the ISO numeric code, such as '826' and is * zero padded to three digits. - * + * * @return this, for chaining, never null */ public MoneyFormatterBuilder appendCurrencyNumeric3Code() { @@ -123,7 +123,7 @@ public MoneyFormatterBuilder appendCurrencyNumeric3Code() { * Appends the currency code to the builder. *

    * The numeric code is the ISO numeric code, such as '826'. - * + * * @return this, for chaining, never null */ public MoneyFormatterBuilder appendCurrencyNumericCode() { @@ -137,7 +137,7 @@ public MoneyFormatterBuilder appendCurrencyNumericCode() { * of the formatter. *

    * Symbols cannot be parsed. - * + * * @return this, for chaining, never null */ public MoneyFormatterBuilder appendCurrencySymbolLocalized() { @@ -149,7 +149,7 @@ public MoneyFormatterBuilder appendCurrencySymbolLocalized() { *

    * The localized currency symbol is the symbol as chosen by the locale * of the formatter. - * + * * @param literal the literal to append, null or empty ignored * @return this, for chaining, never null */ @@ -157,7 +157,7 @@ public MoneyFormatterBuilder appendLiteral(CharSequence literal) { if (literal == null || literal.length() == 0) { return this; } - LiteralPrinterParser pp = new LiteralPrinterParser(literal.toString()); + var pp = new LiteralPrinterParser(literal.toString()); return appendInternal(pp, pp); } @@ -168,7 +168,7 @@ public MoneyFormatterBuilder appendLiteral(CharSequence literal) { * If the specified formatter cannot print, then the the output of this * builder will be unable to print. If the specified formatter cannot parse, * then the output of this builder will be unable to parse. - * + * * @param formatter the formatter to append, not null * @return this for chaining, never null */ @@ -182,7 +182,7 @@ public MoneyFormatterBuilder append(MoneyFormatter formatter) { * Appends the specified printer and parser to this builder. *

    * If null is specified then the formatter will be unable to print/parse. - * + * * @param printer the printer to append, null makes the formatter unable to print * @param parser the parser to append, null makes the formatter unable to parse * @return this for chaining, never null @@ -208,7 +208,7 @@ public MoneyFormatterBuilder append(MoneyPrinter printer, MoneyParser parser) { * In order to use this method, it may be necessary to output an unsigned amount. * This can be achieved using {@link #appendAmount(MoneyAmountStyle)} and * {@link MoneyAmountStyle#withAbsValue(boolean)}. - * + * * @param whenPositiveOrZero the formatter to use when the amount is positive or zero * @param whenNegative the formatter to use when the amount is negative * @return this for chaining, never null @@ -234,7 +234,7 @@ public MoneyFormatterBuilder appendSigned(MoneyFormatter whenPositiveOrZero, Mon * In order to use this method, it may be necessary to output an unsigned amount. * This can be achieved using {@link #appendAmount(MoneyAmountStyle)} and * {@link MoneyAmountStyle#withAbsValue(boolean)}. - * + * * @param whenPositive the formatter to use when the amount is positive * @param whenZero the formatter to use when the amount is zero * @param whenNegative the formatter to use when the amount is negative @@ -244,7 +244,7 @@ public MoneyFormatterBuilder appendSigned(MoneyFormatter whenPositive, MoneyForm MoneyFormatter.checkNotNull(whenPositive, "MoneyFormatter whenPositive must not be null"); MoneyFormatter.checkNotNull(whenZero, "MoneyFormatter whenZero must not be null"); MoneyFormatter.checkNotNull(whenNegative, "MoneyFormatter whenNegative must not be null"); - SignedPrinterParser pp = new SignedPrinterParser(whenPositive, whenZero, whenNegative); + var pp = new SignedPrinterParser(whenPositive, whenZero, whenNegative); return appendInternal(pp, pp); } @@ -253,7 +253,7 @@ public MoneyFormatterBuilder appendSigned(MoneyFormatter whenPositive, MoneyForm * Appends the specified printer and parser to this builder. *

    * Either the printer or parser must be non-null. - * + * * @param printer the printer to append, null makes the formatter unable to print * @param parser the parser to append, null makes the formatter unable to parse * @return this for chaining, never null @@ -274,7 +274,7 @@ private MoneyFormatterBuilder appendInternal(MoneyPrinter printer, MoneyParser p *

    * This method uses the default locale within the returned formatter. * It can be changed by calling {@link MoneyFormatter#withLocale(Locale)}. - * + * * @return the formatter built from this builder, never null */ public MoneyFormatter toFormatter() { @@ -290,15 +290,15 @@ public MoneyFormatter toFormatter() { *

    * This method uses the specified locale within the returned formatter. * It can be changed by calling {@link MoneyFormatter#withLocale(Locale)}. - * + * * @param locale the initial locale for the formatter, not null * @return the formatter built from this builder, never null */ @SuppressWarnings("cast") public MoneyFormatter toFormatter(Locale locale) { MoneyFormatter.checkNotNull(locale, "Locale must not be null"); - MoneyPrinter[] printersCopy = (MoneyPrinter[]) printers.toArray(new MoneyPrinter[printers.size()]); - MoneyParser[] parsersCopy = (MoneyParser[]) parsers.toArray(new MoneyParser[parsers.size()]); + var printersCopy = printers.toArray(new MoneyPrinter[printers.size()]); + var parsersCopy = parsers.toArray(new MoneyParser[parsers.size()]); return new MoneyFormatter(locale, printersCopy, parsersCopy); } @@ -315,11 +315,11 @@ public void print(MoneyPrintContext context, Appendable appendable, BigMoney mon @Override public void parse(MoneyParseContext context) { - int endPos = context.getIndex() + 3; + var endPos = context.getIndex() + 3; if (endPos > context.getTextLength()) { context.setError(); } else { - String code = context.getTextSubstring(context.getIndex(), endPos); + var code = context.getTextSubstring(context.getIndex(), endPos); try { context.setCurrency(CurrencyUnit.of(code)); context.setIndex(endPos); @@ -337,11 +337,11 @@ public void print(MoneyPrintContext context, Appendable appendable, BigMoney mon @Override public void parse(MoneyParseContext context) { - int endPos = context.getIndex() + 3; + var endPos = context.getIndex() + 3; if (endPos > context.getTextLength()) { context.setError(); } else { - String code = context.getTextSubstring(context.getIndex(), endPos); + var code = context.getTextSubstring(context.getIndex(), endPos); try { context.setCurrency(CurrencyUnit.ofNumericCode(code)); context.setIndex(endPos); @@ -359,15 +359,15 @@ public void print(MoneyPrintContext context, Appendable appendable, BigMoney mon @Override public void parse(MoneyParseContext context) { - int count = 0; + var count = 0; for (; count < 3 && context.getIndex() + count < context.getTextLength(); count++) { - char ch = context.getText().charAt(context.getIndex() + count); + var ch = context.getText().charAt(context.getIndex() + count); if (ch < '0' || ch > '9') { break; } } - int endPos = context.getIndex() + count; - String code = context.getTextSubstring(context.getIndex(), endPos); + var endPos = context.getIndex() + count; + var code = context.getTextSubstring(context.getIndex(), endPos); try { context.setCurrency(CurrencyUnit.ofNumericCode(code)); context.setIndex(endPos); diff --git a/src/main/java/org/joda/money/format/MoneyParseContext.java b/src/main/java/org/joda/money/format/MoneyParseContext.java index 6086c61..4873ad3 100644 --- a/src/main/java/org/joda/money/format/MoneyParseContext.java +++ b/src/main/java/org/joda/money/format/MoneyParseContext.java @@ -57,7 +57,7 @@ public final class MoneyParseContext { /** * Constructor. - * + * * @param locale the locale, not null * @param text the text to parse, not null * @param index the current text index @@ -70,7 +70,7 @@ public final class MoneyParseContext { /** * Constructor. - * + * * @param locale the locale, not null * @param text the text to parse, not null * @param index the current text index @@ -90,7 +90,7 @@ public final class MoneyParseContext { //----------------------------------------------------------------------- /** * Gets the locale. - * + * * @return the locale, not null */ public Locale getLocale() { @@ -99,7 +99,7 @@ public Locale getLocale() { /** * Sets the locale. - * + * * @param locale the locale, not null */ public void setLocale(Locale locale) { @@ -109,7 +109,7 @@ public void setLocale(Locale locale) { /** * Gets the text being parsed. - * + * * @return the text being parsed, never null */ public CharSequence getText() { @@ -118,7 +118,7 @@ public CharSequence getText() { /** * Sets the text. - * + * * @param text the text being parsed, not null */ public void setText(CharSequence text) { @@ -128,7 +128,7 @@ public void setText(CharSequence text) { /** * Gets the length of the text being parsed. - * + * * @return the length of the text being parsed */ public int getTextLength() { @@ -137,7 +137,7 @@ public int getTextLength() { /** * Gets a substring of the text being parsed. - * + * * @param start the start index * @param end the end index * @return the substring, not null @@ -149,7 +149,7 @@ public String getTextSubstring(int start, int end) { //----------------------------------------------------------------------- /** * Gets the current parse position index. - * + * * @return the current parse position index */ public int getIndex() { @@ -158,7 +158,7 @@ public int getIndex() { /** * Sets the current parse position index. - * + * * @param index the current parse position index */ public void setIndex(int index) { @@ -168,7 +168,7 @@ public void setIndex(int index) { //----------------------------------------------------------------------- /** * Gets the error index. - * + * * @return the error index, negative if no error */ public int getErrorIndex() { @@ -177,7 +177,7 @@ public int getErrorIndex() { /** * Sets the error index. - * + * * @param index the error index */ public void setErrorIndex(int index) { @@ -194,7 +194,7 @@ public void setError() { //----------------------------------------------------------------------- /** * Gets the parsed currency. - * + * * @return the parsed currency, null if not parsed yet */ public CurrencyUnit getCurrency() { @@ -203,7 +203,7 @@ public CurrencyUnit getCurrency() { /** * Sets the parsed currency. - * + * * @param currency the parsed currency, may be null */ public void setCurrency(CurrencyUnit currency) { @@ -213,7 +213,7 @@ public void setCurrency(CurrencyUnit currency) { //----------------------------------------------------------------------- /** * Gets the parsed amount. - * + * * @return the parsed amount, null if not parsed yet */ public BigDecimal getAmount() { @@ -222,7 +222,7 @@ public BigDecimal getAmount() { /** * Sets the parsed currency. - * + * * @param amount the parsed amount, may be null */ public void setAmount(BigDecimal amount) { @@ -232,7 +232,7 @@ public void setAmount(BigDecimal amount) { //----------------------------------------------------------------------- /** * Checks if the parse has found an error. - * + * * @return whether a parse error has occurred */ public boolean isError() { @@ -241,7 +241,7 @@ public boolean isError() { /** * Checks if the text has been fully parsed such that there is no more text to parse. - * + * * @return true if fully parsed */ public boolean isFullyParsed() { @@ -251,7 +251,7 @@ public boolean isFullyParsed() { /** * Checks if the context contains a currency and amount suitable for creating * a monetary value. - * + * * @return true if able to create a monetary value */ public boolean isComplete() { @@ -261,7 +261,7 @@ public boolean isComplete() { //----------------------------------------------------------------------- /** * Creates a child context. - * + * * @return the child context, never null */ MoneyParseContext createChild() { @@ -270,7 +270,7 @@ MoneyParseContext createChild() { /** * Merges the child context back into this instance. - * + * * @param child the child context, not null */ void mergeChild(MoneyParseContext child) { @@ -285,18 +285,18 @@ void mergeChild(MoneyParseContext child) { //----------------------------------------------------------------------- /** * Converts the indexes to a parse position. - * + * * @return the parse position, never null */ public ParsePosition toParsePosition() { - ParsePosition pp = new ParsePosition(textIndex); + var pp = new ParsePosition(textIndex); pp.setErrorIndex(textErrorIndex); return pp; } /** * Converts the context to a {@code BigMoney}. - * + * * @return the monetary value, never null * @throws MoneyFormatException if either the currency or amount is missing */ diff --git a/src/main/java/org/joda/money/format/MoneyParser.java b/src/main/java/org/joda/money/format/MoneyParser.java index aba5d99..9892be8 100644 --- a/src/main/java/org/joda/money/format/MoneyParser.java +++ b/src/main/java/org/joda/money/format/MoneyParser.java @@ -42,9 +42,9 @@ public interface MoneyParser { * The context is not a thread-safe object and a new instance will be created * for each parse. The context must not be stored in an instance variable * or shared with any other threads. - * + * * @param context the context to use and parse into, not null */ - void parse(MoneyParseContext context); + public abstract void parse(MoneyParseContext context); } diff --git a/src/main/java/org/joda/money/format/MoneyPrintContext.java b/src/main/java/org/joda/money/format/MoneyPrintContext.java index fcacf69..10dc14d 100644 --- a/src/main/java/org/joda/money/format/MoneyPrintContext.java +++ b/src/main/java/org/joda/money/format/MoneyPrintContext.java @@ -32,7 +32,7 @@ public final class MoneyPrintContext { /** * Constructor. - * + * * @param locale the locale, not null */ MoneyPrintContext(Locale locale) { @@ -43,7 +43,7 @@ public final class MoneyPrintContext { //----------------------------------------------------------------------- /** * Gets the locale. - * + * * @return the locale, never null */ public Locale getLocale() { @@ -52,7 +52,7 @@ public Locale getLocale() { /** * Sets the locale. - * + * * @param locale the locale, not null */ public void setLocale(Locale locale) { diff --git a/src/main/java/org/joda/money/format/MoneyPrinter.java b/src/main/java/org/joda/money/format/MoneyPrinter.java index 29a3000..9c14c97 100644 --- a/src/main/java/org/joda/money/format/MoneyPrinter.java +++ b/src/main/java/org/joda/money/format/MoneyPrinter.java @@ -41,13 +41,13 @@ public interface MoneyPrinter { * The context is not a thread-safe object and a new instance will be created * for each print. The context must not be stored in an instance variable * or shared with any other threads. - * + * * @param context the context being used, not null * @param appendable the appendable to add to, not null * @param money the money to print, not null * @throws MoneyFormatException if there is a problem while printing * @throws IOException if an IO exception occurs */ - void print(MoneyPrintContext context, Appendable appendable, BigMoney money) throws IOException; + public abstract void print(MoneyPrintContext context, Appendable appendable, BigMoney money) throws IOException; } diff --git a/src/main/java/org/joda/money/format/MultiPrinterParser.java b/src/main/java/org/joda/money/format/MultiPrinterParser.java index 98ac280..1ec6467 100644 --- a/src/main/java/org/joda/money/format/MultiPrinterParser.java +++ b/src/main/java/org/joda/money/format/MultiPrinterParser.java @@ -51,15 +51,15 @@ final class MultiPrinterParser implements MoneyPrinter, MoneyParser, Serializabl //----------------------------------------------------------------------- boolean isPrinter() { - return Arrays.asList(printers).contains(null) == false; + return !Arrays.asList(printers).contains(null); } boolean isParser() { - return Arrays.asList(parsers).contains(null) == false; + return !Arrays.asList(parsers).contains(null); } void appendTo(MoneyFormatterBuilder builder) { - for (int i = 0; i < printers.length; i++) { + for (var i = 0; i < printers.length; i++) { builder.append(printers[i], parsers[i]); } } @@ -84,23 +84,23 @@ public void parse(MoneyParseContext context) { @Override public String toString() { - StringBuilder buf1 = new StringBuilder(); + var buf1 = new StringBuilder(); if (isPrinter()) { for (MoneyPrinter printer : printers) { buf1.append(printer.toString()); } } - StringBuilder buf2 = new StringBuilder(); + var buf2 = new StringBuilder(); if (isParser()) { for (MoneyParser parser : parsers) { buf2.append(parser.toString()); } } - String str1 = buf1.toString(); - String str2 = buf2.toString(); - if (isPrinter() && isParser() == false) { + var str1 = buf1.toString(); + var str2 = buf2.toString(); + if (isPrinter() && !isParser()) { return str1; - } else if (isParser() && isPrinter() == false) { + } else if (isParser() && !isPrinter()) { return str2; } else if (str1.equals(str2)) { return str1; diff --git a/src/main/java/org/joda/money/format/SignedPrinterParser.java b/src/main/java/org/joda/money/format/SignedPrinterParser.java index 991fc07..784a4ea 100644 --- a/src/main/java/org/joda/money/format/SignedPrinterParser.java +++ b/src/main/java/org/joda/money/format/SignedPrinterParser.java @@ -53,19 +53,19 @@ final class SignedPrinterParser implements MoneyPrinter, MoneyParser, Serializab //----------------------------------------------------------------------- @Override public void print(MoneyPrintContext context, Appendable appendable, BigMoney money) throws IOException { - MoneyFormatter fmt = (money.isZero() ? whenZero : money.isPositive() ? whenPositive : whenNegative); + var fmt = (money.isZero() ? whenZero : money.isPositive() ? whenPositive : whenNegative); fmt.getPrinterParser().print(context, appendable, money); } @Override public void parse(MoneyParseContext context) { - MoneyParseContext positiveContext = context.createChild(); + var positiveContext = context.createChild(); whenPositive.getPrinterParser().parse(positiveContext); - MoneyParseContext zeroContext = context.createChild(); + var zeroContext = context.createChild(); whenZero.getPrinterParser().parse(zeroContext); - MoneyParseContext negativeContext = context.createChild(); + var negativeContext = context.createChild(); whenNegative.getPrinterParser().parse(negativeContext); - MoneyParseContext best = null; + var best = (MoneyParseContext) null; if (!positiveContext.isError()) { best = positiveContext; } diff --git a/src/test/java/org/joda/money/TestBigMoney.java b/src/test/java/org/joda/money/TestBigMoney.java index 4a89899..14b0b20 100644 --- a/src/test/java/org/joda/money/TestBigMoney.java +++ b/src/test/java/org/joda/money/TestBigMoney.java @@ -25,7 +25,6 @@ import java.io.InvalidObjectException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; -import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Modifier; import java.math.BigDecimal; @@ -76,12 +75,7 @@ class TestBigMoney { private static final BigMoney USD_1_23 = BigMoney.parse("USD 1.23"); private static final BigMoney USD_2_34 = BigMoney.parse("USD 2.34"); private static final BigMoney USD_2_35 = BigMoney.parse("USD 2.35"); - private static final BigMoneyProvider BAD_PROVIDER = new BigMoneyProvider() { - @Override - public BigMoney toBigMoney() { - return null; // shouldn't return null - } - }; + private static final BigMoneyProvider BAD_PROVIDER = () -> null; private static BigDecimal bd(String str) { return new BigDecimal(str); @@ -92,7 +86,7 @@ private static BigDecimal bd(String str) { //----------------------------------------------------------------------- @Test void test_factory_of_Currency_BigDecimal() { - BigMoney test = BigMoney.of(GBP, BIGDEC_2_345); + var test = BigMoney.of(GBP, BIGDEC_2_345); assertThat(test.getCurrencyUnit()).isEqualTo(GBP); assertThat(test.getAmount()).isEqualTo(BIGDEC_2_345); assertThat(test.getScale()).isEqualTo(3); @@ -100,13 +94,13 @@ void test_factory_of_Currency_BigDecimal() { @Test void test_factory_of_Currency_BigDecimal_nullCurrency() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> BigMoney.of((CurrencyUnit) null, BIGDEC_2_345)); } @Test void test_factory_of_Currency_BigDecimal_nullBigDecimal() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> BigMoney.of(GBP, (BigDecimal) null)); } @@ -130,7 +124,7 @@ public int scale() { } } BigDecimal sub = new BadDecimal(); - assertThatExceptionOfType(IllegalArgumentException.class) + assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> BigMoney.of(GBP, sub)); } @@ -161,7 +155,7 @@ public int scale() { } } BigDecimal sub = new BadDecimal(); - BigMoney test = BigMoney.of(GBP, sub); + var test = BigMoney.of(GBP, sub); assertThat(test.getCurrencyUnit()).isEqualTo(GBP); assertThat(test.getAmount()).isEqualTo(bd("12.3")); assertThat(test.getScale()).isEqualTo(1); @@ -173,7 +167,7 @@ public int scale() { //----------------------------------------------------------------------- @Test void test_factory_of_Currency_double() { - BigMoney test = BigMoney.of(GBP, 2.345d); + var test = BigMoney.of(GBP, 2.345d); assertThat(test.getCurrencyUnit()).isEqualTo(GBP); assertThat(test.getAmount()).isEqualTo(BIGDEC_2_345); assertThat(test.getScale()).isEqualTo(3); @@ -181,7 +175,7 @@ void test_factory_of_Currency_double() { @Test void test_factory_of_Currency_double_trailingZero1() { - BigMoney test = BigMoney.of(GBP, 1.230d); + var test = BigMoney.of(GBP, 1.230d); assertThat(test.getCurrencyUnit()).isEqualTo(GBP); assertThat(test.getAmount()).isEqualTo(BigDecimal.valueOf(123L, 2)); assertThat(test.getScale()).isEqualTo(2); @@ -189,7 +183,7 @@ void test_factory_of_Currency_double_trailingZero1() { @Test void test_factory_of_Currency_double_trailingZero2() { - BigMoney test = BigMoney.of(GBP, 1.20d); + var test = BigMoney.of(GBP, 1.20d); assertThat(test.getCurrencyUnit()).isEqualTo(GBP); assertThat(test.getAmount()).isEqualTo(BigDecimal.valueOf(12L, 1)); assertThat(test.getScale()).isEqualTo(1); @@ -206,7 +200,7 @@ void test_factory_of_Currency_double_zero() { @Test void test_factory_of_Currency_double_medium() { - BigMoney test = BigMoney.of(GBP, 2000d); + var test = BigMoney.of(GBP, 2000d); assertThat(test.getCurrencyUnit()).isEqualTo(GBP); assertThat(test.getAmount()).isEqualTo(BigDecimal.valueOf(2000L, 0)); assertThat(test.getScale()).isEqualTo(0); @@ -214,7 +208,7 @@ void test_factory_of_Currency_double_medium() { @Test void test_factory_of_Currency_double_big() { - BigMoney test = BigMoney.of(GBP, 200000000d); + var test = BigMoney.of(GBP, 200000000d); assertThat(test.getCurrencyUnit()).isEqualTo(GBP); assertThat(test.getAmount()).isEqualTo(BigDecimal.valueOf(200000000L, 0)); assertThat(test.getScale()).isEqualTo(0); @@ -222,7 +216,7 @@ void test_factory_of_Currency_double_big() { @Test void test_factory_of_Currency_double_nullCurrency() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> BigMoney.of((CurrencyUnit) null, 2.345d)); } @@ -231,33 +225,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); + var test = BigMoney.ofScale(GBP, BIGDEC_2_34, 4); 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); + var test = BigMoney.ofScale(GBP, BigDecimal.valueOf(23400), -2); assertThat(test.getCurrencyUnit()).isEqualTo(GBP); assertThat(test.getAmount()).isEqualTo(BigDecimal.valueOf(23400L, 0)); } @Test void test_factory_ofScale_Currency_BigDecimal_invalidScale() { - assertThatExceptionOfType(ArithmeticException.class) + assertThatExceptionOfType(ArithmeticException.class) .isThrownBy(() -> BigMoney.ofScale(GBP, BIGDEC_2_345, 2)); } @Test void test_factory_ofScale_Currency_BigDecimal_nullCurrency() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> BigMoney.ofScale((CurrencyUnit) null, BIGDEC_2_34, 2)); } @Test void test_factory_ofScale_Currency_BigDecimal_nullBigDecimal() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> BigMoney.ofScale(GBP, (BigDecimal) null, 2)); } @@ -266,46 +260,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); + var test = BigMoney.ofScale(GBP, BIGDEC_2_34, 1, RoundingMode.DOWN); 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); + var test = BigMoney.ofScale(JPY, BIGDEC_2_34, 0, RoundingMode.UP); 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); + var test = BigMoney.ofScale(GBP, BigDecimal.valueOf(23400), -2, RoundingMode.DOWN); assertThat(test.getCurrencyUnit()).isEqualTo(GBP); assertThat(test.getAmount()).isEqualTo(BigDecimal.valueOf(23400L, 0)); } @Test void test_factory_ofScale_Currency_BigDecimal_int_RoundingMode_UNNECESSARY() { - assertThatExceptionOfType(ArithmeticException.class) + assertThatExceptionOfType(ArithmeticException.class) .isThrownBy(() -> BigMoney.ofScale(JPY, BIGDEC_2_34, 1, RoundingMode.UNNECESSARY)); } @Test void test_factory_ofScale_Currency_BigDecimal_int_RoundingMode_nullCurrency() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> BigMoney.ofScale((CurrencyUnit) null, BIGDEC_2_34, 2, RoundingMode.DOWN)); } @Test void test_factory_ofScale_Currency_BigDecimal_int_RoundingMode_nullBigDecimal() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> BigMoney.ofScale(GBP, (BigDecimal) null, 2, RoundingMode.DOWN)); } @Test void test_factory_ofScale_Currency_BigDecimal_int_RoundingMode_nullRoundingMode() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> BigMoney.ofScale(GBP, BIGDEC_2_34, 2, (RoundingMode) null)); } @@ -314,21 +308,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); + var test = BigMoney.ofScale(GBP, 234, 4); 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); + var test = BigMoney.ofScale(GBP, 234, -4); assertThat(test.getCurrencyUnit()).isEqualTo(GBP); assertThat(test.getAmount()).isEqualTo(BigDecimal.valueOf(2340000, 0)); } @Test void test_factory_ofScale_Currency_long_int_nullCurrency() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> BigMoney.ofScale((CurrencyUnit) null, 234, 2)); } @@ -337,7 +331,7 @@ void test_factory_ofScale_Currency_long_int_nullCurrency() { //----------------------------------------------------------------------- @Test void test_factory_ofMajor_Currency_long() { - BigMoney test = BigMoney.ofMajor(GBP, 234); + var test = BigMoney.ofMajor(GBP, 234); assertThat(test.getCurrencyUnit()).isEqualTo(GBP); assertThat(test.getAmount()).isEqualTo(bd("234")); assertThat(test.getScale()).isEqualTo(0); @@ -345,7 +339,7 @@ void test_factory_ofMajor_Currency_long() { @Test void test_factory_ofMajor_Currency_long_nullCurrency() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> BigMoney.ofMajor((CurrencyUnit) null, 234)); } @@ -354,7 +348,7 @@ void test_factory_ofMajor_Currency_long_nullCurrency() { //----------------------------------------------------------------------- @Test void test_factory_ofMinor_Currency_long() { - BigMoney test = BigMoney.ofMinor(GBP, 234); + var test = BigMoney.ofMinor(GBP, 234); assertThat(test.getCurrencyUnit()).isEqualTo(GBP); assertThat(test.getAmount()).isEqualTo(bd("2.34")); assertThat(test.getScale()).isEqualTo(2); @@ -362,7 +356,7 @@ void test_factory_ofMinor_Currency_long() { @Test void test_factory_ofMinor_Currency_long_nullCurrency() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> BigMoney.ofMinor((CurrencyUnit) null, 234)); } @@ -371,7 +365,7 @@ void test_factory_ofMinor_Currency_long_nullCurrency() { //----------------------------------------------------------------------- @Test void test_factory_zero_Currency() { - BigMoney test = BigMoney.zero(GBP); + var test = BigMoney.zero(GBP); assertThat(test.getCurrencyUnit()).isEqualTo(GBP); assertThat(test.getAmount()).isEqualTo(BigDecimal.ZERO); assertThat(test.getScale()).isEqualTo(0); @@ -379,7 +373,7 @@ void test_factory_zero_Currency() { @Test void test_factory_zero_Currency_nullCurrency() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> BigMoney.zero((CurrencyUnit) null)); } @@ -388,21 +382,21 @@ void test_factory_zero_Currency_nullCurrency() { //----------------------------------------------------------------------- @Test void test_factory_zero_Currency_int() { - BigMoney test = BigMoney.zero(GBP, 3); + var test = BigMoney.zero(GBP, 3); 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); + var test = BigMoney.zero(GBP, -3); assertThat(test.getCurrencyUnit()).isEqualTo(GBP); assertThat(test.getAmount()).isEqualTo(BigDecimal.valueOf(0, 0)); } @Test void test_factory_zero_Currency_int_nullCurrency() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> BigMoney.zero((CurrencyUnit) null, 3)); } @@ -411,7 +405,7 @@ void test_factory_zero_Currency_int_nullCurrency() { //----------------------------------------------------------------------- @Test void test_factory_from_BigMoneyProvider() { - BigMoney test = BigMoney.of(BigMoney.parse("GBP 104.23")); + var test = BigMoney.of(BigMoney.parse("GBP 104.23")); assertThat(test.getCurrencyUnit()).isEqualTo(GBP); assertThat(test.getAmountMinorInt()).isEqualTo(10423); assertThat(test.getScale()).isEqualTo(2); @@ -419,13 +413,13 @@ void test_factory_from_BigMoneyProvider() { @Test void test_factory_from_BigMoneyProvider_nullBigMoneyProvider() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> BigMoney.of((BigMoneyProvider) null)); } @Test void test_factory_from_BigMoneyProvider_badProvider() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> BigMoney.of(BAD_PROVIDER)); } @@ -434,104 +428,104 @@ void test_factory_from_BigMoneyProvider_badProvider() { //----------------------------------------------------------------------- @Test void test_factory_total_varargs_1BigMoney() { - BigMoney test = BigMoney.total(GBP_1_23); + var test = BigMoney.total(GBP_1_23); 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); + var array = new BigMoneyProvider[] {GBP_1_23}; + var test = BigMoney.total(array); 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); + var test = BigMoney.total(GBP_1_23, GBP_2_33.toMoney(), GBP_2_36); 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); + var array = new BigMoneyProvider[] {GBP_1_23, GBP_2_33.toMoney(), GBP_2_36}; + var test = BigMoney.total(array); 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); + var array = new Money[] {GBP_1_23.toMoney(), GBP_2_33.toMoney(), GBP_2_36.toMoney()}; + var test = BigMoney.total(array); assertThat(test.getCurrencyUnit()).isEqualTo(GBP); assertThat(test.getAmountMinorInt()).isEqualTo(592); } @Test void test_factory_total_varargs_empty() { - assertThatExceptionOfType(IllegalArgumentException.class) + assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> BigMoney.total()); } @Test void test_factory_total_array_empty() { - BigMoneyProvider[] array = new BigMoneyProvider[0]; - assertThatExceptionOfType(IllegalArgumentException.class) + var array = new BigMoneyProvider[0]; + assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> BigMoney.total(array)); } @Test void test_factory_total_varargs_currenciesDiffer() { - assertThatExceptionOfType(CurrencyMismatchException.class) + 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}; - assertThatExceptionOfType(CurrencyMismatchException.class) + var array = new BigMoneyProvider[] {GBP_2_33, JPY_423}; + assertThatExceptionOfType(CurrencyMismatchException.class) .isThrownBy(() -> BigMoney.total(array)); } @Test void test_factory_total_varargs_nullFirst() { - assertThatExceptionOfType(NullPointerException.class) + 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}; - assertThatExceptionOfType(NullPointerException.class) + var array = new BigMoneyProvider[] {null, GBP_2_33, GBP_2_36}; + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> BigMoney.total(array)); } @Test void test_factory_total_varargs_nullNotFirst() { - assertThatExceptionOfType(NullPointerException.class) + 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}; - assertThatExceptionOfType(NullPointerException.class) + var array = new BigMoneyProvider[] {GBP_2_33, null, GBP_2_36}; + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> BigMoney.total(array)); } @Test void test_factory_total_varargs_badProvider() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> BigMoney.total(BAD_PROVIDER)); } @Test void test_factory_total_array_badProvider() { - BigMoneyProvider[] array = new BigMoneyProvider[] {BAD_PROVIDER}; - assertThatExceptionOfType(NullPointerException.class) + var array = new BigMoneyProvider[] {BAD_PROVIDER}; + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> BigMoney.total(array)); } @@ -541,7 +535,7 @@ void test_factory_total_array_badProvider() { @Test 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); + var test = BigMoney.total(iterable); assertThat(test.getCurrencyUnit()).isEqualTo(GBP); assertThat(test.getAmount()).isEqualTo(BigDecimal.valueOf(5921, 3)); } @@ -549,7 +543,7 @@ void test_factory_total_Iterable() { @Test void test_factory_total_Iterable_Mixed() { Iterable iterable = Arrays.asList(GBP_1_23.toMoney(), GBP_2_33); - BigMoney test = BigMoney.total(iterable); + var test = BigMoney.total(iterable); assertThat(test.getCurrencyUnit()).isEqualTo(GBP); assertThat(test.getAmount()).isEqualTo(BigDecimal.valueOf(356, 2)); } @@ -557,35 +551,35 @@ void test_factory_total_Iterable_Mixed() { @Test void test_factory_total_Iterable_empty() { Iterable iterable = Collections.emptyList(); - assertThatExceptionOfType(IllegalArgumentException.class) + assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> BigMoney.total(iterable)); } @Test void test_factory_total_Iterable_currenciesDiffer() { Iterable iterable = Arrays.asList(GBP_2_33, JPY_423); - assertThatExceptionOfType(CurrencyMismatchException.class) + 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); - assertThatExceptionOfType(NullPointerException.class) + 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); - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> BigMoney.total(iterable)); } @Test void test_factory_total_Iterable_badProvider() { Iterable iterable = Arrays.asList(BAD_PROVIDER); - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> BigMoney.total(iterable)); } @@ -594,134 +588,134 @@ void test_factory_total_Iterable_badProvider() { //----------------------------------------------------------------------- @Test void test_factory_total_CurrencyUnitVarargs_1() { - BigMoney test = BigMoney.total(GBP, GBP_1_23); + var test = BigMoney.total(GBP, GBP_1_23); 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); + var array = new BigMoney[] {GBP_1_23}; + var test = BigMoney.total(GBP, array); 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); + var test = BigMoney.total(GBP, GBP_1_23, GBP_2_33, GBP_2_36); 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); + var array = new BigMoney[] {GBP_1_23, GBP_2_33, GBP_2_36}; + var test = BigMoney.total(GBP, array); 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); + var test = BigMoney.total(GBP, GBP_1_23, GBP_2_33.toMoney(), GBP_2_36); 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); + var array = new BigMoneyProvider[] {GBP_1_23, GBP_2_33.toMoney(), GBP_2_36}; + var test = BigMoney.total(GBP, array); 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); + var array = new Money[] {GBP_1_23.toMoney(), GBP_2_33.toMoney(), GBP_2_36.toMoney()}; + var test = BigMoney.total(GBP, array); assertThat(test.getCurrencyUnit()).isEqualTo(GBP); assertThat(test.getAmountMinorInt()).isEqualTo(592); } @Test void test_factory_total_CurrencyUnitVarargs_empty() { - BigMoney test = BigMoney.total(GBP); + var test = BigMoney.total(GBP); 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); + var array = new BigMoney[0]; + var test = BigMoney.total(GBP, array); assertThat(test.getCurrencyUnit()).isEqualTo(GBP); assertThat(test.getAmountMinorInt()).isEqualTo(0); } @Test void test_factory_total_CurrencyUnitVarargs_currenciesDiffer() { - assertThatExceptionOfType(CurrencyMismatchException.class) + assertThatExceptionOfType(CurrencyMismatchException.class) .isThrownBy(() -> BigMoney.total(GBP, JPY_423)); } @Test void test_factory_total_CurrencyUnitArray_currenciesDiffer() { - BigMoney[] array = new BigMoney[] {JPY_423}; - assertThatExceptionOfType(CurrencyMismatchException.class) + var array = new BigMoney[] {JPY_423}; + assertThatExceptionOfType(CurrencyMismatchException.class) .isThrownBy(() -> BigMoney.total(GBP, array)); } @Test void test_factory_total_CurrencyUnitVarargs_currenciesDifferInArray() { - assertThatExceptionOfType(CurrencyMismatchException.class) + 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}; - assertThatExceptionOfType(CurrencyMismatchException.class) + var array = new BigMoney[] {GBP_2_33, JPY_423}; + assertThatExceptionOfType(CurrencyMismatchException.class) .isThrownBy(() -> BigMoney.total(GBP, array)); } @Test void test_factory_total_CurrencyUnitVarargs_nullFirst() { - assertThatExceptionOfType(NullPointerException.class) + 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}; - assertThatExceptionOfType(NullPointerException.class) + var array = new BigMoney[] {null, GBP_2_33, GBP_2_36}; + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> BigMoney.total(GBP, array)); } @Test void test_factory_total_CurrencyUnitVarargs_nullNotFirst() { - assertThatExceptionOfType(NullPointerException.class) + 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}; - assertThatExceptionOfType(NullPointerException.class) + var array = new BigMoney[] {GBP_2_33, null, GBP_2_36}; + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> BigMoney.total(GBP, array)); } @Test void test_factory_total_CurrencyUnitVarargs_badProvider() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> BigMoney.total(GBP, BAD_PROVIDER)); } @Test void test_factory_total_CurrencyUnitArray_badProvider() { - BigMoneyProvider[] array = new BigMoneyProvider[] {BAD_PROVIDER}; - assertThatExceptionOfType(NullPointerException.class) + var array = new BigMoneyProvider[] {BAD_PROVIDER}; + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> BigMoney.total(GBP, array)); } @@ -731,7 +725,7 @@ void test_factory_total_CurrencyUnitArray_badProvider() { @Test 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); + var test = BigMoney.total(GBP, iterable); assertThat(test.getCurrencyUnit()).isEqualTo(GBP); assertThat(test.getAmount()).isEqualTo(BigDecimal.valueOf(5921, 3)); } @@ -739,7 +733,7 @@ void test_factory_total_CurrencyUnitIterable() { @Test void test_factory_total_CurrencyUnitIterable_Mixed() { Iterable iterable = Arrays.asList(GBP_1_23.toMoney(), GBP_2_33); - BigMoney test = BigMoney.total(GBP, iterable); + var test = BigMoney.total(GBP, iterable); assertThat(test.getCurrencyUnit()).isEqualTo(GBP); assertThat(test.getAmount()).isEqualTo(BigDecimal.valueOf(356, 2)); } @@ -747,7 +741,7 @@ void test_factory_total_CurrencyUnitIterable_Mixed() { @Test void test_factory_total_CurrencyUnitIterable_empty() { Iterable iterable = Collections.emptyList(); - BigMoney test = BigMoney.total(GBP, iterable); + var test = BigMoney.total(GBP, iterable); assertThat(test.getCurrencyUnit()).isEqualTo(GBP); assertThat(test.getAmountMinorInt()).isEqualTo(0); } @@ -755,35 +749,35 @@ void test_factory_total_CurrencyUnitIterable_empty() { @Test void test_factory_total_CurrencyUnitIterable_currenciesDiffer() { Iterable iterable = Arrays.asList(JPY_423); - assertThatExceptionOfType(CurrencyMismatchException.class) + assertThatExceptionOfType(CurrencyMismatchException.class) .isThrownBy(() -> BigMoney.total(GBP, iterable)); } @Test void test_factory_total_CurrencyUnitIterable_currenciesDifferInIterable() { Iterable iterable = Arrays.asList(GBP_2_33, JPY_423); - assertThatExceptionOfType(CurrencyMismatchException.class) + 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); - assertThatExceptionOfType(NullPointerException.class) + 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); - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> BigMoney.total(GBP, iterable)); } @Test void test_factory_total_CurrencyUnitIterable_badProvider() { Iterable iterable = Arrays.asList(BAD_PROVIDER); - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> BigMoney.total(GBP, iterable)); } @@ -816,7 +810,7 @@ public static Object[][] data_parse() { @ParameterizedTest @MethodSource("data_parse") void test_factory_parse(String str, CurrencyUnit currency, String amountStr, int scale) { - BigMoney test = BigMoney.parse(str); + var test = BigMoney.parse(str); assertThat(test.getCurrencyUnit()).isEqualTo(currency); assertThat(test.getAmount()).isEqualTo(bd(amountStr)); assertThat(test.getScale()).isEqualTo(scale); @@ -824,25 +818,25 @@ void test_factory_parse(String str, CurrencyUnit currency, String amountStr, int @Test void test_factory_parse_String_tooShort() { - assertThatExceptionOfType(IllegalArgumentException.class) + assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> BigMoney.parse("GBP")); } @Test void test_factory_parse_String_exponent() { - assertThatExceptionOfType(IllegalArgumentException.class) + assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> BigMoney.parse("GBP 234E2")); } @Test void test_factory_parse_String_badCurrency() { - assertThatExceptionOfType(IllegalArgumentException.class) + assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> BigMoney.parse("GBX 2.34")); } @Test void test_factory_parse_String_nullString() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> BigMoney.parse((String) null)); } @@ -851,7 +845,7 @@ void test_factory_parse_String_nullString() { //----------------------------------------------------------------------- @Test void test_constructor_null1() throws Exception { - Constructor con = BigMoney.class.getDeclaredConstructor(CurrencyUnit.class, BigDecimal.class); + var con = BigMoney.class.getDeclaredConstructor(CurrencyUnit.class, BigDecimal.class); assertThat(Modifier.isPublic(con.getModifiers())).isFalse(); assertThat(Modifier.isProtected(con.getModifiers())).isFalse(); try { @@ -865,7 +859,7 @@ void test_constructor_null1() throws Exception { @Test void test_constructor_null2() throws Exception { - Constructor con = BigMoney.class.getDeclaredConstructor(CurrencyUnit.class, BigDecimal.class); + var con = BigMoney.class.getDeclaredConstructor(CurrencyUnit.class, BigDecimal.class); try { con.setAccessible(true); con.newInstance(new Object[] {GBP, null}); @@ -878,8 +872,8 @@ void test_constructor_null2() throws Exception { //----------------------------------------------------------------------- @Test void test_scaleNormalization1() { - BigMoney a = BigMoney.ofScale(GBP, 100, 0); - BigMoney b = BigMoney.ofScale(GBP, 1, -2); + var a = BigMoney.ofScale(GBP, 100, 0); + var b = BigMoney.ofScale(GBP, 1, -2); assertThat(a.toString()).isEqualTo("GBP 100"); assertThat(b.toString()).isEqualTo("GBP 100"); assertThat(a).isEqualTo(a); @@ -891,8 +885,8 @@ void test_scaleNormalization1() { @Test void test_scaleNormalization2() { - BigMoney a = BigMoney.ofScale(GBP, 1, 1); - BigMoney b = BigMoney.ofScale(GBP, 10, 2); + var a = BigMoney.ofScale(GBP, 1, 1); + var b = BigMoney.ofScale(GBP, 10, 2); assertThat(a.toString()).isEqualTo("GBP 0.1"); assertThat(b.toString()).isEqualTo("GBP 0.10"); assertThat(a).isEqualTo(a); @@ -904,8 +898,8 @@ void test_scaleNormalization2() { @Test void test_scaleNormalization3() { - BigMoney a = BigMoney.of(GBP, new BigDecimal("100")); - BigMoney b = BigMoney.of(GBP, new BigDecimal("1E+2")); + var a = BigMoney.of(GBP, new BigDecimal("100")); + var b = BigMoney.of(GBP, new BigDecimal("1E+2")); assertThat(a.toString()).isEqualTo("GBP 100"); assertThat(b.toString()).isEqualTo("GBP 100"); assertThat(a).isEqualTo(a); @@ -920,41 +914,41 @@ void test_scaleNormalization3() { //----------------------------------------------------------------------- @Test void test_serialization() throws Exception { - BigMoney a = BigMoney.parse("GBP 2.34"); - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - try (ObjectOutputStream oos = new ObjectOutputStream(baos)) { + var a = BigMoney.parse("GBP 2.34"); + var baos = new ByteArrayOutputStream(); + try (var oos = new ObjectOutputStream(baos)) { oos.writeObject(a); oos.close(); - ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); - BigMoney input = (BigMoney) ois.readObject(); + var ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); + var input = (BigMoney) ois.readObject(); assertThat(input).isEqualTo(a); } } @Test void test_serialization_invalidNumericCode() throws IOException { - CurrencyUnit cu = new CurrencyUnit("GBP", (short) 234, (short) 2); - BigMoney m = BigMoney.of(cu, 123.43d); - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - try (ObjectOutputStream oos = new ObjectOutputStream(baos)) { + var cu = new CurrencyUnit("GBP", (short) 234, (short) 2); + var m = BigMoney.of(cu, 123.43d); + var baos = new ByteArrayOutputStream(); + try (var oos = new ObjectOutputStream(baos)) { oos.writeObject(m); oos.close(); - ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); - assertThatExceptionOfType(InvalidObjectException.class) + var ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); + assertThatExceptionOfType(InvalidObjectException.class) .isThrownBy(() -> ois.readObject()); } } @Test void test_serialization_invalidDecimalPlaces() throws IOException { - CurrencyUnit cu = new CurrencyUnit("GBP", (short) 826, (short) 1); - BigMoney m = BigMoney.of(cu, 123.43d); - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - try (ObjectOutputStream oos = new ObjectOutputStream(baos)) { + var cu = new CurrencyUnit("GBP", (short) 826, (short) 1); + var m = BigMoney.of(cu, 123.43d); + var baos = new ByteArrayOutputStream(); + try (var oos = new ObjectOutputStream(baos)) { oos.writeObject(m); oos.close(); - ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); - assertThatExceptionOfType(InvalidObjectException.class) + var ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); + assertThatExceptionOfType(InvalidObjectException.class) .isThrownBy(() -> ois.readObject()); } } @@ -977,25 +971,25 @@ void test_getCurrencyUnit_EUR() { //----------------------------------------------------------------------- @Test void test_withCurrencyUnit_Currency() { - BigMoney test = GBP_2_34.withCurrencyUnit(USD); + var test = GBP_2_34.withCurrencyUnit(USD); assertThat(test).hasToString("USD 2.34"); } @Test void test_withCurrencyUnit_Currency_same() { - BigMoney test = GBP_2_34.withCurrencyUnit(GBP); + var test = GBP_2_34.withCurrencyUnit(GBP); assertThat(test).isSameAs(GBP_2_34); } @Test void test_withCurrencyUnit_Currency_differentCurrencyScale() { - BigMoney test = GBP_2_34.withCurrencyUnit(JPY); + var test = GBP_2_34.withCurrencyUnit(JPY); assertThat(test).hasToString("JPY 2.34"); } @Test void test_withCurrencyUnit_Currency_nullCurrency() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> GBP_2_34.withCurrencyUnit((CurrencyUnit) null)); } @@ -1036,20 +1030,20 @@ void test_isCurrencyScale_JPY() { //----------------------------------------------------------------------- @Test void test_withScale_int_same() { - BigMoney test = GBP_2_34.withScale(2); + var test = GBP_2_34.withScale(2); assertThat(test).isSameAs(GBP_2_34); } @Test void test_withScale_int_more() { - BigMoney test = GBP_2_34.withScale(3); + var test = GBP_2_34.withScale(3); assertThat(test.getAmount()).isEqualTo(bd("2.340")); assertThat(test.getScale()).isEqualTo(3); } @Test void test_withScale_int_less() { - assertThatExceptionOfType(ArithmeticException.class) + assertThatExceptionOfType(ArithmeticException.class) .isThrownBy(() -> BigMoney.parse("GBP 2.345").withScale(2)); } @@ -1058,14 +1052,14 @@ void test_withScale_int_less() { //----------------------------------------------------------------------- @Test void test_withScale_intRoundingMode_less() { - BigMoney test = GBP_2_34.withScale(1, RoundingMode.UP); + var test = GBP_2_34.withScale(1, RoundingMode.UP); 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); + var test = GBP_2_34.withScale(3, RoundingMode.UP); assertThat(test.getAmount()).isEqualTo(bd("2.340")); assertThat(test.getScale()).isEqualTo(3); } @@ -1075,20 +1069,20 @@ void test_withScale_intRoundingMode_more() { //----------------------------------------------------------------------- @Test void test_withCurrencyScale_int_same() { - BigMoney test = GBP_2_34.withCurrencyScale(); + var test = GBP_2_34.withCurrencyScale(); assertThat(test).isSameAs(GBP_2_34); } @Test void test_withCurrencyScale_int_more() { - BigMoney test = BigMoney.parse("GBP 2.3").withCurrencyScale(); + var test = BigMoney.parse("GBP 2.3").withCurrencyScale(); assertThat(test.getAmount()).isEqualTo(bd("2.30")); assertThat(test.getScale()).isEqualTo(2); } @Test void test_withCurrencyScale_int_less() { - assertThatExceptionOfType(ArithmeticException.class) + assertThatExceptionOfType(ArithmeticException.class) .isThrownBy(() -> BigMoney.parse("GBP 2.345").withCurrencyScale()); } @@ -1097,21 +1091,21 @@ void test_withCurrencyScale_int_less() { //----------------------------------------------------------------------- @Test void test_withCurrencyScale_intRoundingMode_less() { - BigMoney test = BigMoney.parse("GBP 2.345").withCurrencyScale(RoundingMode.UP); + var test = BigMoney.parse("GBP 2.345").withCurrencyScale(RoundingMode.UP); 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); + var test = BigMoney.parse("GBP 2.3").withCurrencyScale(RoundingMode.UP); 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); + var test = BigMoney.parse("JPY 2.345").withCurrencyScale(RoundingMode.UP); assertThat(test.getAmount()).isEqualTo(bd("3")); assertThat(test.getScale()).isEqualTo(0); } @@ -1157,13 +1151,13 @@ void test_getAmountMajorLong_negative() { @Test void test_getAmountMajorLong_tooBigPositive() { - assertThatExceptionOfType(ArithmeticException.class) + assertThatExceptionOfType(ArithmeticException.class) .isThrownBy(() -> GBP_LONG_MAX_MAJOR_PLUS1.getAmountMajorLong()); } @Test void test_getAmountMajorLong_tooBigNegative() { - assertThatExceptionOfType(ArithmeticException.class) + assertThatExceptionOfType(ArithmeticException.class) .isThrownBy(() -> GBP_LONG_MIN_MAJOR_MINUS1.getAmountMajorLong()); } @@ -1182,13 +1176,13 @@ void test_getAmountMajorInt_negative() { @Test void test_getAmountMajorInt_tooBigPositive() { - assertThatExceptionOfType(ArithmeticException.class) + assertThatExceptionOfType(ArithmeticException.class) .isThrownBy(() -> GBP_INT_MAX_MAJOR_PLUS1.getAmountMajorInt()); } @Test void test_getAmountMajorInt_tooBigNegative() { - assertThatExceptionOfType(ArithmeticException.class) + assertThatExceptionOfType(ArithmeticException.class) .isThrownBy(() -> GBP_INT_MIN_MAJOR_MINUS1.getAmountMajorInt()); } @@ -1220,13 +1214,13 @@ void test_getAmountMinorLong_negative() { @Test void test_getAmountMinorLong_tooBigPositive() { - assertThatExceptionOfType(ArithmeticException.class) + assertThatExceptionOfType(ArithmeticException.class) .isThrownBy(() -> GBP_LONG_MAX_PLUS1.getAmountMinorLong()); } @Test void test_getAmountMinorLong_tooBigNegative() { - assertThatExceptionOfType(ArithmeticException.class) + assertThatExceptionOfType(ArithmeticException.class) .isThrownBy(() -> GBP_LONG_MIN_MINUS1.getAmountMinorLong()); } @@ -1245,13 +1239,13 @@ void test_getAmountMinorInt_negative() { @Test void test_getAmountMinorInt_tooBigPositive() { - assertThatExceptionOfType(ArithmeticException.class) + assertThatExceptionOfType(ArithmeticException.class) .isThrownBy(() -> GBP_INT_MAX_PLUS1.getAmountMinorInt()); } @Test void test_getAmountMinorInt_tooBigNegative() { - assertThatExceptionOfType(ArithmeticException.class) + assertThatExceptionOfType(ArithmeticException.class) .isThrownBy(() -> GBP_INT_MIN_MINUS1.getAmountMinorInt()); } @@ -1323,20 +1317,20 @@ void test_isNegativeOrZero() { //----------------------------------------------------------------------- @Test void test_withAmount_BigDecimal() { - BigMoney test = GBP_2_34.withAmount(BIGDEC_2_345); + var test = GBP_2_34.withAmount(BIGDEC_2_345); 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); + var test = GBP_2_34.withAmount(BIGDEC_2_34); assertThat(test).isSameAs(GBP_2_34); } @Test void test_withAmount_BigDecimal_nullBigDecimal() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> GBP_2_34.withAmount((BigDecimal) null)); } @@ -1345,14 +1339,14 @@ void test_withAmount_BigDecimal_nullBigDecimal() { //----------------------------------------------------------------------- @Test void test_withAmount_double() { - BigMoney test = GBP_2_34.withAmount(2.345d); + var test = GBP_2_34.withAmount(2.345d); 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); + var test = GBP_2_34.withAmount(2.34d); assertThat(test).isSameAs(GBP_2_34); } @@ -1362,72 +1356,62 @@ void test_withAmount_double_same() { @Test void test_plus_Iterable_BigMoneyProvider() { Iterable iterable = Arrays.asList(GBP_2_33, GBP_1_23); - BigMoney test = GBP_2_34.plus(iterable); + var test = GBP_2_34.plus(iterable); 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); + var test = GBP_2_34.plus(iterable); 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); + var test = GBP_2_34.plus(iterable); assertThat(test).hasToString("GBP 5.90"); } @Test void test_plus_Iterable_Mixed() { - Iterable iterable = Arrays.asList(GBP_2_33.toMoney(), new BigMoneyProvider() { - @Override - public BigMoney toBigMoney() { - return GBP_1_23; - } - }); - BigMoney test = GBP_2_34.plus(iterable); + Iterable iterable = Arrays.asList(GBP_2_33.toMoney(), () -> GBP_1_23); + var test = GBP_2_34.plus(iterable); 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); + var test = GBP_2_34.plus(iterable); assertThat(test).isEqualTo(GBP_2_34); } @Test void test_plus_Iterable_currencyMismatch() { Iterable iterable = Arrays.asList(GBP_2_33, JPY_423); - assertThatExceptionOfType(CurrencyMismatchException.class) + assertThatExceptionOfType(CurrencyMismatchException.class) .isThrownBy(() -> GBP_M5_78.plus(iterable)); } @Test void test_plus_Iterable_nullEntry() { Iterable iterable = Arrays.asList(GBP_2_33, null); - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> GBP_M5_78.plus(iterable)); } @Test void test_plus_Iterable_nullIterable() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> GBP_M5_78.plus((Iterable) null)); } @Test void test_plus_Iterable_badProvider() { - Iterable iterable = Arrays.asList(new BigMoneyProvider() { - @Override - public BigMoney toBigMoney() { - return null; - } - }); - assertThatExceptionOfType(NullPointerException.class) + Iterable iterable = Arrays.asList(() -> null); + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> GBP_M5_78.plus(iterable)); } @@ -1436,59 +1420,54 @@ public BigMoney toBigMoney() { //----------------------------------------------------------------------- @Test void test_plus_BigMoneyProvider_zero() { - BigMoney test = GBP_2_34.plus(GBP_0_00); + var test = GBP_2_34.plus(GBP_0_00); assertThat(test).isSameAs(GBP_2_34); } @Test void test_plus_BigMoneyProvider_positive() { - BigMoney test = GBP_2_34.plus(GBP_1_23); + var test = GBP_2_34.plus(GBP_1_23); 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); + var test = GBP_2_34.plus(GBP_M1_23); 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")); + var test = GBP_2_34.plus(BigMoney.parse("GBP 1.111")); 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)); + var test = GBP_2_34.plus(BigMoney.ofMinor(GBP, 1)); assertThat(test).hasToString("GBP 2.35"); assertThat(test.getScale()).isEqualTo(2); } @Test void test_plus_BigMoneyProvider_currencyMismatch() { - assertThatExceptionOfType(CurrencyMismatchException.class) + assertThatExceptionOfType(CurrencyMismatchException.class) .isThrownBy(() -> GBP_M5_78.plus(USD_1_23)); } @Test void test_plus_BigMoneyProvider_nullBigMoneyProvider() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> GBP_M5_78.plus((BigMoneyProvider) null)); } @Test void test_plus_BigMoneyProvider_badProvider() { - BigMoneyProvider provider = new BigMoneyProvider() { - @Override - public BigMoney toBigMoney() { - return null; - } - }; - assertThatExceptionOfType(NullPointerException.class) + BigMoneyProvider provider = () -> null; + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> GBP_M5_78.plus(provider)); } @@ -1497,34 +1476,34 @@ public BigMoney toBigMoney() { //----------------------------------------------------------------------- @Test void test_plus_BigDecimal_zero() { - BigMoney test = GBP_2_34.plus(BigDecimal.ZERO); + var test = GBP_2_34.plus(BigDecimal.ZERO); assertThat(test).isSameAs(GBP_2_34); } @Test void test_plus_BigDecimal_positive() { - BigMoney test = GBP_2_34.plus(bd("1.23")); + var test = GBP_2_34.plus(bd("1.23")); 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")); + var test = GBP_2_34.plus(bd("-1.23")); 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")); + var test = GBP_2_34.plus(bd("1.235")); assertThat(test).hasToString("GBP 3.575"); assertThat(test.getScale()).isEqualTo(3); } @Test void test_plus_BigDecimal_nullBigDecimal() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> GBP_M5_78.plus((BigDecimal) null)); } @@ -1533,27 +1512,27 @@ void test_plus_BigDecimal_nullBigDecimal() { //----------------------------------------------------------------------- @Test void test_plus_double_zero() { - BigMoney test = GBP_2_34.plus(0d); + var test = GBP_2_34.plus(0d); assertThat(test).isSameAs(GBP_2_34); } @Test void test_plus_double_positive() { - BigMoney test = GBP_2_34.plus(1.23d); + var test = GBP_2_34.plus(1.23d); 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); + var test = GBP_2_34.plus(-1.23d); 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); + var test = GBP_2_34.plus(1.234d); assertThat(test).hasToString("GBP 3.574"); assertThat(test.getScale()).isEqualTo(3); } @@ -1563,20 +1542,20 @@ void test_plus_double_scale() { //----------------------------------------------------------------------- @Test void test_plusMajor_zero() { - BigMoney test = GBP_2_34.plusMajor(0); + var test = GBP_2_34.plusMajor(0); assertThat(test).isSameAs(GBP_2_34); } @Test void test_plusMajor_positive() { - BigMoney test = GBP_2_34.plusMajor(123); + var test = GBP_2_34.plusMajor(123); assertThat(test).hasToString("GBP 125.34"); assertThat(test.getScale()).isEqualTo(2); } @Test void test_plusMajor_negative() { - BigMoney test = GBP_2_34.plusMajor(-123); + var test = GBP_2_34.plusMajor(-123); assertThat(test).hasToString("GBP -120.66"); assertThat(test.getScale()).isEqualTo(2); } @@ -1586,27 +1565,27 @@ void test_plusMajor_negative() { //----------------------------------------------------------------------- @Test void test_plusMinor_zero() { - BigMoney test = GBP_2_34.plusMinor(0); + var test = GBP_2_34.plusMinor(0); assertThat(test).isSameAs(GBP_2_34); } @Test void test_plusMinor_positive() { - BigMoney test = GBP_2_34.plusMinor(123); + var test = GBP_2_34.plusMinor(123); assertThat(test).hasToString("GBP 3.57"); assertThat(test.getScale()).isEqualTo(2); } @Test void test_plusMinor_negative() { - BigMoney test = GBP_2_34.plusMinor(-123); + var test = GBP_2_34.plusMinor(-123); assertThat(test).hasToString("GBP 1.11"); assertThat(test.getScale()).isEqualTo(2); } @Test void test_plusMinor_scale() { - BigMoney test = BigMoney.parse("GBP 12").plusMinor(123); + var test = BigMoney.parse("GBP 12").plusMinor(123); assertThat(test).hasToString("GBP 13.23"); assertThat(test.getScale()).isEqualTo(2); } @@ -1616,43 +1595,43 @@ void test_plusMinor_scale() { //----------------------------------------------------------------------- @Test void test_plusRetainScale_BigMoneyProviderRoundingMode_zero() { - BigMoney test = GBP_2_34.plusRetainScale(BigMoney.zero(GBP), RoundingMode.UNNECESSARY); + var test = GBP_2_34.plusRetainScale(BigMoney.zero(GBP), RoundingMode.UNNECESSARY); 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); + var test = GBP_2_34.plusRetainScale(BigMoney.parse("GBP 1.23"), RoundingMode.UNNECESSARY); 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); + var test = GBP_2_34.plusRetainScale(BigMoney.parse("GBP -1.23"), RoundingMode.UNNECESSARY); 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); + var test = GBP_2_34.plusRetainScale(BigMoney.parse("GBP 1.235"), RoundingMode.DOWN); assertThat(test).hasToString("GBP 3.57"); } @Test void test_plusRetainScale_BigMoneyProviderRoundingMode_roundUnecessary() { - assertThatExceptionOfType(ArithmeticException.class) + assertThatExceptionOfType(ArithmeticException.class) .isThrownBy(() -> GBP_2_34.plusRetainScale(BigMoney.parse("GBP 1.235"), RoundingMode.UNNECESSARY)); } @Test void test_plusRetainScale_BigMoneyProviderRoundingMode_nullBigDecimal() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> GBP_M5_78.plusRetainScale((BigDecimal) null, RoundingMode.UNNECESSARY)); } @Test void test_plusRetainScale_BigMoneyProviderRoundingMode_nullRoundingMode() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> GBP_M5_78.plusRetainScale(BigMoney.parse("GBP 1.23"), (RoundingMode) null)); } @@ -1661,43 +1640,43 @@ void test_plusRetainScale_BigMoneyProviderRoundingMode_nullRoundingMode() { //----------------------------------------------------------------------- @Test void test_plusRetainScale_BigDecimalRoundingMode_zero() { - BigMoney test = GBP_2_34.plusRetainScale(BigDecimal.ZERO, RoundingMode.UNNECESSARY); + var test = GBP_2_34.plusRetainScale(BigDecimal.ZERO, RoundingMode.UNNECESSARY); assertThat(test).isSameAs(GBP_2_34); } @Test void test_plusRetainScale_BigDecimalRoundingMode_positive() { - BigMoney test = GBP_2_34.plusRetainScale(bd("1.23"), RoundingMode.UNNECESSARY); + var test = GBP_2_34.plusRetainScale(bd("1.23"), RoundingMode.UNNECESSARY); assertThat(test).hasToString("GBP 3.57"); } @Test void test_plusRetainScale_BigDecimalRoundingMode_negative() { - BigMoney test = GBP_2_34.plusRetainScale(bd("-1.23"), RoundingMode.UNNECESSARY); + var test = GBP_2_34.plusRetainScale(bd("-1.23"), RoundingMode.UNNECESSARY); assertThat(test).hasToString("GBP 1.11"); } @Test void test_plusRetainScale_BigDecimalRoundingMode_roundDown() { - BigMoney test = GBP_2_34.plusRetainScale(bd("1.235"), RoundingMode.DOWN); + var test = GBP_2_34.plusRetainScale(bd("1.235"), RoundingMode.DOWN); assertThat(test).hasToString("GBP 3.57"); } @Test void test_plusRetainScale_BigDecimalRoundingMode_roundUnecessary() { - assertThatExceptionOfType(ArithmeticException.class) + assertThatExceptionOfType(ArithmeticException.class) .isThrownBy(() -> GBP_2_34.plusRetainScale(bd("1.235"), RoundingMode.UNNECESSARY)); } @Test void test_plusRetainScale_BigDecimalRoundingMode_nullBigDecimal() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> GBP_M5_78.plusRetainScale((BigDecimal) null, RoundingMode.UNNECESSARY)); } @Test void test_plusRetainScale_BigDecimalRoundingMode_nullRoundingMode() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> GBP_M5_78.plusRetainScale(BIGDEC_2_34, (RoundingMode) null)); } @@ -1706,37 +1685,37 @@ void test_plusRetainScale_BigDecimalRoundingMode_nullRoundingMode() { //----------------------------------------------------------------------- @Test void test_plusRetainScale_doubleRoundingMode_zero() { - BigMoney test = GBP_2_34.plusRetainScale(0d, RoundingMode.UNNECESSARY); + var test = GBP_2_34.plusRetainScale(0d, RoundingMode.UNNECESSARY); assertThat(test).isSameAs(GBP_2_34); } @Test void test_plusRetainScale_doubleRoundingMode_positive() { - BigMoney test = GBP_2_34.plusRetainScale(1.23d, RoundingMode.UNNECESSARY); + var test = GBP_2_34.plusRetainScale(1.23d, RoundingMode.UNNECESSARY); assertThat(test).hasToString("GBP 3.57"); } @Test void test_plusRetainScale_doubleRoundingMode_negative() { - BigMoney test = GBP_2_34.plusRetainScale(-1.23d, RoundingMode.UNNECESSARY); + var test = GBP_2_34.plusRetainScale(-1.23d, RoundingMode.UNNECESSARY); assertThat(test).hasToString("GBP 1.11"); } @Test void test_plusRetainScale_doubleRoundingMode_roundDown() { - BigMoney test = GBP_2_34.plusRetainScale(1.235d, RoundingMode.DOWN); + var test = GBP_2_34.plusRetainScale(1.235d, RoundingMode.DOWN); assertThat(test).hasToString("GBP 3.57"); } @Test void test_plusRetainScale_doubleRoundingMode_roundUnecessary() { - assertThatExceptionOfType(ArithmeticException.class) + assertThatExceptionOfType(ArithmeticException.class) .isThrownBy(() -> GBP_2_34.plusRetainScale(1.235d, RoundingMode.UNNECESSARY)); } @Test void test_plusRetainScale_doubleRoundingMode_nullRoundingMode() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> GBP_M5_78.plusRetainScale(2.34d, (RoundingMode) null)); } @@ -1746,72 +1725,62 @@ void test_plusRetainScale_doubleRoundingMode_nullRoundingMode() { @Test void test_minus_Iterable_BigMoneyProvider() { Iterable iterable = Arrays.asList(GBP_2_33, GBP_1_23); - BigMoney test = GBP_2_34.minus(iterable); + var test = GBP_2_34.minus(iterable); 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); + var test = GBP_2_34.minus(iterable); 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); + var test = GBP_2_34.minus(iterable); assertThat(test).hasToString("GBP -1.22"); } @Test void test_minus_Iterable_Mixed() { - Iterable iterable = Arrays.asList(GBP_2_33.toMoney(), new BigMoneyProvider() { - @Override - public BigMoney toBigMoney() { - return GBP_1_23; - } - }); - BigMoney test = GBP_2_34.minus(iterable); + Iterable iterable = Arrays.asList(GBP_2_33.toMoney(), () -> GBP_1_23); + var test = GBP_2_34.minus(iterable); 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); + var test = GBP_2_34.minus(iterable); assertThat(test).isEqualTo(GBP_2_34); } @Test void test_minus_Iterable_currencyMismatch() { Iterable iterable = Arrays.asList(GBP_2_33, JPY_423); - assertThatExceptionOfType(CurrencyMismatchException.class) + assertThatExceptionOfType(CurrencyMismatchException.class) .isThrownBy(() -> GBP_M5_78.minus(iterable)); } @Test void test_minus_Iterable_nullEntry() { Iterable iterable = Arrays.asList(GBP_2_33, null); - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> GBP_M5_78.minus(iterable)); } @Test void test_minus_Iterable_nullIterable() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> GBP_M5_78.minus((Iterable) null)); } @Test void test_minus_Iterable_badProvider() { - Iterable iterable = Arrays.asList(new BigMoneyProvider() { - @Override - public BigMoney toBigMoney() { - return null; - } - }); - assertThatExceptionOfType(NullPointerException.class) + Iterable iterable = Arrays.asList(() -> null); + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> GBP_M5_78.minus(iterable)); } @@ -1820,59 +1789,54 @@ public BigMoney toBigMoney() { //----------------------------------------------------------------------- @Test void test_minus_BigMoneyProvider_zero() { - BigMoney test = GBP_2_34.minus(GBP_0_00); + var test = GBP_2_34.minus(GBP_0_00); assertThat(test).isSameAs(GBP_2_34); } @Test void test_minus_BigMoneyProvider_positive() { - BigMoney test = GBP_2_34.minus(GBP_1_23); + var test = GBP_2_34.minus(GBP_1_23); 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); + var test = GBP_2_34.minus(GBP_M1_23); 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")); + var test = GBP_2_34.minus(BigMoney.parse("GBP 1.111")); 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)); + var test = GBP_2_34.minus(BigMoney.ofMinor(GBP, 1)); assertThat(test).hasToString("GBP 2.33"); assertThat(test.getScale()).isEqualTo(2); } @Test void test_minus_BigMoneyProvider_currencyMismatch() { - assertThatExceptionOfType(CurrencyMismatchException.class) + assertThatExceptionOfType(CurrencyMismatchException.class) .isThrownBy(() -> GBP_M5_78.minus(USD_1_23)); } @Test void test_minus_BigMoneyProvider_nullBigMoneyProvider() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> GBP_M5_78.minus((BigMoneyProvider) null)); } @Test void test_minus_BigMoneyProvider_badProvider() { - BigMoneyProvider provider = new BigMoneyProvider() { - @Override - public BigMoney toBigMoney() { - return null; - } - }; - assertThatExceptionOfType(NullPointerException.class) + BigMoneyProvider provider = () -> null; + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> GBP_M5_78.minus(provider)); } @@ -1881,34 +1845,34 @@ public BigMoney toBigMoney() { //----------------------------------------------------------------------- @Test void test_minus_BigDecimal_zero() { - BigMoney test = GBP_2_34.minus(BigDecimal.ZERO); + var test = GBP_2_34.minus(BigDecimal.ZERO); assertThat(test).isSameAs(GBP_2_34); } @Test void test_minus_BigDecimal_positive() { - BigMoney test = GBP_2_34.minus(bd("1.23")); + var test = GBP_2_34.minus(bd("1.23")); 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")); + var test = GBP_2_34.minus(bd("-1.23")); 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")); + var test = GBP_2_34.minus(bd("1.235")); assertThat(test).hasToString("GBP 1.105"); assertThat(test.getScale()).isEqualTo(3); } @Test void test_minus_BigDecimal_nullBigDecimal() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> GBP_M5_78.minus((BigDecimal) null)); } @@ -1917,27 +1881,27 @@ void test_minus_BigDecimal_nullBigDecimal() { //----------------------------------------------------------------------- @Test void test_minus_double_zero() { - BigMoney test = GBP_2_34.minus(0d); + var test = GBP_2_34.minus(0d); assertThat(test).isSameAs(GBP_2_34); } @Test void test_minus_double_positive() { - BigMoney test = GBP_2_34.minus(1.23d); + var test = GBP_2_34.minus(1.23d); 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); + var test = GBP_2_34.minus(-1.23d); 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); + var test = GBP_2_34.minus(1.235d); assertThat(test).hasToString("GBP 1.105"); assertThat(test.getScale()).isEqualTo(3); } @@ -1947,20 +1911,20 @@ void test_minus_double_scale() { //----------------------------------------------------------------------- @Test void test_minusMajor_zero() { - BigMoney test = GBP_2_34.minusMajor(0); + var test = GBP_2_34.minusMajor(0); assertThat(test).isSameAs(GBP_2_34); } @Test void test_minusMajor_positive() { - BigMoney test = GBP_2_34.minusMajor(123); + var test = GBP_2_34.minusMajor(123); assertThat(test).hasToString("GBP -120.66"); assertThat(test.getScale()).isEqualTo(2); } @Test void test_minusMajor_negative() { - BigMoney test = GBP_2_34.minusMajor(-123); + var test = GBP_2_34.minusMajor(-123); assertThat(test).hasToString("GBP 125.34"); assertThat(test.getScale()).isEqualTo(2); } @@ -1970,27 +1934,27 @@ void test_minusMajor_negative() { //----------------------------------------------------------------------- @Test void test_minusMinor_zero() { - BigMoney test = GBP_2_34.minusMinor(0); + var test = GBP_2_34.minusMinor(0); assertThat(test).isSameAs(GBP_2_34); } @Test void test_minusMinor_positive() { - BigMoney test = GBP_2_34.minusMinor(123); + var test = GBP_2_34.minusMinor(123); assertThat(test).hasToString("GBP 1.11"); assertThat(test.getScale()).isEqualTo(2); } @Test void test_minusMinor_negative() { - BigMoney test = GBP_2_34.minusMinor(-123); + var test = GBP_2_34.minusMinor(-123); assertThat(test).hasToString("GBP 3.57"); assertThat(test.getScale()).isEqualTo(2); } @Test void test_minusMinor_scale() { - BigMoney test = BigMoney.parse("GBP 12").minusMinor(123); + var test = BigMoney.parse("GBP 12").minusMinor(123); assertThat(test).hasToString("GBP 10.77"); assertThat(test.getScale()).isEqualTo(2); } @@ -2000,43 +1964,43 @@ void test_minusMinor_scale() { //----------------------------------------------------------------------- @Test void test_minusRetainScale_BigMoneyProviderRoundingMode_zero() { - BigMoney test = GBP_2_34.minusRetainScale(BigMoney.zero(GBP), RoundingMode.UNNECESSARY); + var test = GBP_2_34.minusRetainScale(BigMoney.zero(GBP), RoundingMode.UNNECESSARY); 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); + var test = GBP_2_34.minusRetainScale(BigMoney.parse("GBP 1.23"), RoundingMode.UNNECESSARY); 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); + var test = GBP_2_34.minusRetainScale(BigMoney.parse("GBP -1.23"), RoundingMode.UNNECESSARY); 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); + var test = GBP_2_34.minusRetainScale(BigMoney.parse("GBP 1.235"), RoundingMode.DOWN); assertThat(test).hasToString("GBP 1.10"); } @Test void test_minusRetainScale_BigMoneyProviderRoundingMode_roundUnecessary() { - assertThatExceptionOfType(ArithmeticException.class) + assertThatExceptionOfType(ArithmeticException.class) .isThrownBy(() -> GBP_2_34.minusRetainScale(BigMoney.parse("GBP 1.235"), RoundingMode.UNNECESSARY)); } @Test void test_minusRetainScale_BigMoneyProviderRoundingMode_nullBigMoneyProvider() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> GBP_M5_78.minusRetainScale((BigMoneyProvider) null, RoundingMode.UNNECESSARY)); } @Test void test_minusRetainScale_BigMoneyProviderRoundingMode_nullRoundingMode() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> GBP_M5_78.minusRetainScale(BigMoney.parse("GBP 123"), (RoundingMode) null)); } @@ -2045,43 +2009,43 @@ void test_minusRetainScale_BigMoneyProviderRoundingMode_nullRoundingMode() { //----------------------------------------------------------------------- @Test void test_minusRetainScale_BigDecimalRoundingMode_zero() { - BigMoney test = GBP_2_34.minusRetainScale(BigDecimal.ZERO, RoundingMode.UNNECESSARY); + var test = GBP_2_34.minusRetainScale(BigDecimal.ZERO, RoundingMode.UNNECESSARY); assertThat(test).isSameAs(GBP_2_34); } @Test void test_minusRetainScale_BigDecimalRoundingMode_positive() { - BigMoney test = GBP_2_34.minusRetainScale(bd("1.23"), RoundingMode.UNNECESSARY); + var test = GBP_2_34.minusRetainScale(bd("1.23"), RoundingMode.UNNECESSARY); assertThat(test).hasToString("GBP 1.11"); } @Test void test_minusRetainScale_BigDecimalRoundingMode_negative() { - BigMoney test = GBP_2_34.minusRetainScale(bd("-1.23"), RoundingMode.UNNECESSARY); + var test = GBP_2_34.minusRetainScale(bd("-1.23"), RoundingMode.UNNECESSARY); assertThat(test).hasToString("GBP 3.57"); } @Test void test_minusRetainScale_BigDecimalRoundingMode_roundDown() { - BigMoney test = GBP_2_34.minusRetainScale(bd("1.235"), RoundingMode.DOWN); + var test = GBP_2_34.minusRetainScale(bd("1.235"), RoundingMode.DOWN); assertThat(test).hasToString("GBP 1.10"); } @Test void test_minusRetainScale_BigDecimalRoundingMode_roundUnecessary() { - assertThatExceptionOfType(ArithmeticException.class) + assertThatExceptionOfType(ArithmeticException.class) .isThrownBy(() -> GBP_2_34.minusRetainScale(bd("1.235"), RoundingMode.UNNECESSARY)); } @Test void test_minusRetainScale_BigDecimalRoundingMode_nullBigDecimal() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> GBP_M5_78.minusRetainScale((BigDecimal) null, RoundingMode.UNNECESSARY)); } @Test void test_minusRetainScale_BigDecimalRoundingMode_nullRoundingMode() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> GBP_M5_78.minusRetainScale(BIGDEC_2_34, (RoundingMode) null)); } @@ -2090,37 +2054,37 @@ void test_minusRetainScale_BigDecimalRoundingMode_nullRoundingMode() { //----------------------------------------------------------------------- @Test void test_minusRetainScale_doubleRoundingMode_zero() { - BigMoney test = GBP_2_34.minusRetainScale(0d, RoundingMode.UNNECESSARY); + var test = GBP_2_34.minusRetainScale(0d, RoundingMode.UNNECESSARY); assertThat(test).isSameAs(GBP_2_34); } @Test void test_minusRetainScale_doubleRoundingMode_positive() { - BigMoney test = GBP_2_34.minusRetainScale(1.23d, RoundingMode.UNNECESSARY); + var test = GBP_2_34.minusRetainScale(1.23d, RoundingMode.UNNECESSARY); assertThat(test).hasToString("GBP 1.11"); } @Test void test_minusRetainScale_doubleRoundingMode_negative() { - BigMoney test = GBP_2_34.minusRetainScale(-1.23d, RoundingMode.UNNECESSARY); + var test = GBP_2_34.minusRetainScale(-1.23d, RoundingMode.UNNECESSARY); assertThat(test).hasToString("GBP 3.57"); } @Test void test_minusRetainScale_doubleRoundingMode_roundDown() { - BigMoney test = GBP_2_34.minusRetainScale(1.235d, RoundingMode.DOWN); + var test = GBP_2_34.minusRetainScale(1.235d, RoundingMode.DOWN); assertThat(test).hasToString("GBP 1.10"); } @Test void test_minusRetainScale_doubleRoundingMode_roundUnecessary() { - assertThatExceptionOfType(ArithmeticException.class) + assertThatExceptionOfType(ArithmeticException.class) .isThrownBy(() -> GBP_2_34.minusRetainScale(1.235d, RoundingMode.UNNECESSARY)); } @Test void test_minusRetainScale_doubleRoundingMode_nullRoundingMode() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> GBP_M5_78.minusRetainScale(2.34d, (RoundingMode) null)); } @@ -2129,27 +2093,27 @@ void test_minusRetainScale_doubleRoundingMode_nullRoundingMode() { //----------------------------------------------------------------------- @Test void test_multipliedBy_BigDecimal_one() { - BigMoney test = GBP_2_34.multipliedBy(BigDecimal.ONE); + var test = GBP_2_34.multipliedBy(BigDecimal.ONE); assertThat(test).isSameAs(GBP_2_34); } @Test void test_multipliedBy_BigDecimal_positive() { - BigMoney test = GBP_2_33.multipliedBy(bd("2.5")); + var test = GBP_2_33.multipliedBy(bd("2.5")); 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")); + var test = GBP_2_33.multipliedBy(bd("-2.5")); assertThat(test).hasToString("GBP -5.825"); assertThat(test.getScale()).isEqualTo(3); } @Test void test_multipliedBy_BigDecimal_nullBigDecimal() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> GBP_5_78.multipliedBy((BigDecimal) null)); } @@ -2158,20 +2122,20 @@ void test_multipliedBy_BigDecimal_nullBigDecimal() { //----------------------------------------------------------------------- @Test void test_multipliedBy_doubleRoundingMode_one() { - BigMoney test = GBP_2_34.multipliedBy(1d); + var test = GBP_2_34.multipliedBy(1d); assertThat(test).isSameAs(GBP_2_34); } @Test void test_multipliedBy_doubleRoundingMode_positive() { - BigMoney test = GBP_2_33.multipliedBy(2.5d); + var test = GBP_2_33.multipliedBy(2.5d); 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); + var test = GBP_2_33.multipliedBy(-2.5d); assertThat(test).hasToString("GBP -5.825"); assertThat(test.getScale()).isEqualTo(3); } @@ -2181,20 +2145,20 @@ void test_multipliedBy_doubleRoundingMode_negative() { //----------------------------------------------------------------------- @Test void test_multipliedBy_long_one() { - BigMoney test = GBP_2_34.multipliedBy(1); + var test = GBP_2_34.multipliedBy(1); assertThat(test).isSameAs(GBP_2_34); } @Test void test_multipliedBy_long_positive() { - BigMoney test = GBP_2_34.multipliedBy(3); + var test = GBP_2_34.multipliedBy(3); assertThat(test).hasToString("GBP 7.02"); assertThat(test.getScale()).isEqualTo(2); } @Test void test_multipliedBy_long_negative() { - BigMoney test = GBP_2_34.multipliedBy(-3); + var test = GBP_2_34.multipliedBy(-3); assertThat(test).hasToString("GBP -7.02"); assertThat(test.getScale()).isEqualTo(2); } @@ -2204,37 +2168,37 @@ void test_multipliedBy_long_negative() { //----------------------------------------------------------------------- @Test void test_multiplyRetainScale_BigDecimalRoundingMode_one() { - BigMoney test = GBP_2_34.multiplyRetainScale(BigDecimal.ONE, RoundingMode.DOWN); + var test = GBP_2_34.multiplyRetainScale(BigDecimal.ONE, RoundingMode.DOWN); assertThat(test).isSameAs(GBP_2_34); } @Test void test_multiplyRetainScale_BigDecimalRoundingMode_positive() { - BigMoney test = GBP_2_33.multiplyRetainScale(bd("2.5"), RoundingMode.DOWN); + var test = GBP_2_33.multiplyRetainScale(bd("2.5"), RoundingMode.DOWN); 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); + var test = GBP_2_33.multiplyRetainScale(bd("2.5"), RoundingMode.HALF_UP); assertThat(test).hasToString("GBP 5.83"); } @Test void test_multiplyRetainScale_BigDecimalRoundingMode_negative() { - BigMoney test = GBP_2_33.multiplyRetainScale(bd("-2.5"), RoundingMode.FLOOR); + var test = GBP_2_33.multiplyRetainScale(bd("-2.5"), RoundingMode.FLOOR); assertThat(test).hasToString("GBP -5.83"); } @Test void test_multiplyRetainScale_BigDecimalRoundingMode_nullBigDecimal() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> GBP_5_78.multiplyRetainScale((BigDecimal) null, RoundingMode.DOWN)); } @Test void test_multiplyRetainScale_BigDecimalRoundingMode_nullRoundingMode() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> GBP_5_78.multiplyRetainScale(bd("2.5"), (RoundingMode) null)); } @@ -2243,31 +2207,31 @@ void test_multiplyRetainScale_BigDecimalRoundingMode_nullRoundingMode() { //----------------------------------------------------------------------- @Test void test_multiplyRetainScale_doubleRoundingMode_one() { - BigMoney test = GBP_2_34.multiplyRetainScale(1d, RoundingMode.DOWN); + var test = GBP_2_34.multiplyRetainScale(1d, RoundingMode.DOWN); assertThat(test).isSameAs(GBP_2_34); } @Test void test_multiplyRetainScale_doubleRoundingMode_positive() { - BigMoney test = GBP_2_33.multiplyRetainScale(2.5d, RoundingMode.DOWN); + var test = GBP_2_33.multiplyRetainScale(2.5d, RoundingMode.DOWN); assertThat(test).hasToString("GBP 5.82"); } @Test void test_multiplyRetainScale_doubleRoundingMode_positive_halfUp() { - BigMoney test = GBP_2_33.multiplyRetainScale(2.5d, RoundingMode.HALF_UP); + var test = GBP_2_33.multiplyRetainScale(2.5d, RoundingMode.HALF_UP); assertThat(test).hasToString("GBP 5.83"); } @Test void test_multiplyRetainScale_doubleRoundingMode_negative() { - BigMoney test = GBP_2_33.multiplyRetainScale(-2.5d, RoundingMode.FLOOR); + var test = GBP_2_33.multiplyRetainScale(-2.5d, RoundingMode.FLOOR); assertThat(test).hasToString("GBP -5.83"); } @Test void test_multiplyRetainScale_doubleRoundingMode_nullRoundingMode() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> GBP_5_78.multiplyRetainScale(2.5d, (RoundingMode) null)); } @@ -2276,37 +2240,37 @@ void test_multiplyRetainScale_doubleRoundingMode_nullRoundingMode() { //----------------------------------------------------------------------- @Test void test_dividedBy_BigDecimalRoundingMode_one() { - BigMoney test = GBP_2_34.dividedBy(BigDecimal.ONE, RoundingMode.DOWN); + var test = GBP_2_34.dividedBy(BigDecimal.ONE, RoundingMode.DOWN); assertThat(test).isSameAs(GBP_2_34); } @Test void test_dividedBy_BigDecimalRoundingMode_positive() { - BigMoney test = GBP_2_34.dividedBy(bd("2.5"), RoundingMode.DOWN); + var test = GBP_2_34.dividedBy(bd("2.5"), RoundingMode.DOWN); 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); + var test = GBP_2_34.dividedBy(bd("2.5"), RoundingMode.HALF_UP); assertThat(test).hasToString("GBP 0.94"); } @Test void test_dividedBy_BigDecimalRoundingMode_negative() { - BigMoney test = GBP_2_34.dividedBy(bd("-2.5"), RoundingMode.FLOOR); + var test = GBP_2_34.dividedBy(bd("-2.5"), RoundingMode.FLOOR); assertThat(test).hasToString("GBP -0.94"); } @Test void test_dividedBy_BigDecimalRoundingMode_nullBigDecimal() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> GBP_5_78.dividedBy((BigDecimal) null, RoundingMode.DOWN)); } @Test void test_dividedBy_BigDecimalRoundingMode_nullRoundingMode() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> GBP_5_78.dividedBy(bd("2.5"), (RoundingMode) null)); } @@ -2315,31 +2279,31 @@ void test_dividedBy_BigDecimalRoundingMode_nullRoundingMode() { //----------------------------------------------------------------------- @Test void test_dividedBy_doubleRoundingMode_one() { - BigMoney test = GBP_2_34.dividedBy(1d, RoundingMode.DOWN); + var test = GBP_2_34.dividedBy(1d, RoundingMode.DOWN); assertThat(test).isSameAs(GBP_2_34); } @Test void test_dividedBy_doubleRoundingMode_positive() { - BigMoney test = GBP_2_34.dividedBy(2.5d, RoundingMode.DOWN); + var test = GBP_2_34.dividedBy(2.5d, RoundingMode.DOWN); assertThat(test).hasToString("GBP 0.93"); } @Test void test_dividedBy_doubleRoundingMode_positive_halfUp() { - BigMoney test = GBP_2_34.dividedBy(2.5d, RoundingMode.HALF_UP); + var test = GBP_2_34.dividedBy(2.5d, RoundingMode.HALF_UP); assertThat(test).hasToString("GBP 0.94"); } @Test void test_dividedBy_doubleRoundingMode_negative() { - BigMoney test = GBP_2_34.dividedBy(-2.5d, RoundingMode.FLOOR); + var test = GBP_2_34.dividedBy(-2.5d, RoundingMode.FLOOR); assertThat(test).hasToString("GBP -0.94"); } @Test void test_dividedBy_doubleRoundingMode_nullRoundingMode() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> GBP_5_78.dividedBy(2.5d, (RoundingMode) null)); } @@ -2348,31 +2312,31 @@ void test_dividedBy_doubleRoundingMode_nullRoundingMode() { //----------------------------------------------------------------------- @Test void test_dividedBy_long_one() { - BigMoney test = GBP_2_34.dividedBy(1, RoundingMode.DOWN); + var test = GBP_2_34.dividedBy(1, RoundingMode.DOWN); assertThat(test).isSameAs(GBP_2_34); } @Test void test_dividedBy_long_positive() { - BigMoney test = GBP_2_34.dividedBy(3, RoundingMode.DOWN); + var test = GBP_2_34.dividedBy(3, RoundingMode.DOWN); assertThat(test).hasToString("GBP 0.78"); } @Test void test_dividedBy_long_positive_roundDown() { - BigMoney test = GBP_2_35.dividedBy(3, RoundingMode.DOWN); + var test = GBP_2_35.dividedBy(3, RoundingMode.DOWN); assertThat(test).hasToString("GBP 0.78"); } @Test void test_dividedBy_long_positive_roundUp() { - BigMoney test = GBP_2_35.dividedBy(3, RoundingMode.UP); + var test = GBP_2_35.dividedBy(3, RoundingMode.UP); assertThat(test).hasToString("GBP 0.79"); } @Test void test_dividedBy_long_negative() { - BigMoney test = GBP_2_34.dividedBy(-3, RoundingMode.DOWN); + var test = GBP_2_34.dividedBy(-3, RoundingMode.DOWN); assertThat(test).hasToString("GBP -0.78"); } @@ -2381,19 +2345,19 @@ void test_dividedBy_long_negative() { //----------------------------------------------------------------------- @Test void test_negated_zero() { - BigMoney test = GBP_0_00.negated(); + var test = GBP_0_00.negated(); assertThat(test).isSameAs(GBP_0_00); } @Test void test_negated_positive() { - BigMoney test = GBP_2_34.negated(); + var test = GBP_2_34.negated(); assertThat(test).hasToString("GBP -2.34"); } @Test void test_negated_negative() { - BigMoney test = BigMoney.parse("GBP -2.34").negated(); + var test = BigMoney.parse("GBP -2.34").negated(); assertThat(test).hasToString("GBP 2.34"); } @@ -2402,13 +2366,13 @@ void test_negated_negative() { //----------------------------------------------------------------------- @Test void test_abs_positive() { - BigMoney test = GBP_2_34.abs(); + var test = GBP_2_34.abs(); assertThat(test).isSameAs(GBP_2_34); } @Test void test_abs_negative() { - BigMoney test = BigMoney.parse("GBP -2.34").abs(); + var test = BigMoney.parse("GBP -2.34").abs(); assertThat(test).hasToString("GBP 2.34"); } @@ -2417,55 +2381,55 @@ void test_abs_negative() { //----------------------------------------------------------------------- @Test void test_round_2down() { - BigMoney test = GBP_2_34.rounded(2, RoundingMode.DOWN); + var test = GBP_2_34.rounded(2, RoundingMode.DOWN); assertThat(test).isSameAs(GBP_2_34); } @Test void test_round_2up() { - BigMoney test = GBP_2_34.rounded(2, RoundingMode.DOWN); + var test = GBP_2_34.rounded(2, RoundingMode.DOWN); assertThat(test).isSameAs(GBP_2_34); } @Test void test_round_1down() { - BigMoney test = GBP_2_34.rounded(1, RoundingMode.DOWN); + var test = GBP_2_34.rounded(1, RoundingMode.DOWN); assertThat(test).hasToString("GBP 2.30"); } @Test void test_round_1up() { - BigMoney test = GBP_2_34.rounded(1, RoundingMode.UP); + var test = GBP_2_34.rounded(1, RoundingMode.UP); assertThat(test).hasToString("GBP 2.40"); } @Test void test_round_0down() { - BigMoney test = GBP_2_34.rounded(0, RoundingMode.DOWN); + var test = GBP_2_34.rounded(0, RoundingMode.DOWN); assertThat(test).hasToString("GBP 2.00"); } @Test void test_round_0up() { - BigMoney test = GBP_2_34.rounded(0, RoundingMode.UP); + var test = GBP_2_34.rounded(0, RoundingMode.UP); assertThat(test).hasToString("GBP 3.00"); } @Test void test_round_M1down() { - BigMoney test = BigMoney.parse("GBP 432.34").rounded(-1, RoundingMode.DOWN); + var test = BigMoney.parse("GBP 432.34").rounded(-1, RoundingMode.DOWN); assertThat(test).hasToString("GBP 430.00"); } @Test void test_round_M1up() { - BigMoney test = BigMoney.parse("GBP 432.34").rounded(-1, RoundingMode.UP); + var test = BigMoney.parse("GBP 432.34").rounded(-1, RoundingMode.UP); assertThat(test).hasToString("GBP 440.00"); } @Test void test_round_3() { - BigMoney test = GBP_2_34.rounded(3, RoundingMode.DOWN); + var test = GBP_2_34.rounded(3, RoundingMode.DOWN); assertThat(test).isSameAs(GBP_2_34); } @@ -2474,37 +2438,37 @@ void test_round_3() { //----------------------------------------------------------------------- @Test void test_convertedTo_CurrencyUnit_BigDecimal_positive() { - BigMoney test = GBP_2_33.convertedTo(EUR, bd("2.5")); + var test = GBP_2_33.convertedTo(EUR, bd("2.5")); assertThat(test).hasToString("EUR 5.825"); } @Test void test_convertedTo_CurrencyUnit_BigDecimal_sameCurrencyCorrectFactor() { - BigMoney test = GBP_2_33.convertedTo(GBP, bd("1.00000")); + var test = GBP_2_33.convertedTo(GBP, bd("1.00000")); assertThat(test).isEqualTo(GBP_2_33); } @Test void test_convertedTo_CurrencyUnit_BigDecimal_negative() { - assertThatExceptionOfType(IllegalArgumentException.class) + assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> GBP_2_33.convertedTo(EUR, bd("-2.5"))); } @Test void test_convertedTo_CurrencyUnit_BigDecimal_sameCurrencyWrongFactor() { - assertThatExceptionOfType(IllegalArgumentException.class) + assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> GBP_2_33.convertedTo(GBP, bd("2.5"))); } @Test void test_convertedTo_CurrencyUnit_BigDecimal_nullCurrency() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> GBP_5_78.convertedTo((CurrencyUnit) null, bd("2"))); } @Test void test_convertedTo_CurrencyUnit_BigDecimal_nullBigDecimal() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> GBP_5_78.convertedTo(EUR, (BigDecimal) null)); } @@ -2513,43 +2477,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); + var test = BigMoney.parse("GBP 2.2").convertRetainScale(EUR, bd("2.5"), RoundingMode.DOWN); 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); + var test = BigMoney.parse("GBP 2.21").convertRetainScale(EUR, bd("2.5"), RoundingMode.HALF_UP); assertThat(test).hasToString("EUR 5.53"); } @Test void test_convertRetainScale_CurrencyUnit_BigDecimal_RoundingMode_negative() { - assertThatExceptionOfType(IllegalArgumentException.class) + assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> GBP_2_33.convertRetainScale(EUR, bd("-2.5"), RoundingMode.DOWN)); } @Test void test_convertRetainScale_CurrencyUnit_BigDecimal_RoundingMode_sameCurrency() { - assertThatExceptionOfType(IllegalArgumentException.class) + assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> GBP_2_33.convertRetainScale(GBP, bd("2.5"), RoundingMode.DOWN)); } @Test void test_convertRetainScale_CurrencyUnit_BigDecimal_RoundingMode_nullCurrency() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> GBP_5_78.convertRetainScale((CurrencyUnit) null, bd("2"), RoundingMode.DOWN)); } @Test void test_convertRetainScale_CurrencyUnit_BigDecimal_RoundingMode_nullBigDecimal() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> GBP_5_78.convertRetainScale(EUR, (BigDecimal) null, RoundingMode.DOWN)); } @Test void test_convertRetainScale_CurrencyUnit_BigDecimal_RoundingMode_nullRoundingMode() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> GBP_5_78.convertRetainScale(EUR, bd("2"), (RoundingMode) null)); } @@ -2579,7 +2543,7 @@ void test_toMoney_RoundingMode() { @Test void test_toMoney_RoundingMode_round() { - BigMoney money = BigMoney.parse("GBP 2.355"); + var money = BigMoney.parse("GBP 2.355"); assertThat(money.toMoney(RoundingMode.HALF_EVEN)).isEqualTo(Money.parse("GBP 2.36")); } @@ -2608,7 +2572,7 @@ void test_isSameCurrency_Money_different() { @Test void test_isSameCurrency_Money_nullMoney() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> GBP_2_34.isSameCurrency((BigMoney) null)); } @@ -2617,9 +2581,9 @@ void test_isSameCurrency_Money_nullMoney() { //----------------------------------------------------------------------- @Test void test_compareTo_BigMoney() { - BigMoney a = GBP_2_34; - BigMoney b = GBP_2_35; - BigMoney c = GBP_2_36; + var a = GBP_2_34; + var b = GBP_2_35; + var c = GBP_2_36; assertThat(a.compareTo(a)).isEqualTo(0); assertThat(b.compareTo(b)).isEqualTo(0); assertThat(c.compareTo(c)).isEqualTo(0); @@ -2636,10 +2600,10 @@ void test_compareTo_BigMoney() { @Test void test_compareTo_Money() { - BigMoney t = GBP_2_35; - Money a = Money.ofMinor(GBP, 234); - Money b = Money.ofMinor(GBP, 235); - Money c = Money.ofMinor(GBP, 236); + var t = GBP_2_35; + var a = Money.ofMinor(GBP, 234); + var b = Money.ofMinor(GBP, 235); + var c = Money.ofMinor(GBP, 236); assertThat(t.compareTo(a)).isEqualTo(1); assertThat(t.compareTo(b)).isEqualTo(0); assertThat(t.compareTo(c)).isEqualTo(-1); @@ -2647,9 +2611,9 @@ void test_compareTo_Money() { @Test void test_compareTo_currenciesDiffer() { - BigMoney a = GBP_2_34; - BigMoney b = USD_2_35; - assertThatExceptionOfType(CurrencyMismatchException.class) + var a = GBP_2_34; + var b = USD_2_35; + assertThatExceptionOfType(CurrencyMismatchException.class) .isThrownBy(() -> a.compareTo(b)); } @@ -2657,7 +2621,7 @@ void test_compareTo_currenciesDiffer() { @SuppressWarnings({"unchecked", "rawtypes"}) void test_compareTo_wrongType() { Comparable a = GBP_2_34; - assertThatExceptionOfType(ClassCastException.class) + assertThatExceptionOfType(ClassCastException.class) .isThrownBy(() -> a.compareTo("NotRightType")); } @@ -2666,9 +2630,9 @@ void test_compareTo_wrongType() { //----------------------------------------------------------------------- @Test void test_isEqual() { - BigMoney a = GBP_2_34; - BigMoney b = GBP_2_35; - BigMoney c = GBP_2_36; + var a = GBP_2_34; + var b = GBP_2_35; + var c = GBP_2_36; assertThat(a.isEqual(a)).isTrue(); assertThat(b.isEqual(b)).isTrue(); assertThat(c.isEqual(c)).isTrue(); @@ -2685,16 +2649,16 @@ void test_isEqual() { @Test void test_isEqual_Money() { - BigMoney a = GBP_2_34; - Money b = Money.ofMinor(GBP, 234); + var a = GBP_2_34; + var b = Money.ofMinor(GBP, 234); assertThat(a.isEqual(b)).isTrue(); } @Test void test_isEqual_currenciesDiffer() { - BigMoney a = GBP_2_34; - BigMoney b = USD_2_35; - assertThatExceptionOfType(CurrencyMismatchException.class) + var a = GBP_2_34; + var b = USD_2_35; + assertThatExceptionOfType(CurrencyMismatchException.class) .isThrownBy(() -> a.isEqual(b)); } @@ -2703,9 +2667,9 @@ void test_isEqual_currenciesDiffer() { //----------------------------------------------------------------------- @Test void test_isGreaterThan() { - BigMoney a = GBP_2_34; - BigMoney b = GBP_2_35; - BigMoney c = GBP_2_36; + var a = GBP_2_34; + var b = GBP_2_35; + var c = GBP_2_36; assertThat(a.isGreaterThan(a)).isFalse(); assertThat(a.isGreaterThan(b)).isFalse(); assertThat(a.isGreaterThan(c)).isFalse(); @@ -2721,9 +2685,9 @@ void test_isGreaterThan() { @Test void test_isGreaterThan_currenciesDiffer() { - BigMoney a = GBP_2_34; - BigMoney b = USD_2_35; - assertThatExceptionOfType(CurrencyMismatchException.class) + var a = GBP_2_34; + var b = USD_2_35; + assertThatExceptionOfType(CurrencyMismatchException.class) .isThrownBy(() -> a.isGreaterThan(b)); } @@ -2732,9 +2696,9 @@ void test_isGreaterThan_currenciesDiffer() { //----------------------------------------------------------------------- @Test void test_isGreaterThanOrEqual() { - BigMoney a = GBP_2_34; - BigMoney b = GBP_2_35; - BigMoney c = GBP_2_36; + var a = GBP_2_34; + var b = GBP_2_35; + var c = GBP_2_36; assertThat(a.isGreaterThanOrEqual(a)).isTrue(); assertThat(a.isGreaterThanOrEqual(b)).isFalse(); assertThat(a.isGreaterThanOrEqual(c)).isFalse(); @@ -2750,9 +2714,9 @@ void test_isGreaterThanOrEqual() { @Test void test_isGreaterThanOrEqual_currenciesDiffer() { - BigMoney a = GBP_2_34; - BigMoney b = USD_2_35; - assertThatExceptionOfType(CurrencyMismatchException.class) + var a = GBP_2_34; + var b = USD_2_35; + assertThatExceptionOfType(CurrencyMismatchException.class) .isThrownBy(() -> a.isGreaterThanOrEqual(b)); } @@ -2761,9 +2725,9 @@ void test_isGreaterThanOrEqual_currenciesDiffer() { //----------------------------------------------------------------------- @Test void test_isLessThan() { - BigMoney a = GBP_2_34; - BigMoney b = GBP_2_35; - BigMoney c = GBP_2_36; + var a = GBP_2_34; + var b = GBP_2_35; + var c = GBP_2_36; assertThat(a.isLessThan(a)).isFalse(); assertThat(a.isLessThan(b)).isTrue(); assertThat(a.isLessThan(c)).isTrue(); @@ -2779,9 +2743,9 @@ void test_isLessThan() { @Test void test_isLessThan_currenciesDiffer() { - BigMoney a = GBP_2_34; - BigMoney b = USD_2_35; - assertThatExceptionOfType(CurrencyMismatchException.class) + var a = GBP_2_34; + var b = USD_2_35; + assertThatExceptionOfType(CurrencyMismatchException.class) .isThrownBy(() -> a.isLessThan(b)); } @@ -2790,9 +2754,9 @@ void test_isLessThan_currenciesDiffer() { //----------------------------------------------------------------------- @Test void test_isLessThanOrEqual() { - BigMoney a = GBP_2_34; - BigMoney b = GBP_2_35; - BigMoney c = GBP_2_36; + var a = GBP_2_34; + var b = GBP_2_35; + var c = GBP_2_36; assertThat(a.isLessThanOrEqual(a)).isTrue(); assertThat(a.isLessThanOrEqual(b)).isTrue(); assertThat(a.isLessThanOrEqual(c)).isTrue(); @@ -2808,9 +2772,9 @@ void test_isLessThanOrEqual() { @Test void test_isLessThanOrEqual_currenciesDiffer() { - BigMoney a = GBP_2_34; - BigMoney b = USD_2_35; - assertThatExceptionOfType(CurrencyMismatchException.class) + var a = GBP_2_34; + var b = USD_2_35; + assertThatExceptionOfType(CurrencyMismatchException.class) .isThrownBy(() -> a.isLessThanOrEqual(b)); } @@ -2819,9 +2783,9 @@ void test_isLessThanOrEqual_currenciesDiffer() { //----------------------------------------------------------------------- @Test void test_equals_hashCode_positive() { - BigMoney a = GBP_2_34; - BigMoney b = GBP_2_34; - BigMoney c = GBP_2_35; + var a = GBP_2_34; + var b = GBP_2_34; + var c = GBP_2_35; assertThat(a).isEqualTo(a); assertThat(b).isEqualTo(b); assertThat(c).isEqualTo(c); @@ -2836,7 +2800,7 @@ void test_equals_hashCode_positive() { @Test void test_equals_false() { - BigMoney a = GBP_2_34; + var a = GBP_2_34; assertThat(a).isNotEqualTo(null); assertThat(new Object()).isNotEqualTo(a); } @@ -2846,13 +2810,13 @@ void test_equals_false() { //----------------------------------------------------------------------- @Test void test_toString_positive() { - BigMoney test = BigMoney.of(GBP, BIGDEC_2_34); + var test = BigMoney.of(GBP, BIGDEC_2_34); assertThat(test).hasToString("GBP 2.34"); } @Test void test_toString_negative() { - BigMoney test = BigMoney.of(EUR, BIGDEC_M5_78); + var test = BigMoney.of(EUR, BIGDEC_M5_78); 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 ed5dd07..33c9acf 100644 --- a/src/test/java/org/joda/money/TestCurrencyMismatchException.java +++ b/src/test/java/org/joda/money/TestCurrencyMismatchException.java @@ -32,7 +32,7 @@ class TestCurrencyMismatchException { //----------------------------------------------------------------------- @Test void test_new_GBPEUR() { - CurrencyMismatchException test = new CurrencyMismatchException(GBP, EUR); + var test = new CurrencyMismatchException(GBP, EUR); assertThat(test.getMessage()).isEqualTo("Currencies differ: GBP/EUR"); assertThat(test.getCause()).isNull(); assertThat(test.getFirstCurrency()).isEqualTo(GBP); @@ -41,7 +41,7 @@ void test_new_GBPEUR() { @Test void test_new_nullEUR() { - CurrencyMismatchException test = new CurrencyMismatchException(null, EUR); + var test = new CurrencyMismatchException(null, EUR); assertThat(test.getMessage()).isEqualTo("Currencies differ: null/EUR"); assertThat(test.getCause()).isNull(); assertThat(test.getFirstCurrency()).isNull(); @@ -50,7 +50,7 @@ void test_new_nullEUR() { @Test void test_new_GBPnull() { - CurrencyMismatchException test = new CurrencyMismatchException(GBP, null); + var test = new CurrencyMismatchException(GBP, null); assertThat(test.getMessage()).isEqualTo("Currencies differ: GBP/null"); assertThat(test.getCause()).isNull(); assertThat(test.getFirstCurrency()).isEqualTo(GBP); @@ -59,7 +59,7 @@ void test_new_GBPnull() { @Test void test_new_nullnull() { - CurrencyMismatchException test = new CurrencyMismatchException(null, null); + var test = new CurrencyMismatchException(null, null); assertThat(test.getMessage()).isEqualTo("Currencies differ: null/null"); assertThat(test.getCause()).isNull(); assertThat(test.getFirstCurrency()).isNull(); diff --git a/src/test/java/org/joda/money/TestCurrencyUnit.java b/src/test/java/org/joda/money/TestCurrencyUnit.java index 1bfa1dc..92dcc14 100644 --- a/src/test/java/org/joda/money/TestCurrencyUnit.java +++ b/src/test/java/org/joda/money/TestCurrencyUnit.java @@ -28,9 +28,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.Currency; -import java.util.List; import java.util.Locale; -import java.util.Set; import org.junit.jupiter.api.Test; @@ -46,8 +44,8 @@ class TestCurrencyUnit { //----------------------------------------------------------------------- @Test void test_registeredCurrencies() { - List curList = CurrencyUnit.registeredCurrencies(); - boolean found = false; + var curList = CurrencyUnit.registeredCurrencies(); + var found = false; for (CurrencyUnit currencyUnit : curList) { if (currencyUnit.getCode().equals("GBP")) { found = true; @@ -59,8 +57,8 @@ void test_registeredCurrencies() { @Test void test_registeredCurrencies_sorted() { - List curList1 = CurrencyUnit.registeredCurrencies(); - List curList2 = CurrencyUnit.registeredCurrencies(); + var curList1 = CurrencyUnit.registeredCurrencies(); + var curList2 = CurrencyUnit.registeredCurrencies(); Collections.sort(curList2); assertThat(curList1).isEqualTo(curList2); Collections.shuffle(curList2); @@ -70,115 +68,115 @@ void test_registeredCurrencies_sorted() { @Test void test_registeredCurrency_nullCode() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> CurrencyUnit.registerCurrency(null, 991, 2, Arrays.asList("TS"))); } @Test void test_registeredCurrency_invalidStringCode_empty() { - assertThatExceptionOfType(IllegalArgumentException.class) + assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> CurrencyUnit.registerCurrency("", 991, 2, Arrays.asList("TS"))); } @Test void test_registeredCurrency_invalidStringCode_1letter() { - assertThatExceptionOfType(IllegalArgumentException.class) + assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> CurrencyUnit.registerCurrency("A", 991, 2, Arrays.asList("TS"))); } @Test void test_registeredCurrency_invalidStringCode_2letters() { - assertThatExceptionOfType(IllegalArgumentException.class) + assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> CurrencyUnit.registerCurrency("AB", 991, 2, Arrays.asList("TS"))); } @Test void test_registeredCurrency_invalidStringCode_4letters() { - assertThatExceptionOfType(IllegalArgumentException.class) + assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> CurrencyUnit.registerCurrency("ABCD", 991, 2, Arrays.asList("TS"))); } @Test void test_registeredCurrency_invalidStringCode_lowerCase() { - assertThatExceptionOfType(IllegalArgumentException.class) + assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> CurrencyUnit.registerCurrency("xxA", 991, 2, Arrays.asList("xx"))); } @Test void test_registeredCurrency_invalidStringCode_number() { - assertThatExceptionOfType(IllegalArgumentException.class) + assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> CurrencyUnit.registerCurrency("123", 991, 2, Arrays.asList("TS"))); } @Test void test_registeredCurrency_invalidStringCode_dash() { - assertThatExceptionOfType(IllegalArgumentException.class) + assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> CurrencyUnit.registerCurrency("A-", 991, 2, Arrays.asList("TS"))); } @Test void test_registeredCurrency_invalidNumericCode_small() { - assertThatExceptionOfType(IllegalArgumentException.class) + assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> CurrencyUnit.registerCurrency("TST", -2, 2, Arrays.asList("TS"))); } @Test void test_registeredCurrency_invalidNumericCode_big() { - assertThatExceptionOfType(IllegalArgumentException.class) + assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> CurrencyUnit.registerCurrency("TST", 1000, 2, Arrays.asList("TS"))); } @Test void test_registeredCurrency_invalidDP_small() { - assertThatExceptionOfType(IllegalArgumentException.class) + assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> CurrencyUnit.registerCurrency("TST", 991, -2, Arrays.asList("TS"))); } @Test void test_registeredCurrency_invalidDP_big() { - assertThatExceptionOfType(IllegalArgumentException.class) + assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> CurrencyUnit.registerCurrency("TST", 991, 31, Arrays.asList("TS"))); } @Test void test_registeredCurrency_validDP_big() { - CurrencyUnit.registerCurrency("XLG", -1, 30, new ArrayList()); + CurrencyUnit.registerCurrency("XLG", -1, 30, new ArrayList<>()); - CurrencyUnit currency = CurrencyUnit.of("XLG"); + var currency = CurrencyUnit.of("XLG"); assertThat(currency.getDecimalPlaces()).isEqualTo(30); } @Test void test_registeredCurrency_nullCountry() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> CurrencyUnit.registerCurrency("TST", 991, 2, Arrays.asList((String) null))); } @Test void test_registeredCurrency_alreadyRegisteredCode() { - assertThatExceptionOfType(IllegalArgumentException.class) + assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> CurrencyUnit.registerCurrency("GBP", 991, 2, Arrays.asList("GB"))); } @Test void test_registeredCurrency_alreadyRegisteredNumericCode() { - assertThatExceptionOfType(IllegalArgumentException.class) + assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> CurrencyUnit.registerCurrency("TST", 826, 2, Arrays.asList("TS"))); } @Test void test_registeredCurrency_alreadyRegisteredCountry() { - assertThatExceptionOfType(IllegalArgumentException.class) + assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> CurrencyUnit.registerCurrency("GBX", 991, 2, Arrays.asList("GB"))); } @Test void test_registeredCurrencies_crossCheck() { - List curList = CurrencyUnit.registeredCurrencies(); + var curList = CurrencyUnit.registeredCurrencies(); for (CurrencyUnit currencyUnit : curList) { try { - Currency curr = Currency.getInstance(currencyUnit.getCode()); - int dp = curr.getDefaultFractionDigits() < 0 ? 0 : curr.getDefaultFractionDigits(); + var curr = Currency.getInstance(currencyUnit.getCode()); + var dp = curr.getDefaultFractionDigits() < 0 ? 0 : curr.getDefaultFractionDigits(); assertThat(currencyUnit.getDecimalPlaces()).as(curr.getCurrencyCode()).isEqualTo(dp); } catch (IllegalArgumentException ignored) { } @@ -190,7 +188,7 @@ void test_registeredCurrencies_crossCheck() { //----------------------------------------------------------------------- @Test void test_registeredCountries() { - List countryList = CurrencyUnit.registeredCountries(); + var countryList = CurrencyUnit.registeredCountries(); assertThat(countryList).contains("GB"); assertThat(countryList).contains("EU"); assertThat(countryList).contains("US"); @@ -198,8 +196,8 @@ void test_registeredCountries() { @Test void test_registeredCountries_sorted() { - List curList1 = CurrencyUnit.registeredCountries(); - List curList2 = CurrencyUnit.registeredCountries(); + var curList1 = CurrencyUnit.registeredCountries(); + var curList2 = CurrencyUnit.registeredCountries(); Collections.sort(curList2); assertThat(curList1).isEqualTo(curList2); Collections.shuffle(curList2); @@ -226,7 +224,7 @@ void test_constants() { //----------------------------------------------------------------------- @Test void test_constructor_nullCode() { - assertThatExceptionOfType(AssertionError.class) + assertThatExceptionOfType(AssertionError.class) .isThrownBy(() -> new CurrencyUnit(null, (short) 1, (short) 2)); } @@ -235,13 +233,13 @@ void test_constructor_nullCode() { //----------------------------------------------------------------------- @Test void test_factory_of_Currency() { - CurrencyUnit test = CurrencyUnit.of(JDK_GBP); + var test = CurrencyUnit.of(JDK_GBP); assertThat(test.getCode()).isEqualTo("GBP"); } @Test void test_factory_of_Currency_nullCurrency() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> CurrencyUnit.of((Currency) null)); } @@ -250,38 +248,38 @@ void test_factory_of_Currency_nullCurrency() { //----------------------------------------------------------------------- @Test void test_factory_of_String() { - CurrencyUnit test = CurrencyUnit.of("GBP"); + var test = CurrencyUnit.of("GBP"); assertThat(test.getCode()).isEqualTo("GBP"); } @Test void test_factory_of_String_nullString() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> CurrencyUnit.of((String) null)); } @Test void test_factory_of_String_unknownCurrency() { - assertThatExceptionOfType(IllegalCurrencyException.class) + assertThatExceptionOfType(IllegalCurrencyException.class) .isThrownBy(() -> CurrencyUnit.of("ABC")) .withMessage("Unknown currency 'ABC'"); } @Test void test_factory_of_String_empty() { - assertThatExceptionOfType(IllegalCurrencyException.class) + assertThatExceptionOfType(IllegalCurrencyException.class) .isThrownBy(() -> CurrencyUnit.of("")); } @Test void test_factory_of_String_tooShort_unknown() { - assertThatExceptionOfType(IllegalCurrencyException.class) + assertThatExceptionOfType(IllegalCurrencyException.class) .isThrownBy(() -> CurrencyUnit.of("AB")); } @Test void test_factory_of_String_tooLong_unknown() { - assertThatExceptionOfType(IllegalCurrencyException.class) + assertThatExceptionOfType(IllegalCurrencyException.class) .isThrownBy(() -> CurrencyUnit.of("ABCD")); } @@ -290,63 +288,63 @@ void test_factory_of_String_tooLong_unknown() { //----------------------------------------------------------------------- @Test void test_factory_ofNumericCode_String() { - CurrencyUnit test = CurrencyUnit.ofNumericCode("826"); + var test = CurrencyUnit.ofNumericCode("826"); assertThat(test.getCode()).isEqualTo("GBP"); } @Test void test_factory_ofNumericCode_String_2char() { - CurrencyUnit test = CurrencyUnit.ofNumericCode("051"); + var test = CurrencyUnit.ofNumericCode("051"); assertThat(test.getCode()).isEqualTo("AMD"); } @Test void test_factory_ofNumericCode_String_2charNoPad() { - CurrencyUnit test = CurrencyUnit.ofNumericCode("51"); + var test = CurrencyUnit.ofNumericCode("51"); assertThat(test.getCode()).isEqualTo("AMD"); } @Test void test_factory_ofNumericCode_String_1char() { - CurrencyUnit test = CurrencyUnit.ofNumericCode("008"); + var test = CurrencyUnit.ofNumericCode("008"); assertThat(test.getCode()).isEqualTo("ALL"); } @Test void test_factory_ofNumericCode_String_1charNoPad() { - CurrencyUnit test = CurrencyUnit.ofNumericCode("8"); + var test = CurrencyUnit.ofNumericCode("8"); assertThat(test.getCode()).isEqualTo("ALL"); } @Test void test_factory_ofNumericCode_String_nullString() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> CurrencyUnit.ofNumericCode((String) null)); } @Test void test_factory_ofNumericCode_String_unknownCurrency() { - assertThatExceptionOfType(IllegalCurrencyException.class) + assertThatExceptionOfType(IllegalCurrencyException.class) .isThrownBy(() -> CurrencyUnit.ofNumericCode("111")) .withMessage("Unknown currency '111'"); } @Test void test_factory_ofNumericCode_String_negative() { - assertThatExceptionOfType(IllegalCurrencyException.class) + assertThatExceptionOfType(IllegalCurrencyException.class) .isThrownBy(() -> CurrencyUnit.ofNumericCode("-1")); } @Test void test_factory_ofNumericCode_String_empty() { - assertThatExceptionOfType(IllegalCurrencyException.class) + assertThatExceptionOfType(IllegalCurrencyException.class) .isThrownBy(() -> CurrencyUnit.ofNumericCode("")) .withMessage("Unknown currency ''"); } @Test void test_factory_ofNumericCode_String_tooLong() { - assertThatExceptionOfType(IllegalCurrencyException.class) + assertThatExceptionOfType(IllegalCurrencyException.class) .isThrownBy(() -> CurrencyUnit.ofNumericCode("1234")) .withMessage("Unknown currency '1234'"); } @@ -356,39 +354,39 @@ void test_factory_ofNumericCode_String_tooLong() { //----------------------------------------------------------------------- @Test void test_factory_ofNumericCode_int() { - CurrencyUnit test = CurrencyUnit.ofNumericCode(826); + var test = CurrencyUnit.ofNumericCode(826); assertThat(test.getCode()).isEqualTo("GBP"); } @Test void test_factory_ofNumericCode_int_2char() { - CurrencyUnit test = CurrencyUnit.ofNumericCode(51); + var test = CurrencyUnit.ofNumericCode(51); assertThat(test.getCode()).isEqualTo("AMD"); } @Test void test_factory_ofNumericCode_int_1char() { - CurrencyUnit test = CurrencyUnit.ofNumericCode(8); + var test = CurrencyUnit.ofNumericCode(8); assertThat(test.getCode()).isEqualTo("ALL"); } @Test void test_factory_ofNumericCode_int_unknownCurrency() { - assertThatExceptionOfType(IllegalCurrencyException.class) + assertThatExceptionOfType(IllegalCurrencyException.class) .isThrownBy(() -> CurrencyUnit.ofNumericCode(111)) .withMessage("Unknown currency '111'"); } @Test void test_factory_ofNumericCode_int_negative() { - assertThatExceptionOfType(IllegalCurrencyException.class) + assertThatExceptionOfType(IllegalCurrencyException.class) .isThrownBy(() -> CurrencyUnit.ofNumericCode(-1)) .withMessage("Unknown currency '-1'"); } @Test void test_factory_ofNumericCode_int_tooLong() { - assertThatExceptionOfType(IllegalCurrencyException.class) + assertThatExceptionOfType(IllegalCurrencyException.class) .isThrownBy(() -> CurrencyUnit.ofNumericCode(1234)) .withMessage("Unknown currency '1234'"); } @@ -398,25 +396,25 @@ void test_factory_ofNumericCode_int_tooLong() { //----------------------------------------------------------------------- @Test void test_factory_of_LocaleUK() { - CurrencyUnit test = CurrencyUnit.of(Locale.UK); + var test = CurrencyUnit.of(Locale.UK); assertThat(test.getCode()).isEqualTo("GBP"); } @Test void test_factory_of_LocaleUS() { - CurrencyUnit test = CurrencyUnit.of(Locale.US); + var test = CurrencyUnit.of(Locale.US); assertThat(test.getCode()).isEqualTo("USD"); } @Test void test_factory_of_Locale_nullLocale() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> CurrencyUnit.of((Locale) null)); } @Test void test_factory_of_Locale_unknownCurrency() { - assertThatExceptionOfType(IllegalCurrencyException.class) + assertThatExceptionOfType(IllegalCurrencyException.class) .isThrownBy(() -> CurrencyUnit.of(new Locale("en", "XY"))) .withMessage("No currency found for locale 'en_XY'"); } @@ -426,19 +424,19 @@ void test_factory_of_Locale_unknownCurrency() { //----------------------------------------------------------------------- @Test void test_factory_ofCountry_String() { - CurrencyUnit test = CurrencyUnit.ofCountry("GB"); + var test = CurrencyUnit.ofCountry("GB"); assertThat(test.getCode()).isEqualTo("GBP"); } @Test void test_factory_ofCountry_String_nullString() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> CurrencyUnit.ofCountry((String) null)); } @Test void test_factory_ofCountry_String_unknownCurrency() { - assertThatExceptionOfType(IllegalCurrencyException.class) + assertThatExceptionOfType(IllegalCurrencyException.class) .isThrownBy(() -> CurrencyUnit.ofCountry("gb")) .withMessage("No currency found for country 'gb'"); } @@ -448,26 +446,26 @@ void test_factory_ofCountry_String_unknownCurrency() { //----------------------------------------------------------------------- @Test void test_serialization() throws Exception { - CurrencyUnit cu = CurrencyUnit.of("GBP"); - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - try (ObjectOutputStream oos = new ObjectOutputStream(baos)) { + var cu = CurrencyUnit.of("GBP"); + var baos = new ByteArrayOutputStream(); + try (var oos = new ObjectOutputStream(baos)) { oos.writeObject(cu); oos.close(); - ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); - CurrencyUnit input = (CurrencyUnit) ois.readObject(); + var ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); + var input = (CurrencyUnit) ois.readObject(); assertThat(input).isEqualTo(cu); } } @Test void test_serialization_invalidNumericCode() throws IOException { - CurrencyUnit cu = new CurrencyUnit("GBP", (short) 234, (short) 2); - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - try (ObjectOutputStream oos = new ObjectOutputStream(baos)) { + var cu = new CurrencyUnit("GBP", (short) 234, (short) 2); + var baos = new ByteArrayOutputStream(); + try (var oos = new ObjectOutputStream(baos)) { oos.writeObject(cu); oos.close(); - ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); - assertThatExceptionOfType(InvalidObjectException.class) + var ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); + assertThatExceptionOfType(InvalidObjectException.class) .isThrownBy(() -> ois.readObject()) .withMessageContaining("numeric code") .withMessageContaining("currency GBP"); @@ -476,12 +474,12 @@ void test_serialization_invalidNumericCode() throws IOException { @Test void test_serialization_invalidDecimalPlaces() throws IOException { - CurrencyUnit cu = new CurrencyUnit("GBP", (short) 826, (short) 1); - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - try (ObjectOutputStream oos = new ObjectOutputStream(baos)) { + var cu = new CurrencyUnit("GBP", (short) 826, (short) 1); + var baos = new ByteArrayOutputStream(); + try (var oos = new ObjectOutputStream(baos)) { oos.writeObject(cu); oos.close(); - ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); + var ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); assertThatExceptionOfType(InvalidObjectException.class) .isThrownBy(() -> ois.readObject()) .withMessageContaining("decimal places") @@ -494,25 +492,25 @@ void test_serialization_invalidDecimalPlaces() throws IOException { //----------------------------------------------------------------------- @Test void test_getNumeric3Code_GBP() { - CurrencyUnit test = CurrencyUnit.of("GBP"); + var test = CurrencyUnit.of("GBP"); assertThat(test.getNumeric3Code()).isEqualTo("826"); } @Test void test_getNumeric3Code_ALL() { - CurrencyUnit test = CurrencyUnit.of("ALL"); + var test = CurrencyUnit.of("ALL"); assertThat(test.getNumeric3Code()).isEqualTo("008"); } @Test void test_getNumeric3Code_AMD() { - CurrencyUnit test = CurrencyUnit.of("AMD"); + var test = CurrencyUnit.of("AMD"); assertThat(test.getNumeric3Code()).isEqualTo("051"); } @Test void test_getNumeric3Code_XFU() { - CurrencyUnit test = CurrencyUnit.of("XFU"); + var test = CurrencyUnit.of("XFU"); assertThat(test.getNumeric3Code()).isEmpty(); } @@ -521,7 +519,7 @@ void test_getNumeric3Code_XFU() { //----------------------------------------------------------------------- @Test void test_getNumericCode_GBP() { - CurrencyUnit test = CurrencyUnit.of("GBP"); + var test = CurrencyUnit.of("GBP"); assertThat(test.getNumericCode()).isEqualTo(826); } @@ -530,7 +528,7 @@ void test_getNumericCode_GBP() { //----------------------------------------------------------------------- @Test void test_getCurrencyCodes_GBP() { - Set test = CurrencyUnit.of("GBP").getCountryCodes(); + var test = CurrencyUnit.of("GBP").getCountryCodes(); assertThat(test).contains("GB"); assertThat(test).contains("IM"); assertThat(test).contains("JE"); @@ -542,19 +540,19 @@ void test_getCurrencyCodes_GBP() { //----------------------------------------------------------------------- @Test void test_getDecimalPlaces_GBP() { - CurrencyUnit test = CurrencyUnit.of("GBP"); + var test = CurrencyUnit.of("GBP"); assertThat(test.getDecimalPlaces()).isEqualTo(2); } @Test void test_getDecimalPlaces_JPY() { - CurrencyUnit test = CurrencyUnit.of("JPY"); + var test = CurrencyUnit.of("JPY"); assertThat(test.getDecimalPlaces()).isEqualTo(0); } @Test void test_getDecimalPlaces_XXX() { - CurrencyUnit test = CurrencyUnit.of("XXX"); + var test = CurrencyUnit.of("XXX"); assertThat(test.getDecimalPlaces()).isEqualTo(0); } @@ -563,19 +561,19 @@ void test_getDecimalPlaces_XXX() { //----------------------------------------------------------------------- @Test void test_isPseudoCurrency_GBP() { - CurrencyUnit test = CurrencyUnit.of("GBP"); + var test = CurrencyUnit.of("GBP"); assertThat(test.isPseudoCurrency()).isFalse(); } @Test void test_isPseudoCurrency_JPY() { - CurrencyUnit test = CurrencyUnit.of("JPY"); + var test = CurrencyUnit.of("JPY"); assertThat(test.isPseudoCurrency()).isFalse(); } @Test void test_isPseudoCurrency_XXX() { - CurrencyUnit test = CurrencyUnit.of("XXX"); + var test = CurrencyUnit.of("XXX"); assertThat(test.isPseudoCurrency()).isTrue(); } @@ -584,10 +582,10 @@ void test_isPseudoCurrency_XXX() { //----------------------------------------------------------------------- @Test void test_getSymbol_GBP() { - Locale loc = Locale.getDefault(); + var loc = Locale.getDefault(); try { Locale.setDefault(Locale.UK); - CurrencyUnit test = CurrencyUnit.of("GBP"); + var test = CurrencyUnit.of("GBP"); assertThat(test.getSymbol()).isEqualTo("\u00A3"); } finally { Locale.setDefault(loc); @@ -596,10 +594,10 @@ void test_getSymbol_GBP() { @Test void test_getSymbol_JPY() { - Locale loc = Locale.getDefault(); + var loc = Locale.getDefault(); try { Locale.setDefault(Locale.UK); - CurrencyUnit test = CurrencyUnit.of("JPY"); + var test = CurrencyUnit.of("JPY"); assertThat(test.getSymbol()).contains("JP"); } finally { Locale.setDefault(loc); @@ -608,10 +606,10 @@ void test_getSymbol_JPY() { @Test void test_getSymbol_TMT() { - Locale loc = Locale.getDefault(); + var loc = Locale.getDefault(); try { Locale.setDefault(Locale.UK); - CurrencyUnit test = CurrencyUnit.of("TMT"); + var test = CurrencyUnit.of("TMT"); assertThat(test.getSymbol()).isEqualTo("TMT"); } finally { Locale.setDefault(loc); @@ -620,10 +618,10 @@ void test_getSymbol_TMT() { @Test void test_getSymbol_XXX() { - Locale loc = Locale.getDefault(); + var loc = Locale.getDefault(); try { Locale.setDefault(Locale.UK); - CurrencyUnit test = CurrencyUnit.of("XXX"); + var test = CurrencyUnit.of("XXX"); assertThat(test.getSymbol()).isEqualTo("XXX"); } finally { Locale.setDefault(loc); @@ -635,10 +633,10 @@ void test_getSymbol_XXX() { //----------------------------------------------------------------------- @Test void test_getSymbol_Locale_GBP_UK() { - Locale loc = Locale.getDefault(); + var loc = Locale.getDefault(); try { Locale.setDefault(Locale.UK); - CurrencyUnit test = CurrencyUnit.of("GBP"); + var test = CurrencyUnit.of("GBP"); assertThat(test.getSymbol(Locale.UK)).isEqualTo("\u00A3"); } finally { Locale.setDefault(loc); @@ -647,10 +645,10 @@ void test_getSymbol_Locale_GBP_UK() { @Test void test_getSymbol_Locale_GBP_France() { - Locale loc = Locale.getDefault(); + var loc = Locale.getDefault(); try { Locale.setDefault(Locale.UK); - CurrencyUnit test = CurrencyUnit.of("GBP"); + var test = CurrencyUnit.of("GBP"); assertThat(test.getSymbol(Locale.FRANCE)).contains("GB"); } finally { Locale.setDefault(loc); @@ -659,10 +657,10 @@ void test_getSymbol_Locale_GBP_France() { @Test void test_getSymbol_Locale_USD_UK() { - Locale loc = Locale.getDefault(); + var loc = Locale.getDefault(); try { Locale.setDefault(Locale.UK); - CurrencyUnit test = CurrencyUnit.of("USD"); + var test = CurrencyUnit.of("USD"); assertThat(test.getSymbol(Locale.US)).isEqualTo("$"); } finally { Locale.setDefault(loc); @@ -671,10 +669,10 @@ void test_getSymbol_Locale_USD_UK() { @Test void test_getSymbol_Locale_USD_France() { - Locale loc = Locale.getDefault(); + var loc = Locale.getDefault(); try { Locale.setDefault(Locale.UK); - CurrencyUnit test = CurrencyUnit.of("USD"); + var test = CurrencyUnit.of("USD"); assertThat(test.getSymbol(Locale.FRANCE)).contains("US"); } finally { Locale.setDefault(loc); @@ -683,10 +681,10 @@ void test_getSymbol_Locale_USD_France() { @Test void test_getSymbol_Locale_JPY_Japan() { - Locale loc = Locale.getDefault(); + var loc = Locale.getDefault(); try { Locale.setDefault(Locale.UK); - CurrencyUnit test = CurrencyUnit.of("JPY"); + var test = CurrencyUnit.of("JPY"); assertThat(test.getSymbol(Locale.JAPAN)).isEqualTo("\uFFE5"); } finally { Locale.setDefault(loc); @@ -695,10 +693,10 @@ void test_getSymbol_Locale_JPY_Japan() { @Test void test_getSymbol_TMT_UK() { - Locale loc = Locale.getDefault(); + var loc = Locale.getDefault(); try { Locale.setDefault(Locale.UK); - CurrencyUnit test = CurrencyUnit.of("TMT"); + var test = CurrencyUnit.of("TMT"); assertThat(test.getSymbol(Locale.UK)).isEqualTo("TMT"); } finally { Locale.setDefault(loc); @@ -707,10 +705,10 @@ void test_getSymbol_TMT_UK() { @Test void test_getSymbol_Locale_XXX() { - Locale loc = Locale.getDefault(); + var loc = Locale.getDefault(); try { Locale.setDefault(Locale.UK); - CurrencyUnit test = CurrencyUnit.of("XXX"); + var test = CurrencyUnit.of("XXX"); assertThat(test.getSymbol(Locale.FRANCE)).isEqualTo("XXX"); test = CurrencyUnit.of("XXX"); assertThat(test.getSymbol(Locale.US)).isEqualTo("XXX"); @@ -724,7 +722,7 @@ void test_getSymbol_Locale_XXX() { //----------------------------------------------------------------------- @Test void test_toCurrency() { - CurrencyUnit test = CurrencyUnit.of("GBP"); + var test = CurrencyUnit.of("GBP"); assertThat(test.toCurrency()).isEqualTo(JDK_GBP); } @@ -733,9 +731,9 @@ void test_toCurrency() { //----------------------------------------------------------------------- @Test void test_compareTo() { - CurrencyUnit a = CurrencyUnit.of("EUR"); - CurrencyUnit b = CurrencyUnit.of("GBP"); - CurrencyUnit c = CurrencyUnit.of("JPY"); + var a = CurrencyUnit.of("EUR"); + var b = CurrencyUnit.of("GBP"); + var c = CurrencyUnit.of("JPY"); assertThat(a.compareTo(a)).isEqualTo(0); assertThat(b.compareTo(b)).isEqualTo(0); assertThat(c.compareTo(c)).isEqualTo(0); @@ -752,7 +750,7 @@ void test_compareTo() { @Test void test_compareTo_null() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> CurrencyUnit.of("EUR").compareTo(null)); } @@ -761,9 +759,9 @@ void test_compareTo_null() { //----------------------------------------------------------------------- @Test void test_equals_hashCode() { - CurrencyUnit a = CurrencyUnit.of("GBP"); - CurrencyUnit b = CurrencyUnit.of("GBP"); - CurrencyUnit c = CurrencyUnit.of("EUR"); + var a = CurrencyUnit.of("GBP"); + var b = CurrencyUnit.of("GBP"); + var c = CurrencyUnit.of("EUR"); assertThat(a).isEqualTo(a); assertThat(b).isEqualTo(b); assertThat(c).isEqualTo(c); @@ -778,7 +776,7 @@ void test_equals_hashCode() { @Test void test_equals_false() { - CurrencyUnit a = CurrencyUnit.of("GBP"); + var a = CurrencyUnit.of("GBP"); assertThat(a).isNotEqualTo(null); Object obj = "String"; // avoid warning in Eclipse assertThat(obj).isNotEqualTo(a); @@ -790,7 +788,7 @@ void test_equals_false() { //----------------------------------------------------------------------- @Test void test_toString() { - CurrencyUnit test = CurrencyUnit.of("GBP"); + var test = CurrencyUnit.of("GBP"); 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 35e9526..cd45c71 100644 --- a/src/test/java/org/joda/money/TestCurrencyUnitExtension.java +++ b/src/test/java/org/joda/money/TestCurrencyUnitExtension.java @@ -18,8 +18,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; -import java.util.List; - import org.junit.jupiter.api.Test; /** @@ -29,8 +27,8 @@ class TestCurrencyUnitExtension { @Test void test_CurrencyFromMoneyData() { - List curList = CurrencyUnit.registeredCurrencies(); - boolean found = false; + var curList = CurrencyUnit.registeredCurrencies(); + var found = false; for (CurrencyUnit currencyUnit : curList) { if (currencyUnit.getCode().equals("GBP")) { found = true; @@ -42,8 +40,8 @@ void test_CurrencyFromMoneyData() { @Test void test_CurrencyFromMoneyDataExtension() { - List curList = CurrencyUnit.registeredCurrencies(); - boolean found = false; + var curList = CurrencyUnit.registeredCurrencies(); + var found = false; for (CurrencyUnit currencyUnit : curList) { if (currencyUnit.getCode().equals("BTC")) { found = true; @@ -55,8 +53,8 @@ void test_CurrencyFromMoneyDataExtension() { @Test void test_LargerDecimalPrecisionCurrencyFromMoneyDataExtension() { - List curList = CurrencyUnit.registeredCurrencies(); - boolean found = false; + var curList = CurrencyUnit.registeredCurrencies(); + var found = false; for (CurrencyUnit currencyUnit : curList) { if (currencyUnit.getCode().equals("ETH")) { found = true; @@ -87,7 +85,7 @@ void test_CurrencyMissing() { @Test void test_CurrencyEURChanged() { - CurrencyUnit currency = CurrencyUnit.ofCountry("HU"); + var currency = CurrencyUnit.ofCountry("HU"); 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 45b31a7..69d25ee 100644 --- a/src/test/java/org/joda/money/TestIllegalCurrencyException.java +++ b/src/test/java/org/joda/money/TestIllegalCurrencyException.java @@ -29,14 +29,14 @@ class TestIllegalCurrencyException { //----------------------------------------------------------------------- @Test void test_String() { - IllegalCurrencyException test = new IllegalCurrencyException("PROBLEM"); + var test = new IllegalCurrencyException("PROBLEM"); assertThat(test.getMessage()).isEqualTo("PROBLEM"); assertThat(test.getCause()).isNull(); } @Test void test_String_nullString() { - IllegalCurrencyException test = new IllegalCurrencyException(null); + var test = new IllegalCurrencyException(null); 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 ef1e500..7e62986 100644 --- a/src/test/java/org/joda/money/TestMoney.java +++ b/src/test/java/org/joda/money/TestMoney.java @@ -26,7 +26,6 @@ import java.io.InvalidObjectException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; -import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Modifier; import java.math.BigDecimal; @@ -84,7 +83,7 @@ class TestMoney { //----------------------------------------------------------------------- @Test void test_factory_of_Currency_BigDecimal() { - Money test = Money.of(GBP, BIGDEC_2_34); + var test = Money.of(GBP, BIGDEC_2_34); assertThat(test.getCurrencyUnit()).isEqualTo(GBP); assertThat(test.getAmountMinorInt()).isEqualTo(234); assertThat(test.getAmount().scale()).isEqualTo(2); @@ -92,7 +91,7 @@ void test_factory_of_Currency_BigDecimal() { @Test void test_factory_of_Currency_BigDecimal_correctScale() { - Money test = Money.of(GBP, BIGDEC_2_3); + var test = Money.of(GBP, BIGDEC_2_3); assertThat(test.getCurrencyUnit()).isEqualTo(GBP); assertThat(test.getAmountMinorInt()).isEqualTo(230); assertThat(test.getAmount().scale()).isEqualTo(2); @@ -100,25 +99,25 @@ void test_factory_of_Currency_BigDecimal_correctScale() { @Test void test_factory_of_Currency_BigDecimal_invalidScaleGBP() { - assertThatExceptionOfType(ArithmeticException.class) + assertThatExceptionOfType(ArithmeticException.class) .isThrownBy(() -> Money.of(GBP, BIGDEC_2_345)); } @Test void test_factory_of_Currency_BigDecimal_invalidScaleJPY() { - assertThatExceptionOfType(ArithmeticException.class) + assertThatExceptionOfType(ArithmeticException.class) .isThrownBy(() -> Money.of(JPY, BIGDEC_2_3)); } @Test void test_factory_of_Currency_BigDecimal_nullCurrency() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> Money.of((CurrencyUnit) null, BIGDEC_2_34)); } @Test void test_factory_of_Currency_BigDecimal_nullBigDecimal() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> Money.of(GBP, (BigDecimal) null)); } @@ -127,7 +126,7 @@ 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); + var test = Money.of(GBP, BIGDEC_2_34, RoundingMode.DOWN); assertThat(test.getCurrencyUnit()).isEqualTo(GBP); assertThat(test.getAmountMinorInt()).isEqualTo(234); assertThat(test.getAmount().scale()).isEqualTo(2); @@ -135,7 +134,7 @@ void test_factory_of_Currency_BigDecimal_GBP_RoundingMode_DOWN() { @Test void test_factory_of_Currency_BigDecimal_JPY_RoundingMode_DOWN() { - Money test = Money.of(JPY, BIGDEC_2_34, RoundingMode.DOWN); + var test = Money.of(JPY, BIGDEC_2_34, RoundingMode.DOWN); assertThat(test.getCurrencyUnit()).isEqualTo(JPY); assertThat(test.getAmountMinorInt()).isEqualTo(2); assertThat(test.getAmount().scale()).isEqualTo(0); @@ -143,7 +142,7 @@ void test_factory_of_Currency_BigDecimal_JPY_RoundingMode_DOWN() { @Test void test_factory_of_Currency_BigDecimal_JPY_RoundingMode_UP() { - Money test = Money.of(JPY, BIGDEC_2_34, RoundingMode.UP); + var test = Money.of(JPY, BIGDEC_2_34, RoundingMode.UP); assertThat(test.getCurrencyUnit()).isEqualTo(JPY); assertThat(test.getAmountMinorInt()).isEqualTo(3); assertThat(test.getAmount().scale()).isEqualTo(0); @@ -151,25 +150,25 @@ void test_factory_of_Currency_BigDecimal_JPY_RoundingMode_UP() { @Test void test_factory_of_Currency_BigDecimal_RoundingMode_UNNECESSARY() { - assertThatExceptionOfType(ArithmeticException.class) + assertThatExceptionOfType(ArithmeticException.class) .isThrownBy(() -> Money.of(JPY, BIGDEC_2_34, RoundingMode.UNNECESSARY)); } @Test void test_factory_of_Currency_BigDecimal_RoundingMode_nullCurrency() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> Money.of((CurrencyUnit) null, BIGDEC_2_34, RoundingMode.DOWN)); } @Test void test_factory_of_Currency_BigDecimal_RoundingMode_nullBigDecimal() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> Money.of(GBP, (BigDecimal) null, RoundingMode.DOWN)); } @Test void test_factory_of_Currency_BigDecimal_RoundingMode_nullRoundingMode() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> Money.of(GBP, BIGDEC_2_34, (RoundingMode) null)); } @@ -178,7 +177,7 @@ void test_factory_of_Currency_BigDecimal_RoundingMode_nullRoundingMode() { //----------------------------------------------------------------------- @Test void test_factory_of_Currency_double() { - Money test = Money.of(GBP, 2.34d); + var test = Money.of(GBP, 2.34d); assertThat(test.getCurrencyUnit()).isEqualTo(GBP); assertThat(test.getAmountMinorInt()).isEqualTo(234); assertThat(test.getScale()).isEqualTo(2); @@ -186,7 +185,7 @@ void test_factory_of_Currency_double() { @Test void test_factory_of_Currency_double_correctScale() { - Money test = Money.of(GBP, 2.3d); + var test = Money.of(GBP, 2.3d); assertThat(test.getCurrencyUnit()).isEqualTo(GBP); assertThat(test.getAmountMinorInt()).isEqualTo(230); assertThat(test.getScale()).isEqualTo(2); @@ -194,7 +193,7 @@ void test_factory_of_Currency_double_correctScale() { @Test void test_factory_of_Currency_double_trailingZero1() { - Money test = Money.of(GBP, 1.230d); + var test = Money.of(GBP, 1.230d); assertThat(test.getCurrencyUnit()).isEqualTo(GBP); assertThat(test.getAmount()).isEqualTo(BigDecimal.valueOf(123L, 2)); assertThat(test.getScale()).isEqualTo(2); @@ -202,7 +201,7 @@ void test_factory_of_Currency_double_trailingZero1() { @Test void test_factory_of_Currency_double_trailingZero2() { - Money test = Money.of(GBP, 1.20d); + var test = Money.of(GBP, 1.20d); assertThat(test.getCurrencyUnit()).isEqualTo(GBP); assertThat(test.getAmount()).isEqualTo(BigDecimal.valueOf(120L, 2)); assertThat(test.getScale()).isEqualTo(2); @@ -210,7 +209,7 @@ void test_factory_of_Currency_double_trailingZero2() { @Test void test_factory_of_Currency_double_medium() { - Money test = Money.of(GBP, 2000d); + var test = Money.of(GBP, 2000d); assertThat(test.getCurrencyUnit()).isEqualTo(GBP); assertThat(test.getAmount()).isEqualTo(BigDecimal.valueOf(200000L, 2)); assertThat(test.getScale()).isEqualTo(2); @@ -218,7 +217,7 @@ void test_factory_of_Currency_double_medium() { @Test void test_factory_of_Currency_double_big() { - Money test = Money.of(GBP, 200000000d); + var test = Money.of(GBP, 200000000d); assertThat(test.getCurrencyUnit()).isEqualTo(GBP); assertThat(test.getAmount()).isEqualTo(BigDecimal.valueOf(20000000000L, 2)); assertThat(test.getScale()).isEqualTo(2); @@ -226,19 +225,19 @@ void test_factory_of_Currency_double_big() { @Test void test_factory_of_Currency_double_invalidScaleGBP() { - assertThatExceptionOfType(ArithmeticException.class) + assertThatExceptionOfType(ArithmeticException.class) .isThrownBy(() -> Money.of(GBP, 2.345d)); } @Test void test_factory_of_Currency_double_invalidScaleJPY() { - assertThatExceptionOfType(ArithmeticException.class) + assertThatExceptionOfType(ArithmeticException.class) .isThrownBy(() -> Money.of(JPY, 2.3d)); } @Test void test_factory_of_Currency_double_nullCurrency() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> Money.of((CurrencyUnit) null, BIGDEC_2_34)); } @@ -247,7 +246,7 @@ 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); + var test = Money.of(GBP, 2.34d, RoundingMode.DOWN); assertThat(test.getCurrencyUnit()).isEqualTo(GBP); assertThat(test.getAmountMinorInt()).isEqualTo(234); assertThat(test.getAmount().scale()).isEqualTo(2); @@ -255,7 +254,7 @@ void test_factory_of_Currency_double_GBP_RoundingMode_DOWN() { @Test void test_factory_of_Currency_double_JPY_RoundingMode_DOWN() { - Money test = Money.of(JPY, 2.34d, RoundingMode.DOWN); + var test = Money.of(JPY, 2.34d, RoundingMode.DOWN); assertThat(test.getCurrencyUnit()).isEqualTo(JPY); assertThat(test.getAmountMinorInt()).isEqualTo(2); assertThat(test.getAmount().scale()).isEqualTo(0); @@ -263,7 +262,7 @@ void test_factory_of_Currency_double_JPY_RoundingMode_DOWN() { @Test void test_factory_of_Currency_double_JPY_RoundingMode_UP() { - Money test = Money.of(JPY, 2.34d, RoundingMode.UP); + var test = Money.of(JPY, 2.34d, RoundingMode.UP); assertThat(test.getCurrencyUnit()).isEqualTo(JPY); assertThat(test.getAmountMinorInt()).isEqualTo(3); assertThat(test.getAmount().scale()).isEqualTo(0); @@ -271,19 +270,19 @@ void test_factory_of_Currency_double_JPY_RoundingMode_UP() { @Test void test_factory_of_Currency_double_RoundingMode_UNNECESSARY() { - assertThatExceptionOfType(ArithmeticException.class) + assertThatExceptionOfType(ArithmeticException.class) .isThrownBy(() -> Money.of(JPY, 2.34d, RoundingMode.UNNECESSARY)); } @Test void test_factory_of_Currency_double_RoundingMode_nullCurrency() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> Money.of((CurrencyUnit) null, 2.34d, RoundingMode.DOWN)); } @Test void test_factory_of_Currency_double_RoundingMode_nullRoundingMode() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> Money.of(GBP, 2.34d, (RoundingMode) null)); } @@ -292,7 +291,7 @@ void test_factory_of_Currency_double_RoundingMode_nullRoundingMode() { //----------------------------------------------------------------------- @Test void test_factory_ofMajor_Currency_long() { - Money test = Money.ofMajor(GBP, 234); + var test = Money.ofMajor(GBP, 234); assertThat(test.getCurrencyUnit()).isEqualTo(GBP); assertThat(test.getAmountMinorInt()).isEqualTo(23400); assertThat(test.getAmount().scale()).isEqualTo(2); @@ -300,7 +299,7 @@ void test_factory_ofMajor_Currency_long() { @Test void test_factory_ofMajor_Currency_long_nullCurrency() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> Money.ofMajor((CurrencyUnit) null, 234)); } @@ -309,7 +308,7 @@ void test_factory_ofMajor_Currency_long_nullCurrency() { //----------------------------------------------------------------------- @Test void test_factory_ofMinor_Currency_long() { - Money test = Money.ofMinor(GBP, 234); + var test = Money.ofMinor(GBP, 234); assertThat(test.getCurrencyUnit()).isEqualTo(GBP); assertThat(test.getAmountMinorInt()).isEqualTo(234); assertThat(test.getAmount().scale()).isEqualTo(2); @@ -317,7 +316,7 @@ void test_factory_ofMinor_Currency_long() { @Test void test_factory_ofMinor_Currency_long_nullCurrency() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> Money.ofMinor((CurrencyUnit) null, 234)); } @@ -326,7 +325,7 @@ void test_factory_ofMinor_Currency_long_nullCurrency() { //----------------------------------------------------------------------- @Test void test_factory_zero_Currency() { - Money test = Money.zero(GBP); + var test = Money.zero(GBP); assertThat(test.getCurrencyUnit()).isEqualTo(GBP); assertThat(test.getAmountMinorInt()).isEqualTo(0); assertThat(test.getAmount().scale()).isEqualTo(2); @@ -334,7 +333,7 @@ void test_factory_zero_Currency() { @Test void test_factory_zero_Currency_nullCurrency() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> Money.zero((CurrencyUnit) null)); } @@ -343,7 +342,7 @@ void test_factory_zero_Currency_nullCurrency() { //----------------------------------------------------------------------- @Test void test_factory_from_BigMoneyProvider() { - Money test = Money.of(BigMoney.parse("GBP 104.23")); + var test = Money.of(BigMoney.parse("GBP 104.23")); assertThat(test.getCurrencyUnit()).isEqualTo(GBP); assertThat(test.getAmountMinorInt()).isEqualTo(10423); assertThat(test.getAmount().scale()).isEqualTo(2); @@ -351,7 +350,7 @@ void test_factory_from_BigMoneyProvider() { @Test void test_factory_from_BigMoneyProvider_fixScale() { - Money test = Money.of(BigMoney.parse("GBP 104.2")); + var test = Money.of(BigMoney.parse("GBP 104.2")); assertThat(test.getCurrencyUnit()).isEqualTo(GBP); assertThat(test.getAmountMinorInt()).isEqualTo(10420); assertThat(test.getAmount().scale()).isEqualTo(2); @@ -359,13 +358,13 @@ void test_factory_from_BigMoneyProvider_fixScale() { @Test void test_factory_from_BigMoneyProvider_invalidCurrencyScale() { - assertThatExceptionOfType(ArithmeticException.class) + assertThatExceptionOfType(ArithmeticException.class) .isThrownBy(() -> Money.of(BigMoney.parse("GBP 104.235"))); } @Test void test_factory_from_BigMoneyProvider_nullBigMoneyProvider() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> Money.of((BigMoneyProvider) null)); } @@ -374,7 +373,7 @@ 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); + var test = Money.of(BigMoney.parse("GBP 104.235"), RoundingMode.HALF_EVEN); assertThat(test.getCurrencyUnit()).isEqualTo(GBP); assertThat(test.getAmountMinorInt()).isEqualTo(10424); assertThat(test.getAmount().scale()).isEqualTo(2); @@ -382,13 +381,13 @@ void test_factory_from_BigMoneyProvider_RoundingMode() { @Test void test_factory_from_BigMoneyProvider_RoundingMode_nullBigMoneyProvider() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> Money.of((BigMoneyProvider) null, RoundingMode.DOWN)); } @Test void test_factory_from_BigMoneyProvider_RoundingMode_nullRoundingMode() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> Money.of(BigMoney.parse("GBP 104.235"), (RoundingMode) null)); } @@ -397,43 +396,43 @@ void test_factory_from_BigMoneyProvider_RoundingMode_nullRoundingMode() { //----------------------------------------------------------------------- @Test void test_factory_total_varargs_1() { - Money test = Money.total(GBP_1_23); + var test = Money.total(GBP_1_23); 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); + var array = new Money[] {GBP_1_23}; + var test = Money.total(array); 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); + var test = Money.total(GBP_1_23, GBP_2_33, GBP_2_36); 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); + var array = new Money[] {GBP_1_23, GBP_2_33, GBP_2_36}; + var test = Money.total(array); assertThat(test.getCurrencyUnit()).isEqualTo(GBP); assertThat(test.getAmountMinorInt()).isEqualTo(592); } @Test void test_factory_total_varargs_empty() { - assertThatExceptionOfType(IllegalArgumentException.class) + assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> Money.total()); } @Test void test_factory_total_array_empty() { - Money[] array = new Money[0]; + var array = new Money[0]; assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> Money.total(array)); } @@ -457,7 +456,7 @@ void test_factory_total_array_currenciesDiffer() { assertThatExceptionOfType(CurrencyMismatchException.class) .isThrownBy(() -> { try { - Money[] array = new Money[] {GBP_2_33, JPY_423}; + var array = new Money[] {GBP_2_33, JPY_423}; Money.total(array); } catch (CurrencyMismatchException ex) { assertEquals(GBP, ex.getFirstCurrency()); @@ -469,27 +468,27 @@ void test_factory_total_array_currenciesDiffer() { @Test void test_factory_total_varargs_nullFirst() { - assertThatExceptionOfType(NullPointerException.class) + 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}; - assertThatExceptionOfType(NullPointerException.class) + var array = new Money[] {null, GBP_2_33, GBP_2_36}; + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> Money.total(array)); } @Test void test_factory_total_varargs_nullNotFirst() { - assertThatExceptionOfType(NullPointerException.class) + 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}; - assertThatExceptionOfType(NullPointerException.class) + var array = new Money[] {GBP_2_33, null, GBP_2_36}; + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> Money.total(array)); } @@ -499,7 +498,7 @@ void test_factory_total_array_nullNotFirst() { @Test void test_factory_total_Iterable() { Iterable iterable = Arrays.asList(GBP_1_23, GBP_2_33, GBP_2_36); - Money test = Money.total(iterable); + var test = Money.total(iterable); assertThat(test.getCurrencyUnit()).isEqualTo(GBP); assertThat(test.getAmountMinorInt()).isEqualTo(592); } @@ -507,7 +506,7 @@ void test_factory_total_Iterable() { @Test void test_factory_total_Iterable_empty() { Iterable iterable = Collections.emptyList(); - assertThatExceptionOfType(IllegalArgumentException.class) + assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> Money.total(iterable)); } @@ -529,14 +528,14 @@ void test_factory_total_Iterable_currenciesDiffer() { @Test void test_factory_total_Iterable_nullFirst() { Iterable iterable = Arrays.asList(null, GBP_2_33, GBP_2_36); - assertThatExceptionOfType(NullPointerException.class) + 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); - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> Money.total(iterable)); } @@ -545,45 +544,45 @@ void test_factory_total_Iterable_nullNotFirst() { //----------------------------------------------------------------------- @Test void test_factory_total_CurrencyUnitVarargs_1() { - Money test = Money.total(GBP, GBP_1_23); + var test = Money.total(GBP, GBP_1_23); 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); + var array = new Money[] {GBP_1_23}; + var test = Money.total(GBP, array); 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); + var test = Money.total(GBP, GBP_1_23, GBP_2_33, GBP_2_36); 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); + var array = new Money[] {GBP_1_23, GBP_2_33, GBP_2_36}; + var test = Money.total(GBP, array); assertThat(test.getCurrencyUnit()).isEqualTo(GBP); assertThat(test.getAmountMinorInt()).isEqualTo(592); } @Test void test_factory_total_CurrencyUnitVarargs_empty() { - Money test = Money.total(GBP); + var test = Money.total(GBP); 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); + var array = new Money[0]; + var test = Money.total(GBP, array); assertThat(test.getCurrencyUnit()).isEqualTo(GBP); assertThat(test.getAmountMinorInt()).isEqualTo(0); } @@ -604,7 +603,7 @@ void test_factory_total_CurrencyUnitVarargs_currenciesDiffer() { @Test void test_factory_total_CurrencyUnitArray_currenciesDiffer() { - Money[] array = new Money[] {JPY_423}; + var array = new Money[] {JPY_423}; assertThatExceptionOfType(CurrencyMismatchException.class) .isThrownBy(() -> { try { @@ -633,7 +632,7 @@ void test_factory_total_CurrencyUnitVarargs_currenciesDifferInArray() { @Test void test_factory_total_CurrencyUnitArray_currenciesDifferInArray() { - Money[] array = new Money[] {GBP_2_33, JPY_423}; + var array = new Money[] {GBP_2_33, JPY_423}; assertThatExceptionOfType(CurrencyMismatchException.class) .isThrownBy(() -> { try { @@ -648,27 +647,27 @@ void test_factory_total_CurrencyUnitArray_currenciesDifferInArray() { @Test void test_factory_total_CurrencyUnitVarargs_nullFirst() { - assertThatExceptionOfType(NullPointerException.class) + 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}; - assertThatExceptionOfType(NullPointerException.class) + var array = new Money[] {null, GBP_2_33, GBP_2_36}; + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> Money.total(GBP, array)); } @Test void test_factory_total_CurrencyUnitVarargs_nullNotFirst() { - assertThatExceptionOfType(NullPointerException.class) + 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}; - assertThatExceptionOfType(NullPointerException.class) + var array = new Money[] {GBP_2_33, null, GBP_2_36}; + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> Money.total(GBP, array)); } @@ -678,7 +677,7 @@ void test_factory_total_CurrencyUnitArray_nullNotFirst() { @Test void test_factory_total_CurrencyUnitIterable() { Iterable iterable = Arrays.asList(GBP_1_23, GBP_2_33, GBP_2_36); - Money test = Money.total(GBP, iterable); + var test = Money.total(GBP, iterable); assertThat(test.getCurrencyUnit()).isEqualTo(GBP); assertThat(test.getAmountMinorInt()).isEqualTo(592); } @@ -686,7 +685,7 @@ void test_factory_total_CurrencyUnitIterable() { @Test void test_factory_total_CurrencyUnitIterable_empty() { Iterable iterable = Collections.emptyList(); - Money test = Money.total(GBP, iterable); + var test = Money.total(GBP, iterable); assertThat(test.getCurrencyUnit()).isEqualTo(GBP); assertThat(test.getAmountMinorInt()).isEqualTo(0); } @@ -724,14 +723,14 @@ void test_factory_total_CurrencyUnitIterable_currenciesDifferInIterable() { @Test void test_factory_total_CurrencyUnitIterable_nullFirst() { Iterable iterable = Arrays.asList(null, GBP_2_33, GBP_2_36); - assertThatExceptionOfType(NullPointerException.class) + 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); - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> Money.total(GBP, iterable)); } @@ -763,26 +762,26 @@ public static Object[][] data_parse() { @ParameterizedTest @MethodSource("data_parse") void test_factory_parse(String str, CurrencyUnit currency, int amount) { - Money test = Money.parse(str); + var test = Money.parse(str); assertThat(test.getCurrencyUnit()).isEqualTo(currency); assertThat(test.getAmountMinorInt()).isEqualTo(amount); } @Test void test_factory_parse_String_tooShort() { - assertThatExceptionOfType(IllegalArgumentException.class) + assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> Money.parse("GBP ")); } @Test void test_factory_parse_String_badCurrency() { - assertThatExceptionOfType(IllegalArgumentException.class) + assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> Money.parse("GBX 2.34")); } @Test void test_factory_parse_String_nullString() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> Money.parse((String) null)); } @@ -791,7 +790,7 @@ void test_factory_parse_String_nullString() { //----------------------------------------------------------------------- @Test void test_constructor_null1() throws Exception { - Constructor con = Money.class.getDeclaredConstructor(BigMoney.class); + var con = Money.class.getDeclaredConstructor(BigMoney.class); assertThat(Modifier.isPublic(con.getModifiers())).isFalse(); assertThat(Modifier.isProtected(con.getModifiers())).isFalse(); try { @@ -805,7 +804,7 @@ void test_constructor_null1() throws Exception { @Test void test_constructor_scale() throws Exception { - Constructor con = Money.class.getDeclaredConstructor(BigMoney.class); + var con = Money.class.getDeclaredConstructor(BigMoney.class); try { con.setAccessible(true); con.newInstance(new Object[] {BigMoney.of(GBP, BIGDEC_2_3)}); @@ -820,41 +819,41 @@ void test_constructor_scale() throws Exception { //----------------------------------------------------------------------- @Test void test_serialization() throws Exception { - Money a = GBP_2_34; - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - try (ObjectOutputStream oos = new ObjectOutputStream(baos)) { + var a = GBP_2_34; + var baos = new ByteArrayOutputStream(); + try (var oos = new ObjectOutputStream(baos)) { oos.writeObject(a); oos.close(); - ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); - Money input = (Money) ois.readObject(); + var ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); + var input = (Money) ois.readObject(); assertThat(input).isEqualTo(a); } } @Test void test_serialization_invalidNumericCode() throws IOException { - CurrencyUnit cu = new CurrencyUnit("GBP", (short) 234, (short) 2); - Money m = Money.of(cu, 123.43d); - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - try (ObjectOutputStream oos = new ObjectOutputStream(baos)) { + var cu = new CurrencyUnit("GBP", (short) 234, (short) 2); + var m = Money.of(cu, 123.43d); + var baos = new ByteArrayOutputStream(); + try (var oos = new ObjectOutputStream(baos)) { oos.writeObject(m); oos.close(); - ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); - assertThatExceptionOfType(InvalidObjectException.class) + var ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); + assertThatExceptionOfType(InvalidObjectException.class) .isThrownBy(() -> ois.readObject()); } } @Test void test_serialization_invalidDecimalPlaces() throws IOException { - CurrencyUnit cu = new CurrencyUnit("GBP", (short) 826, (short) 3); - Money m = Money.of(cu, 123.43d); - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - try (ObjectOutputStream oos = new ObjectOutputStream(baos)) { + var cu = new CurrencyUnit("GBP", (short) 826, (short) 3); + var m = Money.of(cu, 123.43d); + var baos = new ByteArrayOutputStream(); + try (var oos = new ObjectOutputStream(baos)) { oos.writeObject(m); oos.close(); - ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); - assertThatExceptionOfType(InvalidObjectException.class) + var ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); + assertThatExceptionOfType(InvalidObjectException.class) .isThrownBy(() -> ois.readObject()); } } @@ -877,25 +876,25 @@ void test_getCurrencyUnit_EUR() { //----------------------------------------------------------------------- @Test void test_withCurrencyUnit_Currency() { - Money test = GBP_2_34.withCurrencyUnit(USD); + var test = GBP_2_34.withCurrencyUnit(USD); assertThat(test).hasToString("USD 2.34"); } @Test void test_withCurrencyUnit_Currency_same() { - Money test = GBP_2_34.withCurrencyUnit(GBP); + var test = GBP_2_34.withCurrencyUnit(GBP); assertThat(test).isSameAs(GBP_2_34); } @Test void test_withCurrencyUnit_Currency_scaleProblem() { - assertThatExceptionOfType(ArithmeticException.class) + assertThatExceptionOfType(ArithmeticException.class) .isThrownBy(() -> GBP_2_34.withCurrencyUnit(JPY)); } @Test void test_withCurrencyUnit_Currency_nullCurrency() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> GBP_2_34.withCurrencyUnit((CurrencyUnit) null)); } @@ -904,31 +903,31 @@ void test_withCurrencyUnit_Currency_nullCurrency() { //----------------------------------------------------------------------- @Test void test_withCurrencyUnit_CurrencyRoundingMode_DOWN() { - Money test = GBP_2_34.withCurrencyUnit(JPY, RoundingMode.DOWN); + var test = GBP_2_34.withCurrencyUnit(JPY, RoundingMode.DOWN); assertThat(test).hasToString("JPY 2"); } @Test void test_withCurrencyUnit_CurrencyRoundingMode_UP() { - Money test = GBP_2_34.withCurrencyUnit(JPY, RoundingMode.UP); + var test = GBP_2_34.withCurrencyUnit(JPY, RoundingMode.UP); assertThat(test).hasToString("JPY 3"); } @Test void test_withCurrencyUnit_CurrencyRoundingMode_same() { - Money test = GBP_2_34.withCurrencyUnit(GBP, RoundingMode.DOWN); + var test = GBP_2_34.withCurrencyUnit(GBP, RoundingMode.DOWN); assertThat(test).isSameAs(GBP_2_34); } @Test void test_withCurrencyUnit_CurrencyRoundingMode_UNECESSARY() { - assertThatExceptionOfType(ArithmeticException.class) + assertThatExceptionOfType(ArithmeticException.class) .isThrownBy(() -> GBP_2_34.withCurrencyUnit(JPY, RoundingMode.UNNECESSARY)); } @Test void test_withCurrencyUnit_CurrencyRoundingMode_nullCurrency() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> GBP_2_34.withCurrencyUnit((CurrencyUnit) null, RoundingMode.UNNECESSARY)); } @@ -986,13 +985,13 @@ void test_getAmountMajorLong_negative() { @Test void test_getAmountMajorLong_tooBigPositive() { - assertThatExceptionOfType(ArithmeticException.class) + assertThatExceptionOfType(ArithmeticException.class) .isThrownBy(() -> GBP_LONG_MAX_MAJOR_PLUS1.getAmountMajorLong()); } @Test void test_getAmountMajorLong_tooBigNegative() { - assertThatExceptionOfType(ArithmeticException.class) + assertThatExceptionOfType(ArithmeticException.class) .isThrownBy(() -> GBP_LONG_MIN_MAJOR_MINUS1.getAmountMajorLong()); } @@ -1011,13 +1010,13 @@ void test_getAmountMajorInt_negative() { @Test void test_getAmountMajorInt_tooBigPositive() { - assertThatExceptionOfType(ArithmeticException.class) + assertThatExceptionOfType(ArithmeticException.class) .isThrownBy(() -> GBP_INT_MAX_MAJOR_PLUS1.getAmountMajorInt()); } @Test void test_getAmountMajorInt_tooBigNegative() { - assertThatExceptionOfType(ArithmeticException.class) + assertThatExceptionOfType(ArithmeticException.class) .isThrownBy(() -> GBP_INT_MIN_MAJOR_MINUS1.getAmountMajorInt()); } @@ -1049,13 +1048,13 @@ void test_getAmountMinorLong_negative() { @Test void test_getAmountMinorLong_tooBigPositive() { - assertThatExceptionOfType(ArithmeticException.class) + assertThatExceptionOfType(ArithmeticException.class) .isThrownBy(() -> GBP_LONG_MAX_PLUS1.getAmountMinorLong()); } @Test void test_getAmountMinorLong_tooBigNegative() { - assertThatExceptionOfType(ArithmeticException.class) + assertThatExceptionOfType(ArithmeticException.class) .isThrownBy(() -> GBP_LONG_MIN_MINUS1.getAmountMinorLong()); } @@ -1074,13 +1073,13 @@ void test_getAmountMinorInt_negative() { @Test void test_getAmountMinorInt_tooBigPositive() { - assertThatExceptionOfType(ArithmeticException.class) + assertThatExceptionOfType(ArithmeticException.class) .isThrownBy(() -> GBP_INT_MAX_PLUS1.getAmountMinorInt()); } @Test void test_getAmountMinorInt_tooBigNegative() { - assertThatExceptionOfType(ArithmeticException.class) + assertThatExceptionOfType(ArithmeticException.class) .isThrownBy(() -> GBP_INT_MIN_MINUS1.getAmountMinorInt()); } @@ -1152,25 +1151,25 @@ void test_isNegativeOrZero() { //----------------------------------------------------------------------- @Test void test_withAmount_BigDecimal() { - Money test = GBP_2_34.withAmount(BIGDEC_M5_78); + var test = GBP_2_34.withAmount(BIGDEC_M5_78); assertThat(test).hasToString("GBP -5.78"); } @Test void test_withAmount_BigDecimal_same() { - Money test = GBP_2_34.withAmount(BIGDEC_2_34); + var test = GBP_2_34.withAmount(BIGDEC_2_34); assertThat(test).isSameAs(GBP_2_34); } @Test void test_withAmount_BigDecimal_invalidScale() { - assertThatExceptionOfType(ArithmeticException.class) + assertThatExceptionOfType(ArithmeticException.class) .isThrownBy(() -> GBP_2_34.withAmount(new BigDecimal("2.345"))); } @Test void test_withAmount_BigDecimal_nullBigDecimal() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> GBP_2_34.withAmount((BigDecimal) null)); } @@ -1179,37 +1178,37 @@ void test_withAmount_BigDecimal_nullBigDecimal() { //----------------------------------------------------------------------- @Test void test_withAmount_BigDecimalRoundingMode() { - Money test = GBP_2_34.withAmount(BIGDEC_M5_78, RoundingMode.UNNECESSARY); + var test = GBP_2_34.withAmount(BIGDEC_M5_78, RoundingMode.UNNECESSARY); assertThat(test).hasToString("GBP -5.78"); } @Test void test_withAmount_BigDecimalRoundingMode_same() { - Money test = GBP_2_34.withAmount(BIGDEC_2_34, RoundingMode.UNNECESSARY); + var test = GBP_2_34.withAmount(BIGDEC_2_34, RoundingMode.UNNECESSARY); assertThat(test).isSameAs(GBP_2_34); } @Test void test_withAmount_BigDecimalRoundingMode_roundDown() { - Money test = GBP_2_34.withAmount(new BigDecimal("2.355"), RoundingMode.DOWN); + var test = GBP_2_34.withAmount(new BigDecimal("2.355"), RoundingMode.DOWN); assertThat(test).isEqualTo(GBP_2_35); } @Test void test_withAmount_BigDecimalRoundingMode_roundUnecessary() { - assertThatExceptionOfType(ArithmeticException.class) + assertThatExceptionOfType(ArithmeticException.class) .isThrownBy(() -> GBP_2_34.withAmount(new BigDecimal("2.345"), RoundingMode.UNNECESSARY)); } @Test void test_withAmount_BigDecimalRoundingMode_nullBigDecimal() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> GBP_2_34.withAmount((BigDecimal) null, RoundingMode.UNNECESSARY)); } @Test void test_withAmount_BigDecimalRoundingMode_nullRoundingMode() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> GBP_2_34.withAmount(BIGDEC_2_34, (RoundingMode) null)); } @@ -1218,19 +1217,19 @@ void test_withAmount_BigDecimalRoundingMode_nullRoundingMode() { //----------------------------------------------------------------------- @Test void test_withAmount_double() { - Money test = GBP_2_34.withAmount(-5.78d); + var test = GBP_2_34.withAmount(-5.78d); assertThat(test).hasToString("GBP -5.78"); } @Test void test_withAmount_double_same() { - Money test = GBP_2_34.withAmount(2.34d); + var test = GBP_2_34.withAmount(2.34d); assertThat(test).isSameAs(GBP_2_34); } @Test void test_withAmount_double_invalidScale() { - assertThatExceptionOfType(ArithmeticException.class) + assertThatExceptionOfType(ArithmeticException.class) .isThrownBy(() -> GBP_2_34.withAmount(2.345d)); } @@ -1239,31 +1238,31 @@ void test_withAmount_double_invalidScale() { //----------------------------------------------------------------------- @Test void test_withAmount_doubleRoundingMode() { - Money test = GBP_2_34.withAmount(-5.78d, RoundingMode.UNNECESSARY); + var test = GBP_2_34.withAmount(-5.78d, RoundingMode.UNNECESSARY); assertThat(test).hasToString("GBP -5.78"); } @Test void test_withAmount_doubleRoundingMode_same() { - Money test = GBP_2_34.withAmount(2.34d, RoundingMode.UNNECESSARY); + var test = GBP_2_34.withAmount(2.34d, RoundingMode.UNNECESSARY); assertThat(test).isSameAs(GBP_2_34); } @Test void test_withAmount_doubleRoundingMode_roundDown() { - Money test = GBP_2_34.withAmount(2.355d, RoundingMode.DOWN); + var test = GBP_2_34.withAmount(2.355d, RoundingMode.DOWN); assertThat(test).isEqualTo(GBP_2_35); } @Test void test_withAmount_doubleRoundingMode_roundUnecessary() { - assertThatExceptionOfType(ArithmeticException.class) + assertThatExceptionOfType(ArithmeticException.class) .isThrownBy(() -> GBP_2_34.withAmount(2.345d, RoundingMode.UNNECESSARY)); } @Test void test_withAmount_doubleRoundingMode_nullRoundingMode() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> GBP_2_34.withAmount(BIGDEC_2_34, (RoundingMode) null)); } @@ -1273,14 +1272,14 @@ void test_withAmount_doubleRoundingMode_nullRoundingMode() { @Test void test_plus_Iterable() { Iterable iterable = Arrays.asList(GBP_2_33, GBP_1_23); - Money test = GBP_2_34.plus(iterable); + var test = GBP_2_34.plus(iterable); 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); + var test = GBP_2_34.plus(iterable); assertThat(test).isSameAs(GBP_2_34); } @@ -1302,13 +1301,13 @@ void test_plus_Iterable_currencyMismatch() { @Test void test_plus_Iterable_nullEntry() { Iterable iterable = Arrays.asList(GBP_2_33, null); - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> GBP_M5_78.plus(iterable)); } @Test void test_plus_Iterable_nullIterable() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> GBP_M5_78.plus((Iterable) null)); } @@ -1317,19 +1316,19 @@ void test_plus_Iterable_nullIterable() { //----------------------------------------------------------------------- @Test void test_plus_Money_zero() { - Money test = GBP_2_34.plus(GBP_0_00); + var test = GBP_2_34.plus(GBP_0_00); assertThat(test).isSameAs(GBP_2_34); } @Test void test_plus_Money_positive() { - Money test = GBP_2_34.plus(GBP_1_23); + var test = GBP_2_34.plus(GBP_1_23); assertThat(test).hasToString("GBP 3.57"); } @Test void test_plus_Money_negative() { - Money test = GBP_2_34.plus(GBP_M1_23); + var test = GBP_2_34.plus(GBP_M1_23); assertThat(test).hasToString("GBP 1.11"); } @@ -1349,7 +1348,7 @@ void test_plus_Money_currencyMismatch() { @Test void test_plus_Money_nullMoney() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> GBP_M5_78.plus((Money) null)); } @@ -1358,31 +1357,31 @@ void test_plus_Money_nullMoney() { //----------------------------------------------------------------------- @Test void test_plus_BigDecimal_zero() { - Money test = GBP_2_34.plus(BigDecimal.ZERO); + var test = GBP_2_34.plus(BigDecimal.ZERO); assertThat(test).isSameAs(GBP_2_34); } @Test void test_plus_BigDecimal_positive() { - Money test = GBP_2_34.plus(new BigDecimal("1.23")); + var test = GBP_2_34.plus(new BigDecimal("1.23")); assertThat(test).hasToString("GBP 3.57"); } @Test void test_plus_BigDecimal_negative() { - Money test = GBP_2_34.plus(new BigDecimal("-1.23")); + var test = GBP_2_34.plus(new BigDecimal("-1.23")); assertThat(test).hasToString("GBP 1.11"); } @Test void test_plus_BigDecimal_invalidScale() { - assertThatExceptionOfType(ArithmeticException.class) + assertThatExceptionOfType(ArithmeticException.class) .isThrownBy(() -> GBP_2_34.plus(new BigDecimal("1.235"))); } @Test void test_plus_BigDecimal_nullBigDecimal() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> GBP_M5_78.plus((BigDecimal) null)); } @@ -1391,43 +1390,43 @@ void test_plus_BigDecimal_nullBigDecimal() { //----------------------------------------------------------------------- @Test void test_plus_BigDecimalRoundingMode_zero() { - Money test = GBP_2_34.plus(BigDecimal.ZERO, RoundingMode.UNNECESSARY); + var test = GBP_2_34.plus(BigDecimal.ZERO, RoundingMode.UNNECESSARY); assertThat(test).isSameAs(GBP_2_34); } @Test void test_plus_BigDecimalRoundingMode_positive() { - Money test = GBP_2_34.plus(new BigDecimal("1.23"), RoundingMode.UNNECESSARY); + var test = GBP_2_34.plus(new BigDecimal("1.23"), RoundingMode.UNNECESSARY); assertThat(test).hasToString("GBP 3.57"); } @Test void test_plus_BigDecimalRoundingMode_negative() { - Money test = GBP_2_34.plus(new BigDecimal("-1.23"), RoundingMode.UNNECESSARY); + var test = GBP_2_34.plus(new BigDecimal("-1.23"), RoundingMode.UNNECESSARY); assertThat(test).hasToString("GBP 1.11"); } @Test void test_plus_BigDecimalRoundingMode_roundDown() { - Money test = GBP_2_34.plus(new BigDecimal("1.235"), RoundingMode.DOWN); + var test = GBP_2_34.plus(new BigDecimal("1.235"), RoundingMode.DOWN); assertThat(test).hasToString("GBP 3.57"); } @Test void test_plus_BigDecimalRoundingMode_roundUnecessary() { - assertThatExceptionOfType(ArithmeticException.class) + assertThatExceptionOfType(ArithmeticException.class) .isThrownBy(() -> GBP_2_34.plus(new BigDecimal("1.235"), RoundingMode.UNNECESSARY)); } @Test void test_plus_BigDecimalRoundingMode_nullBigDecimal() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> GBP_M5_78.plus((BigDecimal) null, RoundingMode.UNNECESSARY)); } @Test void test_plus_BigDecimalRoundingMode_nullRoundingMode() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> GBP_M5_78.plus(BIGDEC_2_34, (RoundingMode) null)); } @@ -1436,25 +1435,25 @@ void test_plus_BigDecimalRoundingMode_nullRoundingMode() { //----------------------------------------------------------------------- @Test void test_plus_double_zero() { - Money test = GBP_2_34.plus(0d); + var test = GBP_2_34.plus(0d); assertThat(test).isSameAs(GBP_2_34); } @Test void test_plus_double_positive() { - Money test = GBP_2_34.plus(1.23d); + var test = GBP_2_34.plus(1.23d); assertThat(test).hasToString("GBP 3.57"); } @Test void test_plus_double_negative() { - Money test = GBP_2_34.plus(-1.23d); + var test = GBP_2_34.plus(-1.23d); assertThat(test).hasToString("GBP 1.11"); } @Test void test_plus_double_invalidScale() { - assertThatExceptionOfType(ArithmeticException.class) + assertThatExceptionOfType(ArithmeticException.class) .isThrownBy(() -> GBP_2_34.plus(1.235d)); } @@ -1463,37 +1462,37 @@ void test_plus_double_invalidScale() { //----------------------------------------------------------------------- @Test void test_plus_doubleRoundingMode_zero() { - Money test = GBP_2_34.plus(0d, RoundingMode.UNNECESSARY); + var test = GBP_2_34.plus(0d, RoundingMode.UNNECESSARY); assertThat(test).isSameAs(GBP_2_34); } @Test void test_plus_doubleRoundingMode_positive() { - Money test = GBP_2_34.plus(1.23d, RoundingMode.UNNECESSARY); + var test = GBP_2_34.plus(1.23d, RoundingMode.UNNECESSARY); assertThat(test).hasToString("GBP 3.57"); } @Test void test_plus_doubleRoundingMode_negative() { - Money test = GBP_2_34.plus(-1.23d, RoundingMode.UNNECESSARY); + var test = GBP_2_34.plus(-1.23d, RoundingMode.UNNECESSARY); assertThat(test).hasToString("GBP 1.11"); } @Test void test_plus_doubleRoundingMode_roundDown() { - Money test = GBP_2_34.plus(1.235d, RoundingMode.DOWN); + var test = GBP_2_34.plus(1.235d, RoundingMode.DOWN); assertThat(test).hasToString("GBP 3.57"); } @Test void test_plus_doubleRoundingMode_roundUnecessary() { - assertThatExceptionOfType(ArithmeticException.class) + assertThatExceptionOfType(ArithmeticException.class) .isThrownBy(() -> GBP_2_34.plus(1.235d, RoundingMode.UNNECESSARY)); } @Test void test_plus_doubleRoundingMode_nullRoundingMode() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> GBP_M5_78.plus(2.34d, (RoundingMode) null)); } @@ -1502,19 +1501,19 @@ void test_plus_doubleRoundingMode_nullRoundingMode() { //----------------------------------------------------------------------- @Test void test_plusMajor_zero() { - Money test = GBP_2_34.plusMajor(0); + var test = GBP_2_34.plusMajor(0); assertThat(test).isSameAs(GBP_2_34); } @Test void test_plusMajor_positive() { - Money test = GBP_2_34.plusMajor(123); + var test = GBP_2_34.plusMajor(123); assertThat(test).hasToString("GBP 125.34"); } @Test void test_plusMajor_negative() { - Money test = GBP_2_34.plusMajor(-123); + var test = GBP_2_34.plusMajor(-123); assertThat(test).hasToString("GBP -120.66"); } @@ -1523,19 +1522,19 @@ void test_plusMajor_negative() { //----------------------------------------------------------------------- @Test void test_plusMinor_zero() { - Money test = GBP_2_34.plusMinor(0); + var test = GBP_2_34.plusMinor(0); assertThat(test).isSameAs(GBP_2_34); } @Test void test_plusMinor_positive() { - Money test = GBP_2_34.plusMinor(123); + var test = GBP_2_34.plusMinor(123); assertThat(test).hasToString("GBP 3.57"); } @Test void test_plusMinor_negative() { - Money test = GBP_2_34.plusMinor(-123); + var test = GBP_2_34.plusMinor(-123); assertThat(test).hasToString("GBP 1.11"); } @@ -1545,14 +1544,14 @@ void test_plusMinor_negative() { @Test void test_minus_Iterable() { Iterable iterable = Arrays.asList(GBP_2_33, GBP_1_23); - Money test = GBP_2_34.minus(iterable); + var test = GBP_2_34.minus(iterable); 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); + var test = GBP_2_34.minus(iterable); assertThat(test).isSameAs(GBP_2_34); } @@ -1574,13 +1573,13 @@ void test_minus_Iterable_currencyMismatch() { @Test void test_minus_Iterable_nullEntry() { Iterable iterable = Arrays.asList(GBP_2_33, null); - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> GBP_M5_78.minus(iterable)); } @Test void test_minus_Iterable_nullIterable() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> GBP_M5_78.minus((Iterable) null)); } @@ -1589,19 +1588,19 @@ void test_minus_Iterable_nullIterable() { //----------------------------------------------------------------------- @Test void test_minus_Money_zero() { - Money test = GBP_2_34.minus(GBP_0_00); + var test = GBP_2_34.minus(GBP_0_00); assertThat(test).isSameAs(GBP_2_34); } @Test void test_minus_Money_positive() { - Money test = GBP_2_34.minus(GBP_1_23); + var test = GBP_2_34.minus(GBP_1_23); assertThat(test).hasToString("GBP 1.11"); } @Test void test_minus_Money_negative() { - Money test = GBP_2_34.minus(GBP_M1_23); + var test = GBP_2_34.minus(GBP_M1_23); assertThat(test).hasToString("GBP 3.57"); } @@ -1621,7 +1620,7 @@ void test_minus_Money_currencyMismatch() { @Test void test_minus_Money_nullMoney() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> GBP_M5_78.minus((Money) null)); } @@ -1630,31 +1629,31 @@ void test_minus_Money_nullMoney() { //----------------------------------------------------------------------- @Test void test_minus_BigDecimal_zero() { - Money test = GBP_2_34.minus(BigDecimal.ZERO); + var test = GBP_2_34.minus(BigDecimal.ZERO); assertThat(test).isSameAs(GBP_2_34); } @Test void test_minus_BigDecimal_positive() { - Money test = GBP_2_34.minus(new BigDecimal("1.23")); + var test = GBP_2_34.minus(new BigDecimal("1.23")); assertThat(test).hasToString("GBP 1.11"); } @Test void test_minus_BigDecimal_negative() { - Money test = GBP_2_34.minus(new BigDecimal("-1.23")); + var test = GBP_2_34.minus(new BigDecimal("-1.23")); assertThat(test).hasToString("GBP 3.57"); } @Test void test_minus_BigDecimal_invalidScale() { - assertThatExceptionOfType(ArithmeticException.class) + assertThatExceptionOfType(ArithmeticException.class) .isThrownBy(() -> GBP_2_34.minus(new BigDecimal("1.235"))); } @Test void test_minus_BigDecimal_nullBigDecimal() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> GBP_M5_78.minus((BigDecimal) null)); } @@ -1663,43 +1662,43 @@ void test_minus_BigDecimal_nullBigDecimal() { //----------------------------------------------------------------------- @Test void test_minus_BigDecimalRoundingMode_zero() { - Money test = GBP_2_34.minus(BigDecimal.ZERO, RoundingMode.UNNECESSARY); + var test = GBP_2_34.minus(BigDecimal.ZERO, RoundingMode.UNNECESSARY); assertThat(test).isSameAs(GBP_2_34); } @Test void test_minus_BigDecimalRoundingMode_positive() { - Money test = GBP_2_34.minus(new BigDecimal("1.23"), RoundingMode.UNNECESSARY); + var test = GBP_2_34.minus(new BigDecimal("1.23"), RoundingMode.UNNECESSARY); assertThat(test).hasToString("GBP 1.11"); } @Test void test_minus_BigDecimalRoundingMode_negative() { - Money test = GBP_2_34.minus(new BigDecimal("-1.23"), RoundingMode.UNNECESSARY); + var test = GBP_2_34.minus(new BigDecimal("-1.23"), RoundingMode.UNNECESSARY); assertThat(test).hasToString("GBP 3.57"); } @Test void test_minus_BigDecimalRoundingMode_roundDown() { - Money test = GBP_2_34.minus(new BigDecimal("1.235"), RoundingMode.DOWN); + var test = GBP_2_34.minus(new BigDecimal("1.235"), RoundingMode.DOWN); assertThat(test).hasToString("GBP 1.10"); } @Test void test_minus_BigDecimalRoundingMode_roundUnecessary() { - assertThatExceptionOfType(ArithmeticException.class) + assertThatExceptionOfType(ArithmeticException.class) .isThrownBy(() -> GBP_2_34.minus(new BigDecimal("1.235"), RoundingMode.UNNECESSARY)); } @Test void test_minus_BigDecimalRoundingMode_nullBigDecimal() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> GBP_M5_78.minus((BigDecimal) null, RoundingMode.UNNECESSARY)); } @Test void test_minus_BigDecimalRoundingMode_nullRoundingMode() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> GBP_M5_78.minus(BIGDEC_2_34, (RoundingMode) null)); } @@ -1708,25 +1707,25 @@ void test_minus_BigDecimalRoundingMode_nullRoundingMode() { //----------------------------------------------------------------------- @Test void test_minus_double_zero() { - Money test = GBP_2_34.minus(0d); + var test = GBP_2_34.minus(0d); assertThat(test).isSameAs(GBP_2_34); } @Test void test_minus_double_positive() { - Money test = GBP_2_34.minus(1.23d); + var test = GBP_2_34.minus(1.23d); assertThat(test).hasToString("GBP 1.11"); } @Test void test_minus_double_negative() { - Money test = GBP_2_34.minus(-1.23d); + var test = GBP_2_34.minus(-1.23d); assertThat(test).hasToString("GBP 3.57"); } @Test void test_minus_double_invalidScale() { - assertThatExceptionOfType(ArithmeticException.class) + assertThatExceptionOfType(ArithmeticException.class) .isThrownBy(() -> GBP_2_34.minus(1.235d)); } @@ -1735,37 +1734,37 @@ void test_minus_double_invalidScale() { //----------------------------------------------------------------------- @Test void test_minus_doubleRoundingMode_zero() { - Money test = GBP_2_34.minus(0d, RoundingMode.UNNECESSARY); + var test = GBP_2_34.minus(0d, RoundingMode.UNNECESSARY); assertThat(test).isSameAs(GBP_2_34); } @Test void test_minus_doubleRoundingMode_positive() { - Money test = GBP_2_34.minus(1.23d, RoundingMode.UNNECESSARY); + var test = GBP_2_34.minus(1.23d, RoundingMode.UNNECESSARY); assertThat(test).hasToString("GBP 1.11"); } @Test void test_minus_doubleRoundingMode_negative() { - Money test = GBP_2_34.minus(-1.23d, RoundingMode.UNNECESSARY); + var test = GBP_2_34.minus(-1.23d, RoundingMode.UNNECESSARY); assertThat(test).hasToString("GBP 3.57"); } @Test void test_minus_doubleRoundingMode_roundDown() { - Money test = GBP_2_34.minus(1.235d, RoundingMode.DOWN); + var test = GBP_2_34.minus(1.235d, RoundingMode.DOWN); assertThat(test).hasToString("GBP 1.10"); } @Test void test_minus_doubleRoundingMode_roundUnecessary() { - assertThatExceptionOfType(ArithmeticException.class) + assertThatExceptionOfType(ArithmeticException.class) .isThrownBy(() -> GBP_2_34.minus(1.235d, RoundingMode.UNNECESSARY)); } @Test void test_minus_doubleRoundingMode_nullRoundingMode() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> GBP_M5_78.minus(2.34d, (RoundingMode) null)); } @@ -1774,19 +1773,19 @@ void test_minus_doubleRoundingMode_nullRoundingMode() { //----------------------------------------------------------------------- @Test void test_minusMajor_zero() { - Money test = GBP_2_34.minusMajor(0); + var test = GBP_2_34.minusMajor(0); assertThat(test).isSameAs(GBP_2_34); } @Test void test_minusMajor_positive() { - Money test = GBP_2_34.minusMajor(123); + var test = GBP_2_34.minusMajor(123); assertThat(test).hasToString("GBP -120.66"); } @Test void test_minusMajor_negative() { - Money test = GBP_2_34.minusMajor(-123); + var test = GBP_2_34.minusMajor(-123); assertThat(test).hasToString("GBP 125.34"); } @@ -1795,19 +1794,19 @@ void test_minusMajor_negative() { //----------------------------------------------------------------------- @Test void test_minusMinor_zero() { - Money test = GBP_2_34.minusMinor(0); + var test = GBP_2_34.minusMinor(0); assertThat(test).isSameAs(GBP_2_34); } @Test void test_minusMinor_positive() { - Money test = GBP_2_34.minusMinor(123); + var test = GBP_2_34.minusMinor(123); assertThat(test).hasToString("GBP 1.11"); } @Test void test_minusMinor_negative() { - Money test = GBP_2_34.minusMinor(-123); + var test = GBP_2_34.minusMinor(-123); assertThat(test).hasToString("GBP 3.57"); } @@ -1816,37 +1815,37 @@ void test_minusMinor_negative() { //----------------------------------------------------------------------- @Test void test_multipliedBy_BigDecimalRoundingMode_one() { - Money test = GBP_2_34.multipliedBy(BigDecimal.ONE, RoundingMode.DOWN); + var test = GBP_2_34.multipliedBy(BigDecimal.ONE, RoundingMode.DOWN); assertThat(test).isSameAs(GBP_2_34); } @Test void test_multipliedBy_BigDecimalRoundingMode_positive() { - Money test = GBP_2_33.multipliedBy(new BigDecimal("2.5"), RoundingMode.DOWN); + var test = GBP_2_33.multipliedBy(new BigDecimal("2.5"), RoundingMode.DOWN); 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); + var test = GBP_2_33.multipliedBy(new BigDecimal("2.5"), RoundingMode.HALF_UP); assertThat(test).hasToString("GBP 5.83"); } @Test void test_multipliedBy_BigDecimalRoundingMode_negative() { - Money test = GBP_2_33.multipliedBy(new BigDecimal("-2.5"), RoundingMode.FLOOR); + var test = GBP_2_33.multipliedBy(new BigDecimal("-2.5"), RoundingMode.FLOOR); assertThat(test).hasToString("GBP -5.83"); } @Test void test_multipliedBy_BigDecimalRoundingMode_nullBigDecimal() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> GBP_5_78.multipliedBy((BigDecimal) null, RoundingMode.DOWN)); } @Test void test_multipliedBy_BigDecimalRoundingMode_nullRoundingMode() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> GBP_5_78.multipliedBy(new BigDecimal("2.5"), (RoundingMode) null)); } @@ -1855,31 +1854,31 @@ void test_multipliedBy_BigDecimalRoundingMode_nullRoundingMode() { //----------------------------------------------------------------------- @Test void test_multipliedBy_doubleRoundingMode_one() { - Money test = GBP_2_34.multipliedBy(1d, RoundingMode.DOWN); + var test = GBP_2_34.multipliedBy(1d, RoundingMode.DOWN); assertThat(test).isSameAs(GBP_2_34); } @Test void test_multipliedBy_doubleRoundingMode_positive() { - Money test = GBP_2_33.multipliedBy(2.5d, RoundingMode.DOWN); + var test = GBP_2_33.multipliedBy(2.5d, RoundingMode.DOWN); assertThat(test).hasToString("GBP 5.82"); } @Test void test_multipliedBy_doubleRoundingMode_positive_halfUp() { - Money test = GBP_2_33.multipliedBy(2.5d, RoundingMode.HALF_UP); + var test = GBP_2_33.multipliedBy(2.5d, RoundingMode.HALF_UP); assertThat(test).hasToString("GBP 5.83"); } @Test void test_multipliedBy_doubleRoundingMode_negative() { - Money test = GBP_2_33.multipliedBy(-2.5d, RoundingMode.FLOOR); + var test = GBP_2_33.multipliedBy(-2.5d, RoundingMode.FLOOR); assertThat(test).hasToString("GBP -5.83"); } @Test void test_multipliedBy_doubleRoundingMode_nullRoundingMode() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> GBP_5_78.multipliedBy(2.5d, (RoundingMode) null)); } @@ -1888,19 +1887,19 @@ void test_multipliedBy_doubleRoundingMode_nullRoundingMode() { //----------------------------------------------------------------------- @Test void test_multipliedBy_long_one() { - Money test = GBP_2_34.multipliedBy(1); + var test = GBP_2_34.multipliedBy(1); assertThat(test).isSameAs(GBP_2_34); } @Test void test_multipliedBy_long_positive() { - Money test = GBP_2_34.multipliedBy(3); + var test = GBP_2_34.multipliedBy(3); assertThat(test).hasToString("GBP 7.02"); } @Test void test_multipliedBy_long_negative() { - Money test = GBP_2_34.multipliedBy(-3); + var test = GBP_2_34.multipliedBy(-3); assertThat(test).hasToString("GBP -7.02"); } @@ -1909,37 +1908,37 @@ void test_multipliedBy_long_negative() { //----------------------------------------------------------------------- @Test void test_dividedBy_BigDecimalRoundingMode_one() { - Money test = GBP_2_34.dividedBy(BigDecimal.ONE, RoundingMode.DOWN); + var test = GBP_2_34.dividedBy(BigDecimal.ONE, RoundingMode.DOWN); assertThat(test).isSameAs(GBP_2_34); } @Test void test_dividedBy_BigDecimalRoundingMode_positive() { - Money test = GBP_2_34.dividedBy(new BigDecimal("2.5"), RoundingMode.DOWN); + var test = GBP_2_34.dividedBy(new BigDecimal("2.5"), RoundingMode.DOWN); 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); + var test = GBP_2_34.dividedBy(new BigDecimal("2.5"), RoundingMode.HALF_UP); assertThat(test).hasToString("GBP 0.94"); } @Test void test_dividedBy_BigDecimalRoundingMode_negative() { - Money test = GBP_2_34.dividedBy(new BigDecimal("-2.5"), RoundingMode.FLOOR); + var test = GBP_2_34.dividedBy(new BigDecimal("-2.5"), RoundingMode.FLOOR); assertThat(test).hasToString("GBP -0.94"); } @Test void test_dividedBy_BigDecimalRoundingMode_nullBigDecimal() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> GBP_5_78.dividedBy((BigDecimal) null, RoundingMode.DOWN)); } @Test void test_dividedBy_BigDecimalRoundingMode_nullRoundingMode() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> GBP_5_78.dividedBy(new BigDecimal("2.5"), (RoundingMode) null)); } @@ -1948,31 +1947,31 @@ void test_dividedBy_BigDecimalRoundingMode_nullRoundingMode() { //----------------------------------------------------------------------- @Test void test_dividedBy_doubleRoundingMode_one() { - Money test = GBP_2_34.dividedBy(1d, RoundingMode.DOWN); + var test = GBP_2_34.dividedBy(1d, RoundingMode.DOWN); assertThat(test).isSameAs(GBP_2_34); } @Test void test_dividedBy_doubleRoundingMode_positive() { - Money test = GBP_2_34.dividedBy(2.5d, RoundingMode.DOWN); + var test = GBP_2_34.dividedBy(2.5d, RoundingMode.DOWN); assertThat(test).hasToString("GBP 0.93"); } @Test void test_dividedBy_doubleRoundingMode_positive_halfUp() { - Money test = GBP_2_34.dividedBy(2.5d, RoundingMode.HALF_UP); + var test = GBP_2_34.dividedBy(2.5d, RoundingMode.HALF_UP); assertThat(test).hasToString("GBP 0.94"); } @Test void test_dividedBy_doubleRoundingMode_negative() { - Money test = GBP_2_34.dividedBy(-2.5d, RoundingMode.FLOOR); + var test = GBP_2_34.dividedBy(-2.5d, RoundingMode.FLOOR); assertThat(test).hasToString("GBP -0.94"); } @Test void test_dividedBy_doubleRoundingMode_nullRoundingMode() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> GBP_5_78.dividedBy(2.5d, (RoundingMode) null)); } @@ -1981,31 +1980,31 @@ void test_dividedBy_doubleRoundingMode_nullRoundingMode() { //----------------------------------------------------------------------- @Test void test_dividedBy_long_one() { - Money test = GBP_2_34.dividedBy(1, RoundingMode.DOWN); + var test = GBP_2_34.dividedBy(1, RoundingMode.DOWN); assertThat(test).isSameAs(GBP_2_34); } @Test void test_dividedBy_long_positive() { - Money test = GBP_2_34.dividedBy(3, RoundingMode.DOWN); + var test = GBP_2_34.dividedBy(3, RoundingMode.DOWN); assertThat(test).hasToString("GBP 0.78"); } @Test void test_dividedBy_long_positive_roundDown() { - Money test = GBP_2_35.dividedBy(3, RoundingMode.DOWN); + var test = GBP_2_35.dividedBy(3, RoundingMode.DOWN); assertThat(test).hasToString("GBP 0.78"); } @Test void test_dividedBy_long_positive_roundUp() { - Money test = GBP_2_35.dividedBy(3, RoundingMode.UP); + var test = GBP_2_35.dividedBy(3, RoundingMode.UP); assertThat(test).hasToString("GBP 0.79"); } @Test void test_dividedBy_long_negative() { - Money test = GBP_2_34.dividedBy(-3, RoundingMode.DOWN); + var test = GBP_2_34.dividedBy(-3, RoundingMode.DOWN); assertThat(test).hasToString("GBP -0.78"); } @@ -2014,13 +2013,13 @@ void test_dividedBy_long_negative() { //----------------------------------------------------------------------- @Test void test_negated_positive() { - Money test = GBP_2_34.negated(); + var test = GBP_2_34.negated(); assertThat(test).hasToString("GBP -2.34"); } @Test void test_negated_negative() { - Money test = Money.parse("GBP -2.34").negated(); + var test = Money.parse("GBP -2.34").negated(); assertThat(test).hasToString("GBP 2.34"); } @@ -2029,13 +2028,13 @@ void test_negated_negative() { //----------------------------------------------------------------------- @Test void test_abs_positive() { - Money test = GBP_2_34.abs(); + var test = GBP_2_34.abs(); assertThat(test).isSameAs(GBP_2_34); } @Test void test_abs_negative() { - Money test = Money.parse("GBP -2.34").abs(); + var test = Money.parse("GBP -2.34").abs(); assertThat(test).hasToString("GBP 2.34"); } @@ -2044,55 +2043,55 @@ void test_abs_negative() { //----------------------------------------------------------------------- @Test void test_round_2down() { - Money test = GBP_2_34.rounded(2, RoundingMode.DOWN); + var test = GBP_2_34.rounded(2, RoundingMode.DOWN); assertThat(test).isSameAs(GBP_2_34); } @Test void test_round_2up() { - Money test = GBP_2_34.rounded(2, RoundingMode.DOWN); + var test = GBP_2_34.rounded(2, RoundingMode.DOWN); assertThat(test).isSameAs(GBP_2_34); } @Test void test_round_1down() { - Money test = GBP_2_34.rounded(1, RoundingMode.DOWN); + var test = GBP_2_34.rounded(1, RoundingMode.DOWN); assertThat(test).hasToString("GBP 2.30"); } @Test void test_round_1up() { - Money test = GBP_2_34.rounded(1, RoundingMode.UP); + var test = GBP_2_34.rounded(1, RoundingMode.UP); assertThat(test).hasToString("GBP 2.40"); } @Test void test_round_0down() { - Money test = GBP_2_34.rounded(0, RoundingMode.DOWN); + var test = GBP_2_34.rounded(0, RoundingMode.DOWN); assertThat(test).hasToString("GBP 2.00"); } @Test void test_round_0up() { - Money test = GBP_2_34.rounded(0, RoundingMode.UP); + var test = GBP_2_34.rounded(0, RoundingMode.UP); assertThat(test).hasToString("GBP 3.00"); } @Test void test_round_M1down() { - Money test = Money.parse("GBP 432.34").rounded(-1, RoundingMode.DOWN); + var test = Money.parse("GBP 432.34").rounded(-1, RoundingMode.DOWN); assertThat(test).hasToString("GBP 430.00"); } @Test void test_round_M1up() { - Money test = Money.parse("GBP 432.34").rounded(-1, RoundingMode.UP); + var test = Money.parse("GBP 432.34").rounded(-1, RoundingMode.UP); assertThat(test).hasToString("GBP 440.00"); } @Test void test_round_3() { - Money test = GBP_2_34.rounded(3, RoundingMode.DOWN); + var test = GBP_2_34.rounded(3, RoundingMode.DOWN); assertThat(test).isSameAs(GBP_2_34); } @@ -2101,43 +2100,43 @@ void test_round_3() { //----------------------------------------------------------------------- @Test void test_convertedTo_BigDecimalRoundingMode_positive() { - Money test = GBP_2_33.convertedTo(EUR, new BigDecimal("2.5"), RoundingMode.DOWN); + var test = GBP_2_33.convertedTo(EUR, new BigDecimal("2.5"), RoundingMode.DOWN); 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); + var test = GBP_2_33.convertedTo(EUR, new BigDecimal("2.5"), RoundingMode.HALF_UP); assertThat(test).hasToString("EUR 5.83"); } @Test void test_convertedTo_BigDecimalRoundingMode_negative() { - assertThatExceptionOfType(IllegalArgumentException.class) + assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> GBP_2_33.convertedTo(EUR, new BigDecimal("-2.5"), RoundingMode.FLOOR)); } @Test void test_convertedTo_BigDecimalRoundingMode_sameCurrency() { - assertThatExceptionOfType(IllegalArgumentException.class) + assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> GBP_2_33.convertedTo(GBP, new BigDecimal("2.5"), RoundingMode.DOWN)); } @Test void test_convertedTo_BigDecimalRoundingMode_nullCurrency() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> GBP_5_78.convertedTo((CurrencyUnit) null, new BigDecimal("2"), RoundingMode.DOWN)); } @Test void test_convertedTo_BigDecimalRoundingMode_nullBigDecimal() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> GBP_5_78.convertedTo(EUR, (BigDecimal) null, RoundingMode.DOWN)); } @Test void test_convertedTo_BigDecimalRoundingMode_nullRoundingMode() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> GBP_5_78.convertedTo(EUR, new BigDecimal("2.5"), (RoundingMode) null)); } @@ -2174,7 +2173,7 @@ void test_isSameCurrency_BigMoney_different() { @Test void test_isSameCurrency_Money_nullMoney() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> GBP_2_34.isSameCurrency((Money) null)); } @@ -2183,9 +2182,9 @@ void test_isSameCurrency_Money_nullMoney() { //----------------------------------------------------------------------- @Test void test_compareTo_Money() { - Money a = GBP_2_34; - Money b = GBP_2_35; - Money c = GBP_2_36; + var a = GBP_2_34; + var b = GBP_2_35; + var c = GBP_2_36; assertThat(a.compareTo(a)).isEqualTo(0); assertThat(b.compareTo(b)).isEqualTo(0); assertThat(c.compareTo(c)).isEqualTo(0); @@ -2202,10 +2201,10 @@ void test_compareTo_Money() { @Test void test_compareTo_BigMoney() { - Money t = GBP_2_35; - BigMoney a = BigMoney.ofMinor(GBP, 234); - BigMoney b = BigMoney.ofMinor(GBP, 235); - BigMoney c = BigMoney.ofMinor(GBP, 236); + var t = GBP_2_35; + var a = BigMoney.ofMinor(GBP, 234); + var b = BigMoney.ofMinor(GBP, 235); + var c = BigMoney.ofMinor(GBP, 236); assertThat(t.compareTo(a)).isEqualTo(1); assertThat(t.compareTo(b)).isEqualTo(0); assertThat(t.compareTo(c)).isEqualTo(-1); @@ -2213,9 +2212,9 @@ void test_compareTo_BigMoney() { @Test void test_compareTo_currenciesDiffer() { - Money a = GBP_2_34; - Money b = USD_2_35; - assertThatExceptionOfType(CurrencyMismatchException.class) + var a = GBP_2_34; + var b = USD_2_35; + assertThatExceptionOfType(CurrencyMismatchException.class) .isThrownBy(() -> a.compareTo(b)); } @@ -2223,7 +2222,7 @@ void test_compareTo_currenciesDiffer() { @SuppressWarnings({"unchecked", "rawtypes"}) void test_compareTo_wrongType() { Comparable a = GBP_2_34; - assertThatExceptionOfType(ClassCastException.class) + assertThatExceptionOfType(ClassCastException.class) .isThrownBy(() -> a.compareTo("NotRightType")); } @@ -2232,9 +2231,9 @@ void test_compareTo_wrongType() { //----------------------------------------------------------------------- @Test void test_isEqual() { - Money a = GBP_2_34; - Money b = GBP_2_35; - Money c = GBP_2_36; + var a = GBP_2_34; + var b = GBP_2_35; + var c = GBP_2_36; assertThat(a.isEqual(a)).isTrue(); assertThat(b.isEqual(b)).isTrue(); assertThat(c.isEqual(c)).isTrue(); @@ -2251,16 +2250,16 @@ void test_isEqual() { @Test void test_isEqual_Money() { - Money a = GBP_2_34; - BigMoney b = BigMoney.ofMinor(GBP, 234); + var a = GBP_2_34; + var b = BigMoney.ofMinor(GBP, 234); assertThat(a.isEqual(b)).isTrue(); } @Test void test_isEqual_currenciesDiffer() { - Money a = GBP_2_34; - Money b = USD_2_35; - assertThatExceptionOfType(CurrencyMismatchException.class) + var a = GBP_2_34; + var b = USD_2_35; + assertThatExceptionOfType(CurrencyMismatchException.class) .isThrownBy(() -> a.isEqual(b)); } @@ -2269,9 +2268,9 @@ void test_isEqual_currenciesDiffer() { //----------------------------------------------------------------------- @Test void test_isGreaterThan() { - Money a = GBP_2_34; - Money b = GBP_2_35; - Money c = GBP_2_36; + var a = GBP_2_34; + var b = GBP_2_35; + var c = GBP_2_36; assertThat(a.isGreaterThan(a)).isFalse(); assertThat(a.isGreaterThan(b)).isFalse(); assertThat(a.isGreaterThan(c)).isFalse(); @@ -2287,9 +2286,9 @@ void test_isGreaterThan() { @Test void test_isGreaterThan_currenciesDiffer() { - Money a = GBP_2_34; - Money b = USD_2_35; - assertThatExceptionOfType(CurrencyMismatchException.class) + var a = GBP_2_34; + var b = USD_2_35; + assertThatExceptionOfType(CurrencyMismatchException.class) .isThrownBy(() -> a.isGreaterThan(b)); } @@ -2298,9 +2297,9 @@ void test_isGreaterThan_currenciesDiffer() { //----------------------------------------------------------------------- @Test void test_isGreaterThanOrEqual() { - Money a = GBP_2_34; - Money b = GBP_2_35; - Money c = GBP_2_36; + var a = GBP_2_34; + var b = GBP_2_35; + var c = GBP_2_36; assertThat(a.isGreaterThanOrEqual(a)).isTrue(); assertThat(a.isGreaterThanOrEqual(b)).isFalse(); assertThat(a.isGreaterThanOrEqual(c)).isFalse(); @@ -2316,9 +2315,9 @@ void test_isGreaterThanOrEqual() { @Test void test_isGreaterThanOrEqual_currenciesDiffer() { - Money a = GBP_2_34; - Money b = USD_2_35; - assertThatExceptionOfType(CurrencyMismatchException.class) + var a = GBP_2_34; + var b = USD_2_35; + assertThatExceptionOfType(CurrencyMismatchException.class) .isThrownBy(() -> a.isGreaterThanOrEqual(b)); } @@ -2327,9 +2326,9 @@ void test_isGreaterThanOrEqual_currenciesDiffer() { //----------------------------------------------------------------------- @Test void test_isLessThan() { - Money a = GBP_2_34; - Money b = GBP_2_35; - Money c = GBP_2_36; + var a = GBP_2_34; + var b = GBP_2_35; + var c = GBP_2_36; assertThat(a.isLessThan(a)).isFalse(); assertThat(a.isLessThan(b)).isTrue(); assertThat(a.isLessThan(c)).isTrue(); @@ -2345,9 +2344,9 @@ void test_isLessThan() { @Test void test_isLessThan_currenciesDiffer() { - Money a = GBP_2_34; - Money b = USD_2_35; - assertThatExceptionOfType(CurrencyMismatchException.class) + var a = GBP_2_34; + var b = USD_2_35; + assertThatExceptionOfType(CurrencyMismatchException.class) .isThrownBy(() -> a.isLessThan(b)); } @@ -2356,9 +2355,9 @@ void test_isLessThan_currenciesDiffer() { //----------------------------------------------------------------------- @Test void test_isLessThanOrEqual() { - Money a = GBP_2_34; - Money b = GBP_2_35; - Money c = GBP_2_36; + var a = GBP_2_34; + var b = GBP_2_35; + var c = GBP_2_36; assertThat(a.isLessThanOrEqual(a)).isTrue(); assertThat(a.isLessThanOrEqual(b)).isTrue(); assertThat(a.isLessThanOrEqual(c)).isTrue(); @@ -2374,9 +2373,9 @@ void test_isLessThanOrEqual() { @Test void test_isLessThanOrEqual_currenciesDiffer() { - Money a = GBP_2_34; - Money b = USD_2_35; - assertThatExceptionOfType(CurrencyMismatchException.class) + var a = GBP_2_34; + var b = USD_2_35; + assertThatExceptionOfType(CurrencyMismatchException.class) .isThrownBy(() -> a.isLessThanOrEqual(b)); } @@ -2385,9 +2384,9 @@ void test_isLessThanOrEqual_currenciesDiffer() { //----------------------------------------------------------------------- @Test void test_equals_hashCode_positive() { - Money a = GBP_2_34; - Money b = GBP_2_34; - Money c = GBP_2_35; + var a = GBP_2_34; + var b = GBP_2_34; + var c = GBP_2_35; assertThat(a).isEqualTo(a); assertThat(b).isEqualTo(b); assertThat(c).isEqualTo(c); @@ -2402,7 +2401,7 @@ void test_equals_hashCode_positive() { @Test void test_equals_false() { - Money a = GBP_2_34; + var a = GBP_2_34; assertThat(a).isNotEqualTo(null); assertThat(new Object()).isNotEqualTo(a); } @@ -2412,13 +2411,13 @@ void test_equals_false() { //----------------------------------------------------------------------- @Test void test_toString_positive() { - Money test = Money.of(GBP, BIGDEC_2_34); + var test = Money.of(GBP, BIGDEC_2_34); assertThat(test).hasToString("GBP 2.34"); } @Test void test_toString_negative() { - Money test = Money.of(EUR, BIGDEC_M5_78); + var test = Money.of(EUR, BIGDEC_M5_78); 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 260a0b6..695e94b 100644 --- a/src/test/java/org/joda/money/TestMoneyUtils_BigMoney.java +++ b/src/test/java/org/joda/money/TestMoneyUtils_BigMoney.java @@ -18,7 +18,6 @@ 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; import org.junit.jupiter.api.Test; @@ -41,7 +40,7 @@ class TestMoneyUtils_BigMoney { //----------------------------------------------------------------------- @Test void test_constructor() throws Exception { - Constructor con = MoneyUtils.class.getDeclaredConstructor(); + var con = MoneyUtils.class.getDeclaredConstructor(); assertThat(Modifier.isPrivate(con.getModifiers())).isTrue(); con.setAccessible(true); con.newInstance(); diff --git a/src/test/java/org/joda/money/TestStringConvert.java b/src/test/java/org/joda/money/TestStringConvert.java index d049394..2d734e6 100644 --- a/src/test/java/org/joda/money/TestStringConvert.java +++ b/src/test/java/org/joda/money/TestStringConvert.java @@ -17,7 +17,6 @@ import static org.assertj.core.api.Assertions.assertThat; - import org.joda.convert.StringConvert; import org.junit.jupiter.api.Test; @@ -28,24 +27,24 @@ class TestStringConvert { @Test void test_BigMoney() { - BigMoney test = BigMoney.of(CurrencyUnit.CHF, 1234.5678d); - String str = StringConvert.INSTANCE.convertToString(test); + var test = BigMoney.of(CurrencyUnit.CHF, 1234.5678d); + var str = StringConvert.INSTANCE.convertToString(test); 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); + var test = Money.of(CurrencyUnit.CHF, 1234.56d); + var str = StringConvert.INSTANCE.convertToString(test); 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); + var test = CurrencyUnit.CHF; + var str = StringConvert.INSTANCE.convertToString(test); 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 0615738..0bfb95b 100644 --- a/src/test/java/org/joda/money/format/TestMoneyAmountStyle.java +++ b/src/test/java/org/joda/money/format/TestMoneyAmountStyle.java @@ -53,7 +53,7 @@ void afterMethod() { //----------------------------------------------------------------------- @Test void test_ASCII_DECIMAL_POINT_GROUP3_COMMA() { - MoneyAmountStyle style = MoneyAmountStyle.ASCII_DECIMAL_POINT_GROUP3_COMMA; + var style = MoneyAmountStyle.ASCII_DECIMAL_POINT_GROUP3_COMMA; assertThat(style.getZeroCharacter()).isEqualTo((Character) '0'); assertThat(style.getPositiveSignCharacter()).isEqualTo((Character) '+'); assertThat(style.getNegativeSignCharacter()).isEqualTo((Character) '-'); @@ -67,14 +67,14 @@ void test_ASCII_DECIMAL_POINT_GROUP3_COMMA() { @Test void test_ASCII_DECIMAL_POINT_GROUP3_COMMA_print() { - MoneyAmountStyle style = MoneyAmountStyle.ASCII_DECIMAL_POINT_GROUP3_COMMA; - MoneyFormatter test = new MoneyFormatterBuilder().appendAmount(style).toFormatter(); + var style = MoneyAmountStyle.ASCII_DECIMAL_POINT_GROUP3_COMMA; + var test = new MoneyFormatterBuilder().appendAmount(style).toFormatter(); 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; + var style = MoneyAmountStyle.ASCII_DECIMAL_POINT_GROUP3_SPACE; assertThat(style.getZeroCharacter()).isEqualTo((Character) '0'); assertThat(style.getPositiveSignCharacter()).isEqualTo((Character) '+'); assertThat(style.getNegativeSignCharacter()).isEqualTo((Character) '-'); @@ -88,14 +88,14 @@ void test_ASCII_DECIMAL_POINT_GROUP3_SPACE() { @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(); + var style = MoneyAmountStyle.ASCII_DECIMAL_POINT_GROUP3_SPACE; + var test = new MoneyFormatterBuilder().appendAmount(style).toFormatter(); 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; + var style = MoneyAmountStyle.ASCII_DECIMAL_POINT_NO_GROUPING; assertThat(style.getZeroCharacter()).isEqualTo((Character) '0'); assertThat(style.getPositiveSignCharacter()).isEqualTo((Character) '+'); assertThat(style.getNegativeSignCharacter()).isEqualTo((Character) '-'); @@ -109,14 +109,14 @@ void test_ASCII_DECIMAL_POINT_NO_GROUPING() { @Test void test_ASCII_DECIMAL_POINT_NO_GROUPING_print() { - MoneyAmountStyle style = MoneyAmountStyle.ASCII_DECIMAL_POINT_NO_GROUPING; - MoneyFormatter test = new MoneyFormatterBuilder().appendAmount(style).toFormatter(); + var style = MoneyAmountStyle.ASCII_DECIMAL_POINT_NO_GROUPING; + var test = new MoneyFormatterBuilder().appendAmount(style).toFormatter(); assertThat(test.print(MONEY)).isEqualTo("87654321.12345678"); } @Test void test_ASCII_ASCII_DECIMAL_COMMA_GROUP3_DOT() { - MoneyAmountStyle style = MoneyAmountStyle.ASCII_DECIMAL_COMMA_GROUP3_DOT; + var style = MoneyAmountStyle.ASCII_DECIMAL_COMMA_GROUP3_DOT; assertThat(style.getZeroCharacter()).isEqualTo((Character) '0'); assertThat(style.getPositiveSignCharacter()).isEqualTo((Character) '+'); assertThat(style.getNegativeSignCharacter()).isEqualTo((Character) '-'); @@ -130,14 +130,14 @@ void test_ASCII_ASCII_DECIMAL_COMMA_GROUP3_DOT() { @Test void test_ASCII_DECIMAL_COMMA_GROUP3_DOT_print() { - MoneyAmountStyle style = MoneyAmountStyle.ASCII_DECIMAL_COMMA_GROUP3_DOT; - MoneyFormatter test = new MoneyFormatterBuilder().appendAmount(style).toFormatter(); + var style = MoneyAmountStyle.ASCII_DECIMAL_COMMA_GROUP3_DOT; + var test = new MoneyFormatterBuilder().appendAmount(style).toFormatter(); 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; + var style = MoneyAmountStyle.ASCII_DECIMAL_COMMA_GROUP3_SPACE; assertThat(style.getZeroCharacter()).isEqualTo((Character) '0'); assertThat(style.getPositiveSignCharacter()).isEqualTo((Character) '+'); assertThat(style.getNegativeSignCharacter()).isEqualTo((Character) '-'); @@ -151,14 +151,14 @@ void test_ASCII_DECIMAL_COMMA_GROUP3_SPACE() { @Test void test_ASCII_DECIMAL_COMMA_GROUP3_SPACE_print() { - MoneyAmountStyle style = MoneyAmountStyle.ASCII_DECIMAL_COMMA_GROUP3_SPACE; - MoneyFormatter test = new MoneyFormatterBuilder().appendAmount(style).toFormatter(); + var style = MoneyAmountStyle.ASCII_DECIMAL_COMMA_GROUP3_SPACE; + var test = new MoneyFormatterBuilder().appendAmount(style).toFormatter(); 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; + var style = MoneyAmountStyle.ASCII_DECIMAL_COMMA_NO_GROUPING; assertThat(style.getZeroCharacter()).isEqualTo((Character) '0'); assertThat(style.getPositiveSignCharacter()).isEqualTo((Character) '+'); assertThat(style.getNegativeSignCharacter()).isEqualTo((Character) '-'); @@ -172,14 +172,14 @@ void test_ASCII_DECIMAL_COMMA_NO_GROUPING() { @Test void test_ASCII_DECIMAL_COMMA_NO_GROUPING_print() { - MoneyAmountStyle style = MoneyAmountStyle.ASCII_DECIMAL_COMMA_NO_GROUPING; - MoneyFormatter test = new MoneyFormatterBuilder().appendAmount(style).toFormatter(); + var style = MoneyAmountStyle.ASCII_DECIMAL_COMMA_NO_GROUPING; + var test = new MoneyFormatterBuilder().appendAmount(style).toFormatter(); assertThat(test.print(MONEY)).isEqualTo("87654321,12345678"); } @Test void test_LOCALIZED_GROUPING() { - MoneyAmountStyle style = MoneyAmountStyle.LOCALIZED_GROUPING; + var style = MoneyAmountStyle.LOCALIZED_GROUPING; assertThat(style.getZeroCharacter()).isNull(); assertThat(style.getPositiveSignCharacter()).isNull(); assertThat(style.getNegativeSignCharacter()).isNull(); @@ -193,14 +193,14 @@ void test_LOCALIZED_GROUPING() { @Test void test_LOCALIZED_GROUPING_print() { - MoneyAmountStyle style = MoneyAmountStyle.LOCALIZED_GROUPING; - MoneyFormatter test = new MoneyFormatterBuilder().appendAmount(style).toFormatter(); + var style = MoneyAmountStyle.LOCALIZED_GROUPING; + var test = new MoneyFormatterBuilder().appendAmount(style).toFormatter(); assertThat(test.print(MONEY)).isEqualTo("87,654,321.123,456,78"); } @Test void test_LOCALIZED_NO_GROUPING() { - MoneyAmountStyle style = MoneyAmountStyle.LOCALIZED_NO_GROUPING; + var style = MoneyAmountStyle.LOCALIZED_NO_GROUPING; assertThat(style.getZeroCharacter()).isNull(); assertThat(style.getPositiveSignCharacter()).isNull(); assertThat(style.getNegativeSignCharacter()).isNull(); @@ -214,15 +214,15 @@ void test_LOCALIZED_NO_GROUPING() { @Test void test_LOCALIZED_NO_GROUPING_print() { - MoneyAmountStyle style = MoneyAmountStyle.LOCALIZED_NO_GROUPING; - MoneyFormatter test = new MoneyFormatterBuilder().appendAmount(style).toFormatter(); + var style = MoneyAmountStyle.LOCALIZED_NO_GROUPING; + var test = new MoneyFormatterBuilder().appendAmount(style).toFormatter(); 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(); + var style = MoneyAmountStyle.LOCALIZED_GROUPING.withGroupingStyle(GroupingStyle.BEFORE_DECIMAL_POINT); + var test = new MoneyFormatterBuilder().appendAmount(style).toFormatter(); assertThat(test.print(MONEY)).isEqualTo("87,654,321.12345678"); } @@ -231,7 +231,7 @@ void test_print_groupBeforeDecimal() { //----------------------------------------------------------------------- @Test void test_of_Locale_GB() { - MoneyAmountStyle style = MoneyAmountStyle.of(TEST_GB_LOCALE); + var style = MoneyAmountStyle.of(TEST_GB_LOCALE); assertThat(style.getZeroCharacter()).isEqualTo((Character) '0'); assertThat(style.getPositiveSignCharacter()).isEqualTo((Character) '+'); assertThat(style.getNegativeSignCharacter()).isEqualTo((Character) '-'); @@ -245,7 +245,7 @@ void test_of_Locale_GB() { @Test void test_of_Locale_DE() { - MoneyAmountStyle style = MoneyAmountStyle.of(TEST_DE_LOCALE); + var style = MoneyAmountStyle.of(TEST_DE_LOCALE); assertThat(style.getZeroCharacter()).isEqualTo((Character) '0'); assertThat(style.getPositiveSignCharacter()).isEqualTo((Character) '+'); assertThat(style.getNegativeSignCharacter()).isEqualTo((Character) '-'); @@ -262,7 +262,7 @@ void test_of_Locale_DE() { //----------------------------------------------------------------------- @Test void test_localize_GB() { - MoneyAmountStyle style = MoneyAmountStyle.LOCALIZED_GROUPING.localize(TEST_GB_LOCALE); + var style = MoneyAmountStyle.LOCALIZED_GROUPING.localize(TEST_GB_LOCALE); assertThat(style.getZeroCharacter()).isEqualTo((Character) '0'); assertThat(style.getPositiveSignCharacter()).isEqualTo((Character) '+'); assertThat(style.getNegativeSignCharacter()).isEqualTo((Character) '-'); @@ -276,7 +276,7 @@ void test_localize_GB() { @Test void test_localize_DE() { - MoneyAmountStyle style = MoneyAmountStyle.LOCALIZED_GROUPING.localize(TEST_DE_LOCALE); + var style = MoneyAmountStyle.LOCALIZED_GROUPING.localize(TEST_DE_LOCALE); assertThat(style.getZeroCharacter()).isEqualTo((Character) '0'); assertThat(style.getPositiveSignCharacter()).isEqualTo((Character) '+'); assertThat(style.getNegativeSignCharacter()).isEqualTo((Character) '-'); @@ -290,8 +290,8 @@ void test_localize_DE() { @Test void test_localize_DE_fixedZero() { - MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING.withZeroCharacter('_'); - MoneyAmountStyle style = base.localize(TEST_DE_LOCALE); + var base = MoneyAmountStyle.LOCALIZED_GROUPING.withZeroCharacter('_'); + var style = base.localize(TEST_DE_LOCALE); assertThat(style.getZeroCharacter()).isEqualTo((Character) '_'); assertThat(style.getPositiveSignCharacter()).isEqualTo((Character) '+'); assertThat(style.getNegativeSignCharacter()).isEqualTo((Character) '-'); @@ -305,8 +305,8 @@ void test_localize_DE_fixedZero() { @Test void test_localize_DE_fixedPositive() { - MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING.withPositiveSignCharacter('_'); - MoneyAmountStyle style = base.localize(TEST_DE_LOCALE); + var base = MoneyAmountStyle.LOCALIZED_GROUPING.withPositiveSignCharacter('_'); + var style = base.localize(TEST_DE_LOCALE); assertThat(style.getZeroCharacter()).isEqualTo((Character) '0'); assertThat(style.getPositiveSignCharacter()).isEqualTo((Character) '_'); assertThat(style.getNegativeSignCharacter()).isEqualTo((Character) '-'); @@ -320,8 +320,8 @@ void test_localize_DE_fixedPositive() { @Test void test_localize_DE_fixedNegative() { - MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING.withNegativeSignCharacter('_'); - MoneyAmountStyle style = base.localize(TEST_DE_LOCALE); + var base = MoneyAmountStyle.LOCALIZED_GROUPING.withNegativeSignCharacter('_'); + var style = base.localize(TEST_DE_LOCALE); assertThat(style.getZeroCharacter()).isEqualTo((Character) '0'); assertThat(style.getPositiveSignCharacter()).isEqualTo((Character) '+'); assertThat(style.getNegativeSignCharacter()).isEqualTo((Character) '_'); @@ -335,8 +335,8 @@ void test_localize_DE_fixedNegative() { @Test void test_localize_DE_fixedDecimal() { - MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING.withDecimalPointCharacter('_'); - MoneyAmountStyle style = base.localize(TEST_DE_LOCALE); + var base = MoneyAmountStyle.LOCALIZED_GROUPING.withDecimalPointCharacter('_'); + var style = base.localize(TEST_DE_LOCALE); assertThat(style.getZeroCharacter()).isEqualTo((Character) '0'); assertThat(style.getPositiveSignCharacter()).isEqualTo((Character) '+'); assertThat(style.getNegativeSignCharacter()).isEqualTo((Character) '-'); @@ -350,8 +350,8 @@ void test_localize_DE_fixedDecimal() { @Test void test_localize_DE_fixedGrouping() { - MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING.withGroupingCharacter('_'); - MoneyAmountStyle style = base.localize(TEST_DE_LOCALE); + var base = MoneyAmountStyle.LOCALIZED_GROUPING.withGroupingCharacter('_'); + var style = base.localize(TEST_DE_LOCALE); assertThat(style.getZeroCharacter()).isEqualTo((Character) '0'); assertThat(style.getPositiveSignCharacter()).isEqualTo((Character) '+'); assertThat(style.getNegativeSignCharacter()).isEqualTo((Character) '-'); @@ -365,8 +365,8 @@ void test_localize_DE_fixedGrouping() { @Test void test_localize_DE_fixedZeroAndDecimal() { - MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING.withZeroCharacter('_').withDecimalPointCharacter('-'); - MoneyAmountStyle style = base.localize(TEST_DE_LOCALE); + var base = MoneyAmountStyle.LOCALIZED_GROUPING.withZeroCharacter('_').withDecimalPointCharacter('-'); + var style = base.localize(TEST_DE_LOCALE); assertThat(style.getZeroCharacter()).isEqualTo((Character) '_'); assertThat(style.getPositiveSignCharacter()).isEqualTo((Character) '+'); assertThat(style.getNegativeSignCharacter()).isEqualTo((Character) '-'); @@ -380,7 +380,7 @@ void test_localize_DE_fixedZeroAndDecimal() { @Test void test_localize_DE_noGrouping() { - MoneyAmountStyle style = MoneyAmountStyle.LOCALIZED_NO_GROUPING.localize(TEST_DE_LOCALE); + var style = MoneyAmountStyle.LOCALIZED_NO_GROUPING.localize(TEST_DE_LOCALE); assertThat(style.getZeroCharacter()).isEqualTo((Character) '0'); assertThat(style.getPositiveSignCharacter()).isEqualTo((Character) '+'); assertThat(style.getNegativeSignCharacter()).isEqualTo((Character) '-'); @@ -394,7 +394,7 @@ void test_localize_DE_noGrouping() { @Test void test_localize_LV() { - MoneyAmountStyle style = MoneyAmountStyle.LOCALIZED_NO_GROUPING.localize(TEST_LV_LOCALE); + var style = MoneyAmountStyle.LOCALIZED_NO_GROUPING.localize(TEST_LV_LOCALE); assertThat(style.getZeroCharacter()).isEqualTo((Character) '0'); assertThat(style.getPositiveSignCharacter()).isEqualTo((Character) '+'); assertThat(style.getNegativeSignCharacter()).isEqualTo((Character) '-'); @@ -411,180 +411,180 @@ void test_localize_LV() { //----------------------------------------------------------------------- @Test void test_withZeroCharacter() { - MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING; + var base = MoneyAmountStyle.LOCALIZED_GROUPING; assertThat(base.getZeroCharacter()).isNull(); - MoneyAmountStyle test = base.withZeroCharacter('_'); + var test = base.withZeroCharacter('_'); assertThat(base.getZeroCharacter()).isNull(); assertThat(test.getZeroCharacter()).isEqualTo((Character) '_'); } @Test void test_withZeroCharacter_same() { - MoneyAmountStyle base = MoneyAmountStyle.ASCII_DECIMAL_POINT_GROUP3_COMMA; + var base = MoneyAmountStyle.ASCII_DECIMAL_POINT_GROUP3_COMMA; assertThat(base.getZeroCharacter()).isEqualTo((Character) '0'); - MoneyAmountStyle test = base.withZeroCharacter('0'); + var test = base.withZeroCharacter('0'); assertThat(test).isSameAs(base); } @Test void test_withZeroCharacter_sameNull() { - MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING; + var base = MoneyAmountStyle.LOCALIZED_GROUPING; assertThat(base.getZeroCharacter()).isNull(); - MoneyAmountStyle test = base.withZeroCharacter(null); + var test = base.withZeroCharacter(null); assertThat(test).isSameAs(base); } //----------------------------------------------------------------------- @Test void test_withPositiveSignCharacter() { - MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING; + var base = MoneyAmountStyle.LOCALIZED_GROUPING; assertThat(base.getPositiveSignCharacter()).isNull(); - MoneyAmountStyle test = base.withPositiveSignCharacter('_'); + var test = base.withPositiveSignCharacter('_'); assertThat(base.getPositiveSignCharacter()).isNull(); assertThat(test.getPositiveSignCharacter()).isEqualTo((Character) '_'); } @Test void test_withPositiveSignCharacter_same() { - MoneyAmountStyle base = MoneyAmountStyle.ASCII_DECIMAL_POINT_GROUP3_COMMA; + var base = MoneyAmountStyle.ASCII_DECIMAL_POINT_GROUP3_COMMA; assertThat(base.getPositiveSignCharacter()).isEqualTo((Character) '+'); - MoneyAmountStyle test = base.withPositiveSignCharacter('+'); + var test = base.withPositiveSignCharacter('+'); assertThat(test).isSameAs(base); } @Test void test_withPositiveSignCharacter_sameNull() { - MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING; + var base = MoneyAmountStyle.LOCALIZED_GROUPING; assertThat(base.getPositiveSignCharacter()).isNull(); - MoneyAmountStyle test = base.withPositiveSignCharacter(null); + var test = base.withPositiveSignCharacter(null); assertThat(test).isSameAs(base); } //----------------------------------------------------------------------- @Test void test_withNegativeSignCharacter() { - MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING; + var base = MoneyAmountStyle.LOCALIZED_GROUPING; assertThat(base.getNegativeSignCharacter()).isNull(); - MoneyAmountStyle test = base.withNegativeSignCharacter('_'); + var test = base.withNegativeSignCharacter('_'); assertThat(base.getNegativeSignCharacter()).isNull(); assertThat(test.getNegativeSignCharacter()).isEqualTo((Character) '_'); } @Test void test_withNegativeSignCharacter_same() { - MoneyAmountStyle base = MoneyAmountStyle.ASCII_DECIMAL_POINT_GROUP3_COMMA; + var base = MoneyAmountStyle.ASCII_DECIMAL_POINT_GROUP3_COMMA; assertThat(base.getNegativeSignCharacter()).isEqualTo((Character) '-'); - MoneyAmountStyle test = base.withNegativeSignCharacter('-'); + var test = base.withNegativeSignCharacter('-'); assertThat(test).isSameAs(base); } @Test void test_withNegativeSignCharacter_sameNull() { - MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING; + var base = MoneyAmountStyle.LOCALIZED_GROUPING; assertThat(base.getNegativeSignCharacter()).isNull(); - MoneyAmountStyle test = base.withNegativeSignCharacter(null); + var test = base.withNegativeSignCharacter(null); assertThat(test).isSameAs(base); } //----------------------------------------------------------------------- @Test void test_withDecimalPointCharacter() { - MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING; + var base = MoneyAmountStyle.LOCALIZED_GROUPING; assertThat(base.getDecimalPointCharacter()).isNull(); - MoneyAmountStyle test = base.withDecimalPointCharacter('_'); + var test = base.withDecimalPointCharacter('_'); assertThat(base.getDecimalPointCharacter()).isNull(); assertThat(test.getDecimalPointCharacter()).isEqualTo((Character) '_'); } @Test void test_withDecimalPointCharacter_same() { - MoneyAmountStyle base = MoneyAmountStyle.ASCII_DECIMAL_POINT_GROUP3_COMMA; + var base = MoneyAmountStyle.ASCII_DECIMAL_POINT_GROUP3_COMMA; assertThat(base.getDecimalPointCharacter()).isEqualTo((Character) '.'); - MoneyAmountStyle test = base.withDecimalPointCharacter('.'); + var test = base.withDecimalPointCharacter('.'); assertThat(test).isSameAs(base); } @Test void test_withDecimalPointCharacter_sameNull() { - MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING; + var base = MoneyAmountStyle.LOCALIZED_GROUPING; assertThat(base.getDecimalPointCharacter()).isNull(); - MoneyAmountStyle test = base.withDecimalPointCharacter(null); + var test = base.withDecimalPointCharacter(null); assertThat(test).isSameAs(base); } //----------------------------------------------------------------------- @Test void test_withGroupingCharacter() { - MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING; + var base = MoneyAmountStyle.LOCALIZED_GROUPING; assertThat(base.getGroupingCharacter()).isNull(); - MoneyAmountStyle test = base.withGroupingCharacter('_'); + var test = base.withGroupingCharacter('_'); assertThat(base.getGroupingCharacter()).isNull(); assertThat(test.getGroupingCharacter()).isEqualTo((Character) '_'); } @Test void test_withGroupingCharacter_same() { - MoneyAmountStyle base = MoneyAmountStyle.ASCII_DECIMAL_POINT_GROUP3_COMMA; + var base = MoneyAmountStyle.ASCII_DECIMAL_POINT_GROUP3_COMMA; assertThat(base.getGroupingCharacter()).isEqualTo((Character) ','); - MoneyAmountStyle test = base.withGroupingCharacter(','); + var test = base.withGroupingCharacter(','); assertThat(test).isSameAs(base); } @Test void test_withGroupingCharacter_sameNull() { - MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING; + var base = MoneyAmountStyle.LOCALIZED_GROUPING; assertThat(base.getGroupingCharacter()).isNull(); - MoneyAmountStyle test = base.withGroupingCharacter(null); + var test = base.withGroupingCharacter(null); assertThat(test).isSameAs(base); } //----------------------------------------------------------------------- @Test void test_withGroupingStyle() { - MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING; + var base = MoneyAmountStyle.LOCALIZED_GROUPING; assertThat(base.getGroupingStyle()).isEqualTo(GroupingStyle.FULL); - MoneyAmountStyle test = base.withGroupingStyle(GroupingStyle.BEFORE_DECIMAL_POINT); + var test = base.withGroupingStyle(GroupingStyle.BEFORE_DECIMAL_POINT); assertThat(base.getGroupingStyle()).isEqualTo(GroupingStyle.FULL); assertThat(test.getGroupingStyle()).isEqualTo(GroupingStyle.BEFORE_DECIMAL_POINT); } @Test void test_withGroupingStyle_same() { - MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING; + var base = MoneyAmountStyle.LOCALIZED_GROUPING; assertThat(base.getGroupingStyle()).isEqualTo(GroupingStyle.FULL); - MoneyAmountStyle test = base.withGroupingStyle(GroupingStyle.FULL); + var test = base.withGroupingStyle(GroupingStyle.FULL); assertThat(test).isSameAs(base); } //----------------------------------------------------------------------- @Test void test_withGroupingSize() { - MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING; + var base = MoneyAmountStyle.LOCALIZED_GROUPING; assertThat(base.getGroupingSize()).isNull(); - MoneyAmountStyle test = base.withGroupingSize(6); + var test = base.withGroupingSize(6); assertThat(base.getGroupingSize()).isNull(); assertThat(test.getGroupingSize()).isEqualTo((Integer) 6); } @Test void test_withGroupingSize_same() { - MoneyAmountStyle base = MoneyAmountStyle.ASCII_DECIMAL_POINT_GROUP3_COMMA; + var base = MoneyAmountStyle.ASCII_DECIMAL_POINT_GROUP3_COMMA; assertThat(base.getGroupingSize()).isEqualTo((Integer) 3); - MoneyAmountStyle test = base.withGroupingSize(3); + var test = base.withGroupingSize(3); assertThat(test).isSameAs(base); } @Test void test_withGroupingSize_sameNull() { - MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING; + var base = MoneyAmountStyle.LOCALIZED_GROUPING; assertThat(base.getGroupingSize()).isNull(); - MoneyAmountStyle test = base.withGroupingSize(null); + var test = base.withGroupingSize(null); assertThat(test).isSameAs(base); } @Test void test_withGroupingSize_negative() { - MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING; + var base = MoneyAmountStyle.LOCALIZED_GROUPING; assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> base.withGroupingSize(-1)); } @@ -592,36 +592,36 @@ void test_withGroupingSize_negative() { //----------------------------------------------------------------------- @Test void test_withForcedDecimalPoint() { - MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING; + var base = MoneyAmountStyle.LOCALIZED_GROUPING; assertThat(base.isForcedDecimalPoint()).isFalse(); - MoneyAmountStyle test = base.withForcedDecimalPoint(true); + var test = base.withForcedDecimalPoint(true); assertThat(base.isForcedDecimalPoint()).isFalse(); assertThat(test.isForcedDecimalPoint()).isTrue(); } @Test void test_withForcedDecimalPoint_same() { - MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING; + var base = MoneyAmountStyle.LOCALIZED_GROUPING; assertThat(base.isForcedDecimalPoint()).isFalse(); - MoneyAmountStyle test = base.withForcedDecimalPoint(false); + var test = base.withForcedDecimalPoint(false); assertThat(test).isSameAs(base); } //----------------------------------------------------------------------- @Test void test_withAbsValue() { - MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING; + var base = MoneyAmountStyle.LOCALIZED_GROUPING; assertThat(base.isAbsValue()).isFalse(); - MoneyAmountStyle test = base.withAbsValue(true); + var test = base.withAbsValue(true); assertThat(base.isAbsValue()).isFalse(); assertThat(test.isAbsValue()).isTrue(); } @Test void test_withAbsValue_same() { - MoneyAmountStyle base = MoneyAmountStyle.LOCALIZED_GROUPING; + var base = MoneyAmountStyle.LOCALIZED_GROUPING; assertThat(base.isAbsValue()).isFalse(); - MoneyAmountStyle test = base.withAbsValue(false); + var test = base.withAbsValue(false); assertThat(test).isSameAs(base); } @@ -630,26 +630,26 @@ void test_withAbsValue_same() { //----------------------------------------------------------------------- @Test void test_equals_same() { - MoneyAmountStyle a = MoneyAmountStyle.LOCALIZED_GROUPING; + var a = MoneyAmountStyle.LOCALIZED_GROUPING; assertThat(a).isEqualTo(a); } @Test void test_equals_otherType() { - MoneyAmountStyle a = MoneyAmountStyle.LOCALIZED_GROUPING; + var a = MoneyAmountStyle.LOCALIZED_GROUPING; assertThat(new Object()).isNotEqualTo(a); } @Test void test_equals_null() { - MoneyAmountStyle a = MoneyAmountStyle.LOCALIZED_GROUPING; + var a = MoneyAmountStyle.LOCALIZED_GROUPING; assertThat(a).isNotEqualTo(null); } @Test void test_equals_equal_zeroChar() { - MoneyAmountStyle a = MoneyAmountStyle.LOCALIZED_GROUPING.withZeroCharacter('_'); - MoneyAmountStyle b = MoneyAmountStyle.LOCALIZED_GROUPING.withZeroCharacter('_'); + var a = MoneyAmountStyle.LOCALIZED_GROUPING.withZeroCharacter('_'); + var b = MoneyAmountStyle.LOCALIZED_GROUPING.withZeroCharacter('_'); assertThat(b).isEqualTo(a); assertThat(a).isEqualTo(b); assertThat(a.hashCode()).isEqualTo(b.hashCode()); @@ -657,16 +657,16 @@ void test_equals_equal_zeroChar() { @Test void test_equals_notEqual_zeroChar() { - MoneyAmountStyle a = MoneyAmountStyle.LOCALIZED_GROUPING; - MoneyAmountStyle b = MoneyAmountStyle.LOCALIZED_GROUPING.withZeroCharacter('_'); + var a = MoneyAmountStyle.LOCALIZED_GROUPING; + var b = MoneyAmountStyle.LOCALIZED_GROUPING.withZeroCharacter('_'); 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('_'); + var a = MoneyAmountStyle.LOCALIZED_GROUPING.withPositiveSignCharacter('_'); + var b = MoneyAmountStyle.LOCALIZED_GROUPING.withPositiveSignCharacter('_'); assertThat(b).isEqualTo(a); assertThat(a).isEqualTo(b); assertThat(a.hashCode()).isEqualTo(b.hashCode()); @@ -674,16 +674,16 @@ void test_equals_equal_positiveChar() { @Test void test_equals_notEqual_positiveChar() { - MoneyAmountStyle a = MoneyAmountStyle.LOCALIZED_GROUPING; - MoneyAmountStyle b = MoneyAmountStyle.LOCALIZED_GROUPING.withPositiveSignCharacter('_'); + var a = MoneyAmountStyle.LOCALIZED_GROUPING; + var b = MoneyAmountStyle.LOCALIZED_GROUPING.withPositiveSignCharacter('_'); 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('_'); + var a = MoneyAmountStyle.LOCALIZED_GROUPING.withNegativeSignCharacter('_'); + var b = MoneyAmountStyle.LOCALIZED_GROUPING.withNegativeSignCharacter('_'); assertThat(b).isEqualTo(a); assertThat(a).isEqualTo(b); assertThat(a.hashCode()).isEqualTo(b.hashCode()); @@ -691,16 +691,16 @@ void test_equals_equal_negativeChar() { @Test void test_equals_notEqual_negativeChar() { - MoneyAmountStyle a = MoneyAmountStyle.LOCALIZED_GROUPING; - MoneyAmountStyle b = MoneyAmountStyle.LOCALIZED_GROUPING.withNegativeSignCharacter('_'); + var a = MoneyAmountStyle.LOCALIZED_GROUPING; + var b = MoneyAmountStyle.LOCALIZED_GROUPING.withNegativeSignCharacter('_'); 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('_'); + var a = MoneyAmountStyle.LOCALIZED_GROUPING.withDecimalPointCharacter('_'); + var b = MoneyAmountStyle.LOCALIZED_GROUPING.withDecimalPointCharacter('_'); assertThat(b).isEqualTo(a); assertThat(a).isEqualTo(b); assertThat(a.hashCode()).isEqualTo(b.hashCode()); @@ -708,16 +708,16 @@ void test_equals_equal_decimalPointChar() { @Test void test_equals_notEqual_decimalPointChar() { - MoneyAmountStyle a = MoneyAmountStyle.LOCALIZED_GROUPING; - MoneyAmountStyle b = MoneyAmountStyle.LOCALIZED_GROUPING.withDecimalPointCharacter('_'); + var a = MoneyAmountStyle.LOCALIZED_GROUPING; + var b = MoneyAmountStyle.LOCALIZED_GROUPING.withDecimalPointCharacter('_'); 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('_'); + var a = MoneyAmountStyle.LOCALIZED_GROUPING.withGroupingCharacter('_'); + var b = MoneyAmountStyle.LOCALIZED_GROUPING.withGroupingCharacter('_'); assertThat(b).isEqualTo(a); assertThat(a).isEqualTo(b); assertThat(a.hashCode()).isEqualTo(b.hashCode()); @@ -725,16 +725,16 @@ void test_equals_equal_groupingChar() { @Test void test_equals_notEqual_groupingChar() { - MoneyAmountStyle a = MoneyAmountStyle.LOCALIZED_GROUPING; - MoneyAmountStyle b = MoneyAmountStyle.LOCALIZED_GROUPING.withGroupingCharacter('_'); + var a = MoneyAmountStyle.LOCALIZED_GROUPING; + var b = MoneyAmountStyle.LOCALIZED_GROUPING.withGroupingCharacter('_'); 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); + var a = MoneyAmountStyle.LOCALIZED_GROUPING.withGroupingStyle(GroupingStyle.BEFORE_DECIMAL_POINT); + var b = MoneyAmountStyle.LOCALIZED_GROUPING.withGroupingStyle(GroupingStyle.BEFORE_DECIMAL_POINT); assertThat(b).isEqualTo(a); assertThat(a).isEqualTo(b); assertThat(a.hashCode()).isEqualTo(b.hashCode()); @@ -742,16 +742,16 @@ void test_equals_equal_groupingStyle() { @Test void test_equals_notEqual_groupingStyle() { - MoneyAmountStyle a = MoneyAmountStyle.LOCALIZED_GROUPING.withGroupingStyle(GroupingStyle.BEFORE_DECIMAL_POINT); - MoneyAmountStyle b = MoneyAmountStyle.LOCALIZED_GROUPING.withGroupingStyle(GroupingStyle.NONE); + var a = MoneyAmountStyle.LOCALIZED_GROUPING.withGroupingStyle(GroupingStyle.BEFORE_DECIMAL_POINT); + var b = MoneyAmountStyle.LOCALIZED_GROUPING.withGroupingStyle(GroupingStyle.NONE); 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); + var a = MoneyAmountStyle.LOCALIZED_GROUPING.withGroupingSize(4); + var b = MoneyAmountStyle.LOCALIZED_GROUPING.withGroupingSize(4); assertThat(b).isEqualTo(a); assertThat(a).isEqualTo(b); assertThat(a.hashCode()).isEqualTo(b.hashCode()); @@ -759,16 +759,16 @@ void test_equals_equal_groupingSize() { @Test void test_equals_notEqual_groupingSize() { - MoneyAmountStyle a = MoneyAmountStyle.LOCALIZED_GROUPING; - MoneyAmountStyle b = MoneyAmountStyle.LOCALIZED_GROUPING.withGroupingSize(4); + var a = MoneyAmountStyle.LOCALIZED_GROUPING; + var b = MoneyAmountStyle.LOCALIZED_GROUPING.withGroupingSize(4); 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); + var a = MoneyAmountStyle.LOCALIZED_GROUPING.withForcedDecimalPoint(true).withForcedDecimalPoint(false); + var b = MoneyAmountStyle.LOCALIZED_GROUPING.withForcedDecimalPoint(true).withForcedDecimalPoint(false); assertThat(b).isEqualTo(a); assertThat(a).isEqualTo(b); assertThat(a.hashCode()).isEqualTo(b.hashCode()); @@ -776,8 +776,8 @@ void test_equals_equal_forcedDecimalPoint_false() { @Test void test_equals_equal_forcedDecimalPoint_true() { - MoneyAmountStyle a = MoneyAmountStyle.LOCALIZED_GROUPING.withForcedDecimalPoint(true); - MoneyAmountStyle b = MoneyAmountStyle.LOCALIZED_GROUPING.withForcedDecimalPoint(true); + var a = MoneyAmountStyle.LOCALIZED_GROUPING.withForcedDecimalPoint(true); + var b = MoneyAmountStyle.LOCALIZED_GROUPING.withForcedDecimalPoint(true); assertThat(b).isEqualTo(a); assertThat(a).isEqualTo(b); assertThat(a.hashCode()).isEqualTo(b.hashCode()); @@ -785,16 +785,16 @@ void test_equals_equal_forcedDecimalPoint_true() { @Test void test_equals_notEqual_forcedDecimalPoint() { - MoneyAmountStyle a = MoneyAmountStyle.LOCALIZED_GROUPING; - MoneyAmountStyle b = MoneyAmountStyle.LOCALIZED_GROUPING.withForcedDecimalPoint(true); + var a = MoneyAmountStyle.LOCALIZED_GROUPING; + var b = MoneyAmountStyle.LOCALIZED_GROUPING.withForcedDecimalPoint(true); 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); + var a = MoneyAmountStyle.LOCALIZED_GROUPING.withAbsValue(true).withAbsValue(false); + var b = MoneyAmountStyle.LOCALIZED_GROUPING.withAbsValue(true).withAbsValue(false); assertThat(b).isEqualTo(a); assertThat(a).isEqualTo(b); assertThat(a.hashCode()).isEqualTo(b.hashCode()); @@ -802,8 +802,8 @@ void test_equals_equal_absValue_false() { @Test void test_equals_equal_absValue_true() { - MoneyAmountStyle a = MoneyAmountStyle.LOCALIZED_GROUPING.withAbsValue(true); - MoneyAmountStyle b = MoneyAmountStyle.LOCALIZED_GROUPING.withAbsValue(true); + var a = MoneyAmountStyle.LOCALIZED_GROUPING.withAbsValue(true); + var b = MoneyAmountStyle.LOCALIZED_GROUPING.withAbsValue(true); assertThat(b).isEqualTo(a); assertThat(a).isEqualTo(b); assertThat(a.hashCode()).isEqualTo(b.hashCode()); @@ -811,8 +811,8 @@ void test_equals_equal_absValue_true() { @Test void test_equals_notEqual_absValue() { - MoneyAmountStyle a = MoneyAmountStyle.LOCALIZED_GROUPING; - MoneyAmountStyle b = MoneyAmountStyle.LOCALIZED_GROUPING.withAbsValue(true); + var a = MoneyAmountStyle.LOCALIZED_GROUPING; + var b = MoneyAmountStyle.LOCALIZED_GROUPING.withAbsValue(true); assertThat(b).isNotEqualTo(a); assertThat(a).isNotEqualTo(b); } @@ -820,7 +820,7 @@ void test_equals_notEqual_absValue() { //----------------------------------------------------------------------- @Test void test_toString() { - MoneyAmountStyle test = MoneyAmountStyle.LOCALIZED_GROUPING; + var test = MoneyAmountStyle.LOCALIZED_GROUPING; 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 81cda0f..c6f134a 100644 --- a/src/test/java/org/joda/money/format/TestMoneyFormatter.java +++ b/src/test/java/org/joda/money/format/TestMoneyFormatter.java @@ -59,11 +59,7 @@ void beforeMethod() { .appendLiteral(" hello") .toFormatter(); iCannotPrint = new MoneyFormatterBuilder() - .append(null, new MoneyParser() { - @Override - public void parse(MoneyParseContext context) { - } - }) + .append(null, context -> {}) .toFormatter(); iParseTest = new MoneyFormatterBuilder() .appendAmountLocalized() @@ -71,11 +67,7 @@ public void parse(MoneyParseContext context) { .appendCurrencyCode() .toFormatter(); iCannotParse = new MoneyFormatterBuilder() - .append(new MoneyPrinter() { - @Override - public void print(MoneyPrintContext context, Appendable appendable, BigMoney money) throws IOException { - } - }, null) + .append((context, appendable, money) -> {}, null) .toFormatter(); } @@ -90,14 +82,14 @@ void afterMethod() { //----------------------------------------------------------------------- @Test void test_serialization() throws Exception { - MoneyFormatter a = iPrintTest; - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - try (ObjectOutputStream oos = new ObjectOutputStream(baos)) { + var a = iPrintTest; + var baos = new ByteArrayOutputStream(); + try (var oos = new ObjectOutputStream(baos)) { oos.writeObject(a); oos.close(); - ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); - MoneyFormatter input = (MoneyFormatter) ois.readObject(); - Money value = MONEY_GBP_12_34; + var ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); + var input = (MoneyFormatter) ois.readObject(); + var value = MONEY_GBP_12_34; assertThat(input.print(value)).isEqualTo(a.print(value)); } } @@ -112,7 +104,7 @@ void test_getLocale() { @Test void test_withLocale() { - MoneyFormatter test = iPrintTest.withLocale(TEST_FR_LOCALE); + var test = iPrintTest.withLocale(TEST_FR_LOCALE); assertThat(iPrintTest.getLocale()).isEqualTo(TEST_GB_LOCALE); assertThat(test.getLocale()).isEqualTo(TEST_FR_LOCALE); } @@ -139,7 +131,7 @@ void test_print_BigMoneyProvider_cannotPrint() { @Test void test_print_BigMoneyProvider_nullBigMoneyProvider() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> iPrintTest.print((BigMoneyProvider) null)); } @@ -148,14 +140,14 @@ void test_print_BigMoneyProvider_nullBigMoneyProvider() { //----------------------------------------------------------------------- @Test void test_print_AppendableBigMoneyProvider() { - StringBuilder buf = new StringBuilder(); + var buf = new StringBuilder(); iPrintTest.print(buf, MONEY_GBP_12_34); assertThat(buf).hasToString("GBP hello"); } @Test void test_print_AppendableBigMoneyProvider_IOException() { - Appendable appendable = new IOAppendable(); + Appendable appendable = new IOAppendable(); assertThatExceptionOfType(MoneyFormatException.class) .isThrownBy(() -> iPrintTest.print(appendable, MONEY_GBP_12_34)) .withCauseInstanceOf(IOException.class); @@ -163,19 +155,19 @@ void test_print_AppendableBigMoneyProvider_IOException() { @Test void test_print_AppendableBigMoneyProvider_cannotPrint() { - assertThatExceptionOfType(UnsupportedOperationException.class) + assertThatExceptionOfType(UnsupportedOperationException.class) .isThrownBy(() -> iCannotPrint.print(new StringBuilder(), MONEY_GBP_12_34)); } @Test void test_print_AppendableBigMoneyProvider_nullAppendable() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> iPrintTest.print((Appendable) null, MONEY_GBP_12_34)); } @Test void test_print_AppendableBigMoneyProvider_nullBigMoneyProvider() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> iPrintTest.print(new StringBuilder(), (BigMoneyProvider) null)); } @@ -184,7 +176,7 @@ void test_print_AppendableBigMoneyProvider_nullBigMoneyProvider() { //----------------------------------------------------------------------- @Test void test_printIO_AppendableBigMoneyProvider() throws IOException { - StringBuilder buf = new StringBuilder(); + var buf = new StringBuilder(); iPrintTest.printIO(buf, MONEY_GBP_12_34); assertThat(buf).hasToString("GBP hello"); } @@ -192,25 +184,25 @@ void test_printIO_AppendableBigMoneyProvider() throws IOException { @Test void test_printIO_AppendableBigMoneyProvider_IOException() { Appendable appendable = new IOAppendable(); - assertThatExceptionOfType(IOException.class) + assertThatExceptionOfType(IOException.class) .isThrownBy(() -> iPrintTest.printIO(appendable, MONEY_GBP_12_34)); } @Test void test_printIO_AppendableBigMoneyProvider_cannotPrint() { - assertThatExceptionOfType(UnsupportedOperationException.class) + assertThatExceptionOfType(UnsupportedOperationException.class) .isThrownBy(() -> iCannotPrint.printIO(new StringBuilder(), MONEY_GBP_12_34)); } @Test void test_printIO_AppendableBigMoneyProvider_nullAppendable() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> iPrintTest.printIO((Appendable) null, MONEY_GBP_12_34)); } @Test void test_printIO_AppendableBigMoneyProvider_nullBigMoneyProvider() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> iPrintTest.printIO(new StringBuilder(), (BigMoneyProvider) null)); } @@ -220,31 +212,31 @@ void test_printIO_AppendableBigMoneyProvider_nullBigMoneyProvider() { @Test void test_parseBigMoney_CharSequence() { CharSequence input = new StringBuilder("12.34 GBP"); - BigMoney test = iParseTest.parseBigMoney(input); + var test = iParseTest.parseBigMoney(input); assertThat(test).isEqualTo(MONEY_GBP_12_34.toBigMoney()); } @Test void test_parseBigMoney_CharSequence_invalidCurrency() { - assertThatExceptionOfType(MoneyFormatException.class) + assertThatExceptionOfType(MoneyFormatException.class) .isThrownBy(() -> iParseTest.parseBigMoney("12.34 GBX")); } @Test void test_parseBigMoney_CharSequence_notFullyParsed() { - assertThatExceptionOfType(MoneyFormatException.class) + assertThatExceptionOfType(MoneyFormatException.class) .isThrownBy(() -> iParseTest.parseBigMoney("12.34 GBP X")); } @Test void test_parseBigMoney_CharSequence_incomplete() { - assertThatExceptionOfType(MoneyFormatException.class) + assertThatExceptionOfType(MoneyFormatException.class) .isThrownBy(() -> iParseTest.parseBigMoney("12.34 GBP ")); } @Test void test_parseBigMoney_CharSequence_incompleteLongText() { - assertThatExceptionOfType(MoneyFormatException.class) + assertThatExceptionOfType(MoneyFormatException.class) .isThrownBy( () -> iParseTest .parseBigMoney("12.34 GBP ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAB")); @@ -252,26 +244,26 @@ void test_parseBigMoney_CharSequence_incompleteLongText() { @Test void test_parseBigMoney_CharSequence_incompleteEmptyParser() { - assertThatExceptionOfType(MoneyFormatException.class) + assertThatExceptionOfType(MoneyFormatException.class) .isThrownBy(() -> iCannotPrint.parseBigMoney("12.34 GBP")); } @Test void test_parseBigMoney_CharSequence_missingCurrency() { - MoneyFormatter f = new MoneyFormatterBuilder().appendAmount().toFormatter(); - assertThatExceptionOfType(MoneyFormatException.class) + var f = new MoneyFormatterBuilder().appendAmount().toFormatter(); + assertThatExceptionOfType(MoneyFormatException.class) .isThrownBy(() -> f.parseBigMoney("12.34")); } @Test void test_parseBigMoney_CharSequence_cannotParse() { - assertThatExceptionOfType(UnsupportedOperationException.class) + assertThatExceptionOfType(UnsupportedOperationException.class) .isThrownBy(() -> iCannotParse.parseBigMoney(new StringBuilder())); } @Test void test_parseBigMoney_CharSequence_nullCharSequence() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> iParseTest.parseBigMoney((CharSequence) null)); } @@ -281,37 +273,37 @@ void test_parseBigMoney_CharSequence_nullCharSequence() { @Test void test_parseMoney_CharSequence() { CharSequence input = new StringBuilder("12.34 GBP"); - Money test = iParseTest.parseMoney(input); + var test = iParseTest.parseMoney(input); assertThat(test).isEqualTo(MONEY_GBP_12_34); } @Test void test_parseMoney_CharSequence_invalidCurrency() { - assertThatExceptionOfType(MoneyFormatException.class) + assertThatExceptionOfType(MoneyFormatException.class) .isThrownBy(() -> iParseTest.parseMoney("12.34 GBX")); } @Test void test_parseMoney_CharSequence_notFullyParsed() { - assertThatExceptionOfType(MoneyFormatException.class) + assertThatExceptionOfType(MoneyFormatException.class) .isThrownBy(() -> iParseTest.parseMoney("12.34 GBP X")); } @Test void test_parseMoney_CharSequence_incomplete() { - assertThatExceptionOfType(MoneyFormatException.class) + assertThatExceptionOfType(MoneyFormatException.class) .isThrownBy(() -> iCannotPrint.parseMoney("12.34 GBP")); } @Test void test_parseMoney_CharSequence_cannotParse() { - assertThatExceptionOfType(UnsupportedOperationException.class) + assertThatExceptionOfType(UnsupportedOperationException.class) .isThrownBy(() -> iCannotParse.parseMoney(new StringBuilder())); } @Test void test_parseMoney_CharSequence_nullCharSequence() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> iParseTest.parseMoney((CharSequence) null)); } @@ -354,7 +346,7 @@ void test_parse_CharSequenceInt( boolean complete) { CharSequence input = new StringBuilder(str); - MoneyParseContext test = iParseTest.parse(input, 0); + var test = iParseTest.parse(input, 0); assertThat(test.getAmount()).isEqualTo(amount); assertThat(test.getCurrency()).isEqualTo(currency); assertThat(test.getIndex()).isEqualTo(index); @@ -364,7 +356,7 @@ void test_parse_CharSequenceInt( assertThat(test.isError()).isEqualTo(error); assertThat(test.isFullyParsed()).isEqualTo(fullyParsed); assertThat(test.isComplete()).isEqualTo(complete); - ParsePosition pp = new ParsePosition(index); + var pp = new ParsePosition(index); pp.setErrorIndex(errorIndex); assertThat(test.toParsePosition()).isEqualTo(pp); } @@ -372,7 +364,7 @@ void test_parse_CharSequenceInt( @Test void test_parse_CharSequenceInt_incomplete() { // this parser does nothing - MoneyParseContext test = iCannotPrint.parse("12.34 GBP", 0); + var test = iCannotPrint.parse("12.34 GBP", 0); assertThat(test.getAmount()).isNull(); assertThat(test.getCurrency()).isNull(); assertThat(test.getIndex()).isEqualTo(0); @@ -386,9 +378,9 @@ void test_parse_CharSequenceInt_incomplete() { @Test void test_parse_CharSequenceInt_continueAfterDoubleDecimal() { - MoneyFormatter f = new MoneyFormatterBuilder() + var f = new MoneyFormatterBuilder() .appendAmountLocalized().appendLiteral(".").appendCurrencyCode().toFormatter(); - MoneyParseContext test = f.parse("12..GBP", 0); + var test = f.parse("12..GBP", 0); assertThat(test.getAmount()).isEqualTo(BigDecimal.valueOf(12)); assertThat(test.getCurrency()).isEqualTo(CurrencyUnit.of("GBP")); assertThat(test.getIndex()).isEqualTo(7); @@ -402,9 +394,9 @@ void test_parse_CharSequenceInt_continueAfterDoubleDecimal() { @Test void test_parse_CharSequenceInt_continueAfterSingleComma() { - MoneyFormatter f = new MoneyFormatterBuilder() + var f = new MoneyFormatterBuilder() .appendAmountLocalized().appendLiteral(",").appendCurrencyCode().toFormatter(); - MoneyParseContext test = f.parse("12,GBP", 0); + var test = f.parse("12,GBP", 0); assertThat(test.getAmount()).isEqualTo(BigDecimal.valueOf(12)); assertThat(test.getCurrency()).isEqualTo(CurrencyUnit.of("GBP")); assertThat(test.getIndex()).isEqualTo(6); @@ -418,9 +410,9 @@ void test_parse_CharSequenceInt_continueAfterSingleComma() { @Test void test_parse_CharSequenceInt_continueAfterDoubleComma() { - MoneyFormatter f = new MoneyFormatterBuilder() + var f = new MoneyFormatterBuilder() .appendAmountLocalized().appendLiteral(",,").appendCurrencyCode().toFormatter(); - MoneyParseContext test = f.parse("12,,GBP", 0); + var test = f.parse("12,,GBP", 0); assertThat(test.getAmount()).isEqualTo(BigDecimal.valueOf(12)); assertThat(test.getCurrency()).isEqualTo(CurrencyUnit.of("GBP")); assertThat(test.getIndex()).isEqualTo(7); @@ -434,64 +426,64 @@ void test_parse_CharSequenceInt_continueAfterDoubleComma() { @Test void test_parse_CharSequenceInt_cannotParse() { - assertThatExceptionOfType(UnsupportedOperationException.class) + assertThatExceptionOfType(UnsupportedOperationException.class) .isThrownBy(() -> iCannotParse.parse(new StringBuilder(), 0)); } @Test void test_parse_CharSequenceInt_nullCharSequence() { - assertThatExceptionOfType(NullPointerException.class) + assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> iParseTest.parse((CharSequence) null, 0)); } @Test void test_parse_CharSequenceInt_startIndexTooSmall() { - assertThatExceptionOfType(IndexOutOfBoundsException.class) + assertThatExceptionOfType(IndexOutOfBoundsException.class) .isThrownBy(() -> iParseTest.parse("", -1)); } @Test void test_parse_CharSequenceInt_startIndexTooBig() { - assertThatExceptionOfType(IndexOutOfBoundsException.class) + assertThatExceptionOfType(IndexOutOfBoundsException.class) .isThrownBy(() -> iParseTest.parse("", 1)); } //----------------------------------------------------------------------- @Test void test_printParse_zeroChar() { - MoneyAmountStyle style = MoneyAmountStyle.ASCII_DECIMAL_POINT_GROUP3_COMMA.withZeroCharacter('A'); - MoneyFormatter f = new MoneyFormatterBuilder().appendCurrencyCode().appendLiteral(" ").appendAmount(style).toFormatter(); + var style = MoneyAmountStyle.ASCII_DECIMAL_POINT_GROUP3_COMMA.withZeroCharacter('A'); + var f = new MoneyFormatterBuilder().appendCurrencyCode().appendLiteral(" ").appendAmount(style).toFormatter(); 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() { - assertThatExceptionOfType(MoneyFormatException.class) + assertThatExceptionOfType(MoneyFormatException.class) .isThrownBy(() -> iParseTest.parseMoney("GBP hello notfullyparsed")); } @Test void test_parseMoney_noAmount() { - assertThatExceptionOfType(MoneyFormatException.class) + assertThatExceptionOfType(MoneyFormatException.class) .isThrownBy(() -> iParseTest.parseMoney("GBP hello")); } @Test void test_parseBigMoney_notFullyParsed() { - assertThatExceptionOfType(MoneyFormatException.class) + assertThatExceptionOfType(MoneyFormatException.class) .isThrownBy(() -> iParseTest.parseBigMoney("GBP hello notfullyparsed")); } @Test void test_parseBigMoney_noAmount() { - assertThatExceptionOfType(MoneyFormatException.class) + assertThatExceptionOfType(MoneyFormatException.class) .isThrownBy(() -> iParseTest.parseBigMoney("GBP hello")); } @Test void test_parse_notFullyParsed() { - MoneyParseContext context = iParseTest.parse("GBP hello notfullyparsed", 1); + var context = iParseTest.parse("GBP hello notfullyparsed", 1); assertThatExceptionOfType(MoneyFormatException.class) .isThrownBy(() -> context.toBigMoney()); } @@ -526,7 +518,7 @@ public String toString() { return "B"; } }; - MoneyFormatter f = new MoneyFormatterBuilder().append(printer, parser).toFormatter(); + var f = new MoneyFormatterBuilder().append(printer, parser).toFormatter(); 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 a2ca64a..4ab44fc 100644 --- a/src/test/java/org/joda/money/format/TestMoneyFormatterBuilder.java +++ b/src/test/java/org/joda/money/format/TestMoneyFormatterBuilder.java @@ -18,7 +18,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType; -import java.io.IOException; import java.math.BigDecimal; import java.text.DecimalFormatSymbols; import java.util.Locale; @@ -75,7 +74,7 @@ void afterMethod() { //----------------------------------------------------------------------- @Test void test_empty() { - MoneyFormatter test = iBuilder.toFormatter(); + var test = iBuilder.toFormatter(); assertThat(test.print(GBP_2_34)).isEmpty(); assertThat(test).hasToString(""); } @@ -84,7 +83,7 @@ void test_empty() { @Test void test_appendCurrencyCode_print() { iBuilder.appendCurrencyCode(); - MoneyFormatter test = iBuilder.toFormatter(); + var test = iBuilder.toFormatter(); assertThat(test.print(GBP_2_34)).isEqualTo("GBP"); assertThat(test).hasToString("${code}"); } @@ -92,8 +91,8 @@ void test_appendCurrencyCode_print() { @Test void test_appendCurrencyCode_parse_ok() { iBuilder.appendCurrencyCode(); - MoneyFormatter test = iBuilder.toFormatter(); - MoneyParseContext parsed = test.parse("GBP", 0); + var test = iBuilder.toFormatter(); + var parsed = test.parse("GBP", 0); assertThat(parsed.isError()).isFalse(); assertThat(parsed.getIndex()).isEqualTo(3); assertThat(parsed.getErrorIndex()).isEqualTo(-1); @@ -104,8 +103,8 @@ void test_appendCurrencyCode_parse_ok() { @Test void test_appendCurrencyCode_parse_tooShort() { iBuilder.appendCurrencyCode(); - MoneyFormatter test = iBuilder.toFormatter(); - MoneyParseContext parsed = test.parse("GB", 0); + var test = iBuilder.toFormatter(); + var parsed = test.parse("GB", 0); assertThat(parsed.isError()).isTrue(); assertThat(parsed.getIndex()).isEqualTo(0); assertThat(parsed.getErrorIndex()).isEqualTo(0); @@ -116,8 +115,8 @@ void test_appendCurrencyCode_parse_tooShort() { @Test void test_appendCurrencyCode_parse_empty() { iBuilder.appendCurrencyCode(); - MoneyFormatter test = iBuilder.toFormatter(); - MoneyParseContext parsed = test.parse("", 0); + var test = iBuilder.toFormatter(); + var parsed = test.parse("", 0); assertThat(parsed.isError()).isTrue(); assertThat(parsed.getIndex()).isEqualTo(0); assertThat(parsed.getErrorIndex()).isEqualTo(0); @@ -129,7 +128,7 @@ void test_appendCurrencyCode_parse_empty() { @Test void test_appendCurrencyNumeric3Code_print() { iBuilder.appendCurrencyNumeric3Code(); - MoneyFormatter test = iBuilder.toFormatter(); + var test = iBuilder.toFormatter(); assertThat(test.print(GBP_2_34)).isEqualTo("826"); assertThat(test).hasToString("${numeric3Code}"); } @@ -137,8 +136,8 @@ void test_appendCurrencyNumeric3Code_print() { @Test void test_appendCurrencyNumeric3Code_parse_ok() { iBuilder.appendCurrencyNumeric3Code(); - MoneyFormatter test = iBuilder.toFormatter(); - MoneyParseContext parsed = test.parse("826A", 0); + var test = iBuilder.toFormatter(); + var parsed = test.parse("826A", 0); assertThat(parsed.isError()).isFalse(); assertThat(parsed.getIndex()).isEqualTo(3); assertThat(parsed.getErrorIndex()).isEqualTo(-1); @@ -149,8 +148,8 @@ void test_appendCurrencyNumeric3Code_parse_ok() { @Test void test_appendCurrencyNumeric3Code_parse_tooShort() { iBuilder.appendCurrencyNumeric3Code(); - MoneyFormatter test = iBuilder.toFormatter(); - MoneyParseContext parsed = test.parse("82", 0); + var test = iBuilder.toFormatter(); + var parsed = test.parse("82", 0); assertThat(parsed.isError()).isTrue(); assertThat(parsed.getIndex()).isEqualTo(0); assertThat(parsed.getErrorIndex()).isEqualTo(0); @@ -161,8 +160,8 @@ void test_appendCurrencyNumeric3Code_parse_tooShort() { @Test void test_appendCurrencyNumeric3Code_parse_badCurrency() { iBuilder.appendCurrencyNumeric3Code(); - MoneyFormatter test = iBuilder.toFormatter(); - MoneyParseContext parsed = test.parse("991A", 0); + var test = iBuilder.toFormatter(); + var parsed = test.parse("991A", 0); assertThat(parsed.isError()).isTrue(); assertThat(parsed.getIndex()).isEqualTo(0); assertThat(parsed.getErrorIndex()).isEqualTo(0); @@ -173,8 +172,8 @@ void test_appendCurrencyNumeric3Code_parse_badCurrency() { @Test void test_appendCurrencyNumeric3Code_parse_empty() { iBuilder.appendCurrencyNumeric3Code(); - MoneyFormatter test = iBuilder.toFormatter(); - MoneyParseContext parsed = test.parse("", 0); + var test = iBuilder.toFormatter(); + var parsed = test.parse("", 0); assertThat(parsed.isError()).isTrue(); assertThat(parsed.getIndex()).isEqualTo(0); assertThat(parsed.getErrorIndex()).isEqualTo(0); @@ -186,7 +185,7 @@ void test_appendCurrencyNumeric3Code_parse_empty() { @Test void test_appendCurrencyNumericCode_print() { iBuilder.appendCurrencyNumericCode(); - MoneyFormatter test = iBuilder.toFormatter(); + var test = iBuilder.toFormatter(); assertThat(test.print(GBP_2_34)).isEqualTo("826"); assertThat(test).hasToString("${numericCode}"); } @@ -194,8 +193,8 @@ void test_appendCurrencyNumericCode_print() { @Test void test_appendCurrencyNumericCode_parse_ok() { iBuilder.appendCurrencyNumericCode(); - MoneyFormatter test = iBuilder.toFormatter(); - MoneyParseContext parsed = test.parse("826A", 0); + var test = iBuilder.toFormatter(); + var parsed = test.parse("826A", 0); assertThat(parsed.isError()).isFalse(); assertThat(parsed.getIndex()).isEqualTo(3); assertThat(parsed.getErrorIndex()).isEqualTo(-1); @@ -206,8 +205,8 @@ void test_appendCurrencyNumericCode_parse_ok() { @Test void test_appendCurrencyNumericCode_parse_ok_padded() { iBuilder.appendCurrencyNumericCode(); - MoneyFormatter test = iBuilder.toFormatter(); - MoneyParseContext parsed = test.parse("008A", 0); + var test = iBuilder.toFormatter(); + var parsed = test.parse("008A", 0); assertThat(parsed.isError()).isFalse(); assertThat(parsed.getIndex()).isEqualTo(3); assertThat(parsed.getErrorIndex()).isEqualTo(-1); @@ -218,8 +217,8 @@ void test_appendCurrencyNumericCode_parse_ok_padded() { @Test void test_appendCurrencyNumericCode_parse_ok_notPadded1() { iBuilder.appendCurrencyNumericCode(); - MoneyFormatter test = iBuilder.toFormatter(); - MoneyParseContext parsed = test.parse("8A", 0); + var test = iBuilder.toFormatter(); + var parsed = test.parse("8A", 0); assertThat(parsed.isError()).isFalse(); assertThat(parsed.getIndex()).isEqualTo(1); assertThat(parsed.getErrorIndex()).isEqualTo(-1); @@ -230,8 +229,8 @@ void test_appendCurrencyNumericCode_parse_ok_notPadded1() { @Test void test_appendCurrencyNumericCode_parse_ok_notPadded2() { iBuilder.appendCurrencyNumericCode(); - MoneyFormatter test = iBuilder.toFormatter(); - MoneyParseContext parsed = test.parse("51 ", 0); + var test = iBuilder.toFormatter(); + var parsed = test.parse("51 ", 0); assertThat(parsed.isError()).isFalse(); assertThat(parsed.getIndex()).isEqualTo(2); assertThat(parsed.getErrorIndex()).isEqualTo(-1); @@ -242,8 +241,8 @@ void test_appendCurrencyNumericCode_parse_ok_notPadded2() { @Test void test_appendCurrencyNumericCode_parse_tooShort() { iBuilder.appendCurrencyNumericCode(); - MoneyFormatter test = iBuilder.toFormatter(); - MoneyParseContext parsed = test.parse("", 0); + var test = iBuilder.toFormatter(); + var parsed = test.parse("", 0); assertThat(parsed.isError()).isTrue(); assertThat(parsed.getIndex()).isEqualTo(0); assertThat(parsed.getErrorIndex()).isEqualTo(0); @@ -254,8 +253,8 @@ void test_appendCurrencyNumericCode_parse_tooShort() { @Test void test_appendCurrencyNumericCode_parse_badCurrency() { iBuilder.appendCurrencyNumericCode(); - MoneyFormatter test = iBuilder.toFormatter(); - MoneyParseContext parsed = test.parse("991A", 0); + var test = iBuilder.toFormatter(); + var parsed = test.parse("991A", 0); assertThat(parsed.isError()).isTrue(); assertThat(parsed.getIndex()).isEqualTo(0); assertThat(parsed.getErrorIndex()).isEqualTo(0); @@ -266,8 +265,8 @@ void test_appendCurrencyNumericCode_parse_badCurrency() { @Test void test_appendCurrencyNumericCode_parse_empty() { iBuilder.appendCurrencyNumericCode(); - MoneyFormatter test = iBuilder.toFormatter(); - MoneyParseContext parsed = test.parse("", 0); + var test = iBuilder.toFormatter(); + var parsed = test.parse("", 0); assertThat(parsed.isError()).isTrue(); assertThat(parsed.getIndex()).isEqualTo(0); assertThat(parsed.getErrorIndex()).isEqualTo(0); @@ -279,7 +278,7 @@ void test_appendCurrencyNumericCode_parse_empty() { @Test void test_appendCurrencySymbolLocalized_print() { iBuilder.appendCurrencySymbolLocalized(); - MoneyFormatter test = iBuilder.toFormatter(); + var test = iBuilder.toFormatter(); assertThat(test.print(GBP_2_34)).isEqualTo("\u00a3"); assertThat(test).hasToString("${symbolLocalized}"); } @@ -287,7 +286,7 @@ void test_appendCurrencySymbolLocalized_print() { @Test void test_appendCurrencySymbolLocalized_parse() { iBuilder.appendCurrencySymbolLocalized(); - MoneyFormatter test = iBuilder.toFormatter(); + var test = iBuilder.toFormatter(); assertThat(test.isParser()).isFalse(); } @@ -295,7 +294,7 @@ void test_appendCurrencySymbolLocalized_parse() { @Test void test_appendLiteral_print() { iBuilder.appendLiteral("Hello"); - MoneyFormatter test = iBuilder.toFormatter(); + var test = iBuilder.toFormatter(); assertThat(test.print(GBP_2_34)).isEqualTo("Hello"); assertThat(test).hasToString("'Hello'"); } @@ -303,7 +302,7 @@ void test_appendLiteral_print() { @Test void test_appendLiteral_print_empty() { iBuilder.appendLiteral(""); - MoneyFormatter test = iBuilder.toFormatter(); + var test = iBuilder.toFormatter(); assertThat(test.print(GBP_2_34)).isEmpty(); assertThat(test).hasToString(""); } @@ -311,7 +310,7 @@ void test_appendLiteral_print_empty() { @Test void test_appendLiteral_print_null() { iBuilder.appendLiteral((CharSequence) null); - MoneyFormatter test = iBuilder.toFormatter(); + var test = iBuilder.toFormatter(); assertThat(test.print(GBP_2_34)).isEmpty(); assertThat(test).hasToString(""); } @@ -319,8 +318,8 @@ void test_appendLiteral_print_null() { @Test void test_appendLiteral_parse_ok() { iBuilder.appendLiteral("Hello"); - MoneyFormatter test = iBuilder.toFormatter(); - MoneyParseContext parsed = test.parse("HelloWorld", 0); + var test = iBuilder.toFormatter(); + var parsed = test.parse("HelloWorld", 0); assertThat(parsed.isError()).isFalse(); assertThat(parsed.getIndex()).isEqualTo(5); assertThat(parsed.getErrorIndex()).isEqualTo(-1); @@ -331,8 +330,8 @@ void test_appendLiteral_parse_ok() { @Test void test_appendLiteral_parse_tooShort() { iBuilder.appendLiteral("Hello"); - MoneyFormatter test = iBuilder.toFormatter(); - MoneyParseContext parsed = test.parse("Hell", 0); + var test = iBuilder.toFormatter(); + var parsed = test.parse("Hell", 0); assertThat(parsed.isError()).isTrue(); assertThat(parsed.getIndex()).isEqualTo(0); assertThat(parsed.getErrorIndex()).isEqualTo(0); @@ -343,8 +342,8 @@ void test_appendLiteral_parse_tooShort() { @Test void test_appendLiteral_parse_noMatch() { iBuilder.appendLiteral("Hello"); - MoneyFormatter test = iBuilder.toFormatter(); - MoneyParseContext parsed = test.parse("Helol", 0); + var test = iBuilder.toFormatter(); + var parsed = test.parse("Helol", 0); assertThat(parsed.isError()).isTrue(); assertThat(parsed.getIndex()).isEqualTo(0); assertThat(parsed.getErrorIndex()).isEqualTo(0); @@ -370,7 +369,7 @@ public static Object[][] data_appendAmount() { @MethodSource("data_appendAmount") void test_appendAmount(BigMoneyProvider money, String expected) { iBuilder.appendAmount(); - MoneyFormatter test = iBuilder.toFormatter(); + var test = iBuilder.toFormatter(); assertThat(test.print(money)).isEqualTo(expected); assertThat(test).hasToString("${amount}"); } @@ -378,7 +377,7 @@ void test_appendAmount(BigMoneyProvider money, String expected) { @Test void test_appendAmount_GBP_1234_56789_France() { iBuilder.appendAmount(); - MoneyFormatter test = iBuilder.toFormatter(Locale.FRANCE); + var test = iBuilder.toFormatter(Locale.FRANCE); assertThat(test.print(GBP_1234_56789)).isEqualTo("1,234.567,89"); assertThat(test).hasToString("${amount}"); } @@ -386,7 +385,7 @@ void test_appendAmount_GBP_1234_56789_France() { @Test void test_appendAmount_JPY_2345() { iBuilder.appendAmount(); - MoneyFormatter test = iBuilder.toFormatter(); + var test = iBuilder.toFormatter(); assertThat(test.print(JPY_2345)).isEqualTo("2,345"); assertThat(test).hasToString("${amount}"); } @@ -394,8 +393,8 @@ void test_appendAmount_JPY_2345() { @Test void test_appendAmount_3dp_BHD() { iBuilder.appendAmount(); - MoneyFormatter test = iBuilder.toFormatter(); - Money money = Money.of(CurrencyUnit.of("BHD"), 6345345.735d); + var test = iBuilder.toFormatter(); + var money = Money.of(CurrencyUnit.of("BHD"), 6345345.735d); assertThat(test.print(money)).isEqualTo("6,345,345.735"); } @@ -416,7 +415,7 @@ public static Object[][] data_appendAmountLocalized() { @MethodSource("data_appendAmountLocalized") void test_appendAmountLocalized(BigMoneyProvider money, String expected) { iBuilder.appendAmountLocalized(); - MoneyFormatter test = iBuilder.toFormatter(Locale.FRANCE); + var test = iBuilder.toFormatter(Locale.FRANCE); assertThat(test.print(money)).isEqualTo(expected); assertThat(test).hasToString("${amount}"); } @@ -424,7 +423,7 @@ void test_appendAmountLocalized(BigMoneyProvider money, String expected) { @Test void test_appendAmountLocalized_GBP_1234_56789_US() { iBuilder.appendAmountLocalized(); - MoneyFormatter test = iBuilder.toFormatter(Locale.US); + var test = iBuilder.toFormatter(Locale.US); assertThat(test.print(GBP_1234_56789)).isEqualTo("1,234.567,89"); assertThat(test).hasToString("${amount}"); } @@ -432,7 +431,7 @@ void test_appendAmountLocalized_GBP_1234_56789_US() { @Test void test_appendAmountLocalized_JPY_2345() { iBuilder.appendAmountLocalized(); - MoneyFormatter test = iBuilder.toFormatter(Locale.FRANCE); + var test = iBuilder.toFormatter(Locale.FRANCE); assertThat(test.print(JPY_2345)).isEqualTo("2" + FR_GROUP + "345"); assertThat(test).hasToString("${amount}"); } @@ -445,18 +444,18 @@ void test_appendAmount_MoneyAmountStyle_null() { } public static Object[][] data_appendAmount_MoneyAmountStyle() { - MoneyAmountStyle noGrouping = MoneyAmountStyle.ASCII_DECIMAL_POINT_NO_GROUPING; - MoneyAmountStyle group3Comma = MoneyAmountStyle.ASCII_DECIMAL_POINT_GROUP3_COMMA; - MoneyAmountStyle group3Space = MoneyAmountStyle.ASCII_DECIMAL_POINT_GROUP3_SPACE; - MoneyAmountStyle group3BeforeDp = + var noGrouping = MoneyAmountStyle.ASCII_DECIMAL_POINT_NO_GROUPING; + var group3Comma = MoneyAmountStyle.ASCII_DECIMAL_POINT_GROUP3_COMMA; + var group3Space = MoneyAmountStyle.ASCII_DECIMAL_POINT_GROUP3_SPACE; + var group3BeforeDp = MoneyAmountStyle.ASCII_DECIMAL_POINT_GROUP3_COMMA.withGroupingStyle(GroupingStyle.BEFORE_DECIMAL_POINT); - MoneyAmountStyle group3CommaForceDp = MoneyAmountStyle.ASCII_DECIMAL_POINT_GROUP3_COMMA.withForcedDecimalPoint(true); - MoneyAmountStyle group3CommaAbs = MoneyAmountStyle.ASCII_DECIMAL_POINT_GROUP3_COMMA.withAbsValue(true); - MoneyAmountStyle group1Dash = MoneyAmountStyle.ASCII_DECIMAL_POINT_GROUP3_COMMA.withGroupingSize(1).withGroupingCharacter('-'); - MoneyAmountStyle group2Dash = MoneyAmountStyle.ASCII_DECIMAL_POINT_GROUP3_COMMA.withGroupingSize(2).withGroupingCharacter('-'); - MoneyAmountStyle group4CommaAt = MoneyAmountStyle.ASCII_DECIMAL_POINT_GROUP3_COMMA + var group3CommaForceDp = MoneyAmountStyle.ASCII_DECIMAL_POINT_GROUP3_COMMA.withForcedDecimalPoint(true); + var group3CommaAbs = MoneyAmountStyle.ASCII_DECIMAL_POINT_GROUP3_COMMA.withAbsValue(true); + var group1Dash = MoneyAmountStyle.ASCII_DECIMAL_POINT_GROUP3_COMMA.withGroupingSize(1).withGroupingCharacter('-'); + var group2Dash = MoneyAmountStyle.ASCII_DECIMAL_POINT_GROUP3_COMMA.withGroupingSize(2).withGroupingCharacter('-'); + var group4CommaAt = MoneyAmountStyle.ASCII_DECIMAL_POINT_GROUP3_COMMA .withGroupingSize(4).withDecimalPointCharacter('@').withForcedDecimalPoint(true); - MoneyAmountStyle letters = MoneyAmountStyle.ASCII_DECIMAL_POINT_GROUP3_COMMA.withZeroCharacter('A'); + var letters = MoneyAmountStyle.ASCII_DECIMAL_POINT_GROUP3_COMMA.withZeroCharacter('A'); return new Object[][] { {noGrouping, "2", "2"}, {noGrouping, "2123456", "2123456"}, @@ -620,8 +619,8 @@ void test_appendAmount_MoneyAmountStyle_GBP( String expected) { iBuilder.appendAmount(style); - MoneyFormatter test = iBuilder.toFormatter(); - BigMoney money = BigMoney.of(GBP, new BigDecimal(amount)); + var test = iBuilder.toFormatter(); + var money = BigMoney.of(GBP, new BigDecimal(amount)); assertThat(test.print(money)).isEqualTo(expected); if (!style.isAbsValue()) { assertThat(test.parse(expected, 0).getAmount()).isEqualTo(money.getAmount()); @@ -638,8 +637,8 @@ void test_appendAmount_MoneyAmountStyle_JPY( String expected) { iBuilder.appendAmount(style); - MoneyFormatter test = iBuilder.toFormatter(); - BigMoney money = BigMoney.of(JPY, new BigDecimal(amount)); + var test = iBuilder.toFormatter(); + var money = BigMoney.of(JPY, new BigDecimal(amount)); assertThat(test.print(money)).isEqualTo(expected); if (!style.isAbsValue()) { assertThat(test.parse(expected, 0).getAmount()).isEqualTo(money.getAmount()); @@ -656,8 +655,8 @@ void test_appendAmount_MoneyAmountStyle_BHD( String expected) { iBuilder.appendAmount(style); - MoneyFormatter test = iBuilder.toFormatter(); - BigMoney money = BigMoney.of(BHD, new BigDecimal(amount)); + var test = iBuilder.toFormatter(); + var money = BigMoney.of(BHD, new BigDecimal(amount)); assertThat(test.print(money)).isEqualTo(expected); if (!style.isAbsValue()) { assertThat(test.parse(expected, 0).getAmount()).isEqualTo(money.getAmount()); @@ -668,9 +667,9 @@ void test_appendAmount_MoneyAmountStyle_BHD( @Test void test_appendAmount_MoneyAmountStyle_JPY_issue49() { - Money money = Money.parse("JPY 12"); - MoneyAmountStyle style = MoneyAmountStyle.LOCALIZED_GROUPING; - MoneyFormatter formatter = new MoneyFormatterBuilder() + var money = Money.parse("JPY 12"); + var style = MoneyAmountStyle.LOCALIZED_GROUPING; + var formatter = new MoneyFormatterBuilder() .appendAmount(style) .toFormatter() .withLocale(Locale.JAPAN); @@ -695,7 +694,7 @@ public static Object[][] data_appendAmountExtendedGrouping() { @MethodSource("data_appendAmountExtendedGrouping") void test_appendAmount_parseExtendedGroupingSize(BigMoneyProvider money, String expected) { iBuilder.appendAmount(); - MoneyFormatter test = new MoneyFormatterBuilder() + var test = new MoneyFormatterBuilder() .appendAmount(MoneyAmountStyle.ASCII_DECIMAL_POINT_GROUP3_COMMA.withExtendedGroupingSize(2)) .toFormatter(); assertThat(test.print(money)).isEqualTo(expected); @@ -705,28 +704,22 @@ void test_appendAmount_parseExtendedGroupingSize(BigMoneyProvider money, String //----------------------------------------------------------------------- @Test void test_appendAmount_parseExcessGrouping() { - BigMoney expected = BigMoney.parse("GBP 12123.4567"); - MoneyFormatter f = new MoneyFormatterBuilder() + var expected = BigMoney.parse("GBP 12123.4567"); + var f = new MoneyFormatterBuilder() .appendCurrencyCode() .appendLiteral(" ") .appendAmount(MoneyAmountStyle.ASCII_DECIMAL_POINT_GROUP3_COMMA) .toFormatter(); - BigMoney money = f.parseBigMoney("GBP 12,1,2,3,.,45,6,7"); + var money = f.parseBigMoney("GBP 12,1,2,3,.,45,6,7"); assertThat(money).isEqualTo(expected); } //----------------------------------------------------------------------- @Test void test_append_MoneyPrinterMoneyParser_printer() { - MoneyPrinter printer = new MoneyPrinter() { - @Override - @Test - public void print(MoneyPrintContext context, Appendable appendable, BigMoney money) throws IOException { - appendable.append("HELLO"); - } - }; + MoneyPrinter printer = (context, appendable, money) -> appendable.append("HELLO"); iBuilder.append(printer, null); - MoneyFormatter test = iBuilder.toFormatter(); + var test = iBuilder.toFormatter(); assertThat(test.isPrinter()).isTrue(); assertThat(test.isParser()).isFalse(); assertThat(test.print(JPY_2345)).isEqualTo("HELLO"); @@ -735,16 +728,12 @@ public void print(MoneyPrintContext context, Appendable appendable, BigMoney mon @Test void test_append_MoneyPrinterMoneyParser_parser() { - MoneyParser parser = new MoneyParser() { - @Override - @Test - public void parse(MoneyParseContext context) { - context.setAmount(JPY_2345.getAmount()); - context.setCurrency(JPY_2345.getCurrencyUnit()); - } + MoneyParser parser = (context) -> { + context.setAmount(JPY_2345.getAmount()); + context.setCurrency(JPY_2345.getCurrencyUnit()); }; iBuilder.append(null, parser); - MoneyFormatter test = iBuilder.toFormatter(); + var test = iBuilder.toFormatter(); assertThat(test.isPrinter()).isFalse(); assertThat(test.isParser()).isTrue(); assertThat(test.parseMoney("")).isEqualTo(JPY_2345); @@ -754,7 +743,7 @@ public void parse(MoneyParseContext context) { @Test void test_append_MoneyPrinter_nullMoneyPrinter_nullMoneyParser() { iBuilder.append((MoneyPrinter) null, (MoneyParser) null); - MoneyFormatter test = iBuilder.toFormatter(); + var test = iBuilder.toFormatter(); assertThat(test.isPrinter()).isFalse(); assertThat(test.isParser()).isFalse(); assertThat(test).hasToString(""); @@ -763,27 +752,27 @@ void test_append_MoneyPrinter_nullMoneyPrinter_nullMoneyParser() { //----------------------------------------------------------------------- @Test void test_append_MoneyFormatter() { - MoneyFormatter f1 = new MoneyFormatterBuilder().appendAmount().toFormatter(); - MoneyFormatter f2 = new MoneyFormatterBuilder().appendCurrencyCode().appendLiteral(" ").append(f1).toFormatter(); + var f1 = new MoneyFormatterBuilder().appendAmount().toFormatter(); + var f2 = new MoneyFormatterBuilder().appendCurrencyCode().appendLiteral(" ").append(f1).toFormatter(); assertThat(f2.print(GBP_2345_67)).isEqualTo("GBP 2,345.67"); } //----------------------------------------------------------------------- @Test void test_appendSigned_PN() { - MoneyFormatter pos = new MoneyFormatterBuilder() + var pos = new MoneyFormatterBuilder() .appendCurrencyCode() .appendLiteral(" ") .appendAmount() .toFormatter(); - MoneyFormatter neg = new MoneyFormatterBuilder() + var neg = new MoneyFormatterBuilder() .appendLiteral("(") .appendCurrencyCode() .appendLiteral(" ") .appendAmount(MoneyAmountStyle.ASCII_DECIMAL_POINT_GROUP3_COMMA.withAbsValue(true)) .appendLiteral(")") .toFormatter(); - MoneyFormatter f = new MoneyFormatterBuilder().appendSigned(pos, neg).toFormatter(); + var f = new MoneyFormatterBuilder().appendSigned(pos, neg).toFormatter(); assertThat(f) .hasToString("PositiveZeroNegative(${code}' '${amount},${code}' '${amount},'('${code}' '${amount}')')"); assertThat(f.print(GBP_234_56)).isEqualTo("GBP 234.56"); @@ -792,7 +781,7 @@ void test_appendSigned_PN() { 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); + var context = f.parse("X", 0); assertThat(context.getIndex()).isEqualTo(0); assertThat(context.getErrorIndex()).isEqualTo(0); } @@ -800,23 +789,23 @@ void test_appendSigned_PN() { //----------------------------------------------------------------------- @Test void test_appendSigned_PZN() { - MoneyFormatter pos = new MoneyFormatterBuilder() + var pos = new MoneyFormatterBuilder() .appendCurrencyCode() .appendLiteral(" ") .appendAmount() .toFormatter(); - MoneyFormatter zro = new MoneyFormatterBuilder() + var zro = new MoneyFormatterBuilder() .appendCurrencyCode() .appendLiteral(" -") .toFormatter(); - MoneyFormatter neg = new MoneyFormatterBuilder() + var neg = new MoneyFormatterBuilder() .appendLiteral("(") .appendCurrencyCode() .appendLiteral(" ") .appendAmount(MoneyAmountStyle.ASCII_DECIMAL_POINT_GROUP3_COMMA.withAbsValue(true)) .appendLiteral(")") .toFormatter(); - MoneyFormatter f = new MoneyFormatterBuilder().appendSigned(pos, zro, neg).toFormatter(); + var f = new MoneyFormatterBuilder().appendSigned(pos, zro, neg).toFormatter(); 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)"); @@ -829,19 +818,19 @@ void test_appendSigned_PZN() { @Test void test_appendSigned_PZN_edgeCases() { - MoneyFormatter pos = new MoneyFormatterBuilder() + var pos = new MoneyFormatterBuilder() .appendAmount() .toFormatter(); - MoneyFormatter zro = new MoneyFormatterBuilder() + var zro = new MoneyFormatterBuilder() .appendAmount() .appendLiteral(" (zero)") .toFormatter(); - MoneyFormatter neg = new MoneyFormatterBuilder() + var neg = new MoneyFormatterBuilder() .appendLiteral("(") .appendAmount(MoneyAmountStyle.ASCII_DECIMAL_POINT_GROUP3_COMMA.withAbsValue(true)) .appendLiteral(")") .toFormatter(); - MoneyFormatter f = new MoneyFormatterBuilder() + var f = new MoneyFormatterBuilder() .appendCurrencyCode().appendLiteral(" ").appendSigned(pos, zro, neg).toFormatter(); assertThat(f.print(GBP_234_56)).isEqualTo("GBP 234.56"); assertThat(f.print(BigMoney.zero(GBP).withScale(2))).isEqualTo("GBP 0.00 (zero)"); @@ -855,13 +844,13 @@ void test_appendSigned_PZN_edgeCases() { //----------------------------------------------------------------------- @Test void test_toFormatter_defaultLocale() { - MoneyFormatter test = iBuilder.toFormatter(); + var test = iBuilder.toFormatter(); assertThat(test.getLocale()).isEqualTo(TEST_GB_LOCALE); } @Test void test_toFormatter_Locale() { - MoneyFormatter test = iBuilder.toFormatter(TEST_FR_LOCALE); + var test = iBuilder.toFormatter(TEST_FR_LOCALE); 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 58f6992..75fe373 100644 --- a/src/test/java/org/joda/money/format/TestMoneyFormatterException.java +++ b/src/test/java/org/joda/money/format/TestMoneyFormatterException.java @@ -29,14 +29,14 @@ class TestMoneyFormatterException { @Test void test_MoneyFormatException_IOException_notRethrown() { - MoneyFormatException test = new MoneyFormatException("Error", new IOException("Inner")); + var test = new MoneyFormatException("Error", new IOException("Inner")); assertThatExceptionOfType(IOException.class) .isThrownBy(() -> test.rethrowIOException()); } @Test void test_MoneyFormatException_nonIOException_notRethrown() throws IOException { - MoneyFormatException test = new MoneyFormatException("Error", new IllegalStateException("Inner")); + var test = new MoneyFormatException("Error", new IllegalStateException("Inner")); 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 0f2d271..8880ee1 100644 --- a/src/test/java/org/joda/money/format/TestMoneyParseContext.java +++ b/src/test/java/org/joda/money/format/TestMoneyParseContext.java @@ -32,7 +32,7 @@ class TestMoneyParseContext { @Test void test_initialState() { - MoneyParseContext test = new MoneyParseContext(Locale.FRANCE, "GBP 123", 0); + var test = new MoneyParseContext(Locale.FRANCE, "GBP 123", 0); assertThat(test.getAmount()).isNull(); assertThat(test.getCurrency()).isNull(); assertThat(test.getIndex()).isEqualTo(0); @@ -42,14 +42,14 @@ void test_initialState() { assertThat(test.isError()).isFalse(); assertThat(test.isFullyParsed()).isFalse(); assertThat(test.isComplete()).isFalse(); - ParsePosition pp = new ParsePosition(0); + var pp = new ParsePosition(0); pp.setErrorIndex(-1); assertThat(test.toParsePosition()).isEqualTo(pp); } @Test void test_setIndex() { - MoneyParseContext test = new MoneyParseContext(Locale.FRANCE, "GBP 123", 0); + var test = new MoneyParseContext(Locale.FRANCE, "GBP 123", 0); assertThat(test.getIndex()).isEqualTo(0); test.setIndex(2); assertThat(test.getIndex()).isEqualTo(2); @@ -57,7 +57,7 @@ void test_setIndex() { @Test void test_setErrorIndex() { - MoneyParseContext test = new MoneyParseContext(Locale.FRANCE, "GBP 123", 0); + var test = new MoneyParseContext(Locale.FRANCE, "GBP 123", 0); assertThat(test.getErrorIndex()).isEqualTo(-1); test.setErrorIndex(3); assertThat(test.getErrorIndex()).isEqualTo(3); @@ -65,7 +65,7 @@ void test_setErrorIndex() { @Test void test_setError() { - MoneyParseContext test = new MoneyParseContext(Locale.FRANCE, "GBP 123", 0); + var test = new MoneyParseContext(Locale.FRANCE, "GBP 123", 0); assertThat(test.getIndex()).isEqualTo(0); assertThat(test.getErrorIndex()).isEqualTo(-1); test.setError(); @@ -75,7 +75,7 @@ void test_setError() { @Test void test_setError_withIndex() { - MoneyParseContext test = new MoneyParseContext(Locale.FRANCE, "GBP 123", 0); + var test = new MoneyParseContext(Locale.FRANCE, "GBP 123", 0); assertThat(test.getIndex()).isEqualTo(0); assertThat(test.getErrorIndex()).isEqualTo(-1); test.setIndex(2); @@ -87,21 +87,21 @@ void test_setError_withIndex() { //----------------------------------------------------------------------- @Test void test_isComplete_noCurrency() { - MoneyParseContext test = new MoneyParseContext(Locale.FRANCE, "GBP 123", 0); + var test = new MoneyParseContext(Locale.FRANCE, "GBP 123", 0); test.setAmount(BigDecimal.TEN); assertThat(test.isComplete()).isFalse(); } @Test void test_isComplete_noAmount() { - MoneyParseContext test = new MoneyParseContext(Locale.FRANCE, "GBP 123", 0); + var test = new MoneyParseContext(Locale.FRANCE, "GBP 123", 0); test.setCurrency(CurrencyUnit.GBP); assertThat(test.isComplete()).isFalse(); } @Test void test_toBigMoney_noCurrency() { - MoneyParseContext test = new MoneyParseContext(Locale.FRANCE, "GBP 123", 0); + var test = new MoneyParseContext(Locale.FRANCE, "GBP 123", 0); test.setAmount(BigDecimal.TEN); assertThatExceptionOfType(MoneyFormatException.class) .isThrownBy(() -> test.toBigMoney()); @@ -109,7 +109,7 @@ void test_toBigMoney_noCurrency() { @Test void test_toBigMoney_noAmount() { - MoneyParseContext test = new MoneyParseContext(Locale.FRANCE, "GBP 123", 0); + var test = new MoneyParseContext(Locale.FRANCE, "GBP 123", 0); test.setCurrency(CurrencyUnit.GBP); assertThatExceptionOfType(MoneyFormatException.class) .isThrownBy(() -> test.toBigMoney()); @@ -118,21 +118,21 @@ void test_toBigMoney_noAmount() { //----------------------------------------------------------------------- @Test void test_getTextSubstring_ok() { - MoneyParseContext test = new MoneyParseContext(Locale.FRANCE, "GBP 123", 0); + var test = new MoneyParseContext(Locale.FRANCE, "GBP 123", 0); 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); + var test = new MoneyParseContext(Locale.FRANCE, "GBP 123", 0); assertThatExceptionOfType(IndexOutOfBoundsException.class) .isThrownBy(() -> test.getTextSubstring(-1, 2)); } @Test void test_getTextSubstring_afterEnd() { - MoneyParseContext test = new MoneyParseContext(Locale.FRANCE, "GBP 123", 0); + var test = new MoneyParseContext(Locale.FRANCE, "GBP 123", 0); assertThatExceptionOfType(IndexOutOfBoundsException.class) .isThrownBy(() -> test.getTextSubstring(0, 8)); }