@Test @Ignore("The current JDK parses a number of '12-54.234' to 12 without error!") public void testParse_mismatchingPattern_throws_exception() { AmountNumberToken token = new AmountNumberToken(contextForLocale(US, null), PATTERN); ParseContext context = new ParseContext("12-54.234"); try { token.parse(context); fail(); } catch (MonetaryParseException e) { assertEquals(e.getInput(), "12354:234"); assertEquals(e.getErrorIndex(), 0); assertEquals(e.getMessage(), "Unparseable amount: \"12354ghd.234\""); } assertEquals(context.getIndex(), 0); assertFalse(context.isComplete()); assertTrue(context.hasError()); assertEquals(context.getErrorMessage(), "Unparseable amount: \"12354ghd.234\""); assertNull(context.getParsedNumber()); }
@Override public void parse(ParseContext context) throws MonetaryParseException { context.skipWhitespace(); if (!context.isFullyParsed()) { parseToken(context); if (context.hasError()) { throw new MonetaryParseException(context.getErrorMessage(), context.getInput(), context.getIndex()); } } else { context.setError(); context.setErrorMessage("Number expected."); } }
AmountNumberToken implements FormatToken { @Override public void parse(ParseContext context) throws MonetaryParseException { context.skipWhitespace(); if (!context.isFullyParsed()) { parseToken(context); if (context.hasError()) { throw new MonetaryParseException(context.getErrorMessage(), context.getInput(), context.getIndex()); } } else { context.setError(); context.setErrorMessage("Number expected."); } } }
AmountNumberToken implements FormatToken { @Override public void parse(ParseContext context) throws MonetaryParseException { context.skipWhitespace(); if (!context.isFullyParsed()) { parseToken(context); if (context.hasError()) { throw new MonetaryParseException(context.getErrorMessage(), context.getInput(), context.getIndex()); } } else { context.setError(); context.setErrorMessage("Number expected."); } } AmountNumberToken(AmountFormatContext amountFormatContext, String partialNumberPattern); }
AmountNumberToken implements FormatToken { @Override public void parse(ParseContext context) throws MonetaryParseException { context.skipWhitespace(); if (!context.isFullyParsed()) { parseToken(context); if (context.hasError()) { throw new MonetaryParseException(context.getErrorMessage(), context.getInput(), context.getIndex()); } } else { context.setError(); context.setErrorMessage("Number expected."); } } AmountNumberToken(AmountFormatContext amountFormatContext, String partialNumberPattern); AmountFormatContext getAmountFormatContext(); String getNumberPattern(); @Override void print(Appendable appendable, MonetaryAmount amount); @Override void parse(ParseContext context); @Override String toString(); }
AmountNumberToken implements FormatToken { @Override public void parse(ParseContext context) throws MonetaryParseException { context.skipWhitespace(); if (!context.isFullyParsed()) { parseToken(context); if (context.hasError()) { throw new MonetaryParseException(context.getErrorMessage(), context.getInput(), context.getIndex()); } } else { context.setError(); context.setErrorMessage("Number expected."); } } AmountNumberToken(AmountFormatContext amountFormatContext, String partialNumberPattern); AmountFormatContext getAmountFormatContext(); String getNumberPattern(); @Override void print(Appendable appendable, MonetaryAmount amount); @Override void parse(ParseContext context); @Override String toString();  }