LongLiteralEvaluator implements NumberEvaluator<StellarParser.LongLiteralContext> { @Override public Token<Long> evaluate(StellarParser.LongLiteralContext context, FrameContext.Context contextVariety) { if (context == null) { throw new IllegalArgumentException("Cannot evaluate a context that is null."); } String value = context.getText(); if (value.endsWith("l") || value.endsWith("L")) { value = value.substring(0, value.length() - 1); return new Token<>(Long.parseLong(value), Long.class, contextVariety); } else { throw new ParseException("Invalid format for long. Failed trying to parse a long with the following value: " + value); } }  @Override Token<Long> evaluate(StellarParser.LongLiteralContext context, FrameContext.Context contextVariety);  }
@Test public void verifyHappyPathEvaluation() { when(context.getText()).thenReturn("100L"); Token<? extends Number> evaluated = evaluator.evaluate(context, null); assertEquals(new Token<>(100L, Long.class, null), evaluated); verify(context).getText(); verifyNoMoreInteractions(context); }
@Test public void verifyNumberFormationExceptionWithEmptyString() { when(context.getText()).thenReturn(""); Exception e = assertThrows(ParseException.class, () -> evaluator.evaluate(context, null)); assertEquals( "Invalid format for long. Failed trying to parse a long with the following value: ", e.getMessage()); }
@Test public void throwIllegalArgumentExceptionWhenContextIsNull() { Exception e = assertThrows(IllegalArgumentException.class, () -> evaluator.evaluate(null, null)); assertEquals("Cannot evaluate a context that is null.", e.getMessage()); }