@Test public void shouldReturnMajorPartPositive() { MonetaryAmount monetaryAmount = Money.parse("EUR 2.35"); Long result = query.queryFrom(monetaryAmount); Long expected = 35L; assertEquals(result, expected); }
@Override public Long queryFrom(MonetaryAmount amount) { Objects.requireNonNull(amount, "Amount required."); int fractionDigits = amount.getCurrency().getDefaultFractionDigits(); BigDecimal number = amount.getNumber().numberValue(BigDecimal.class); return number.setScale(fractionDigits, RoundingMode.DOWN) .remainder(BigDecimal.ONE) .movePointRight(fractionDigits).longValue(); }
ExtractorMinorPartQuery implements MonetaryQuery<Long> { @Override public Long queryFrom(MonetaryAmount amount) { Objects.requireNonNull(amount, "Amount required."); int fractionDigits = amount.getCurrency().getDefaultFractionDigits(); BigDecimal number = amount.getNumber().numberValue(BigDecimal.class); return number.setScale(fractionDigits, RoundingMode.DOWN) .remainder(BigDecimal.ONE) .movePointRight(fractionDigits).longValue(); } }
ExtractorMinorPartQuery implements MonetaryQuery<Long> { @Override public Long queryFrom(MonetaryAmount amount) { Objects.requireNonNull(amount, "Amount required."); int fractionDigits = amount.getCurrency().getDefaultFractionDigits(); BigDecimal number = amount.getNumber().numberValue(BigDecimal.class); return number.setScale(fractionDigits, RoundingMode.DOWN) .remainder(BigDecimal.ONE) .movePointRight(fractionDigits).longValue(); } ExtractorMinorPartQuery(); }
ExtractorMinorPartQuery implements MonetaryQuery<Long> { @Override public Long queryFrom(MonetaryAmount amount) { Objects.requireNonNull(amount, "Amount required."); int fractionDigits = amount.getCurrency().getDefaultFractionDigits(); BigDecimal number = amount.getNumber().numberValue(BigDecimal.class); return number.setScale(fractionDigits, RoundingMode.DOWN) .remainder(BigDecimal.ONE) .movePointRight(fractionDigits).longValue(); } ExtractorMinorPartQuery(); @Override Long queryFrom(MonetaryAmount amount); }
ExtractorMinorPartQuery implements MonetaryQuery<Long> { @Override public Long queryFrom(MonetaryAmount amount) { Objects.requireNonNull(amount, "Amount required."); int fractionDigits = amount.getCurrency().getDefaultFractionDigits(); BigDecimal number = amount.getNumber().numberValue(BigDecimal.class); return number.setScale(fractionDigits, RoundingMode.DOWN) .remainder(BigDecimal.ONE) .movePointRight(fractionDigits).longValue(); } ExtractorMinorPartQuery(); @Override Long queryFrom(MonetaryAmount amount);  }