MonetaryFormat: Fix equals() and hashCode().

This commit is contained in:
Matthew Leon 2019-03-25 21:44:26 -04:00 committed by Andreas Schildbach
parent c01450a32c
commit 9dc2abc82e
2 changed files with 16 additions and 2 deletions

View file

@ -489,7 +489,7 @@ public final class MonetaryFormat {
return false;
if (!Objects.equals(this.roundingMode, other.roundingMode))
return false;
if (!Objects.equals(this.codes, other.codes))
if (!Arrays.equals(this.codes, other.codes))
return false;
if (!Objects.equals(this.codeSeparator, other.codeSeparator))
return false;
@ -501,6 +501,6 @@ public final class MonetaryFormat {
@Override
public int hashCode() {
return Objects.hash(negativeSign, positiveSign, zeroDigit, decimalMark, minDecimals, decimalGroups, shift,
roundingMode, codes, codeSeparator, codePrefixed);
roundingMode, Arrays.hashCode(codes), codeSeparator, codePrefixed);
}
}

View file

@ -352,4 +352,18 @@ public class MonetaryFormatTest {
public void fiat() throws Exception {
assertEquals(ONE_EURO, NO_CODE.parseFiat("EUR", "1"));
}
@Test
public void testEquals() {
MonetaryFormat mf1 = new MonetaryFormat(true);
MonetaryFormat mf2 = new MonetaryFormat(true);
assertEquals(mf1, mf2);
}
@Test
public void testHashCode() {
MonetaryFormat mf1 = new MonetaryFormat(true);
MonetaryFormat mf2 = new MonetaryFormat(true);
assertEquals(mf1.hashCode(), mf2.hashCode());
}
}