@Test public void testParse_throws_exception() { LiteralToken token = new LiteralToken(" some text "); ParseContext context = new ParseContext("here is some text here"); try { token.parse(context); } catch (MonetaryParseException e) { assertEquals(e.getInput(), "here is some text here"); assertEquals(e.getErrorIndex(), 0); assertEquals(e.getMessage(), "Parse Error"); } assertEquals(context.getIndex(), 0); assertFalse(context.isComplete()); assertTrue(context.hasError()); assertEquals(context.getErrorMessage(), "Parse Error"); }
@Override public void parse(ParseContext context) throws MonetaryParseException { if (!context.consume(token)) { if(token.trim().isEmpty()){ return; } context.setError(); context.setErrorMessage("Parse Error"); throw new MonetaryParseException(context.getOriginalInput(), context.getErrorIndex()); } }
LiteralToken implements FormatToken, Serializable { @Override public void parse(ParseContext context) throws MonetaryParseException { if (!context.consume(token)) { if(token.trim().isEmpty()){ return; } context.setError(); context.setErrorMessage("Parse Error"); throw new MonetaryParseException(context.getOriginalInput(), context.getErrorIndex()); } } }
LiteralToken implements FormatToken, Serializable { @Override public void parse(ParseContext context) throws MonetaryParseException { if (!context.consume(token)) { if(token.trim().isEmpty()){ return; } context.setError(); context.setErrorMessage("Parse Error"); throw new MonetaryParseException(context.getOriginalInput(), context.getErrorIndex()); } } LiteralToken(String token); }
LiteralToken implements FormatToken, Serializable { @Override public void parse(ParseContext context) throws MonetaryParseException { if (!context.consume(token)) { if(token.trim().isEmpty()){ return; } context.setError(); context.setErrorMessage("Parse Error"); throw new MonetaryParseException(context.getOriginalInput(), context.getErrorIndex()); } } LiteralToken(String token); @Override void parse(ParseContext context); @Override void print(Appendable appendable, MonetaryAmount amount); @Override String toString(); }
LiteralToken implements FormatToken, Serializable { @Override public void parse(ParseContext context) throws MonetaryParseException { if (!context.consume(token)) { if(token.trim().isEmpty()){ return; } context.setError(); context.setErrorMessage("Parse Error"); throw new MonetaryParseException(context.getOriginalInput(), context.getErrorIndex()); } } LiteralToken(String token); @Override void parse(ParseContext context); @Override void print(Appendable appendable, MonetaryAmount amount); @Override String toString();  }