### Question:
CobolErrorStrategy extends DefaultErrorStrategy { @Override public void reportError(Parser recognizer, RecognitionException e) { if (inErrorRecoveryMode(recognizer)) { return; } beginErrorCondition(recognizer); if (e instanceof NoViableAltException) { reportNoViableAlternative(recognizer, (NoViableAltException) e); } else if (e instanceof InputMismatchException) { reportInputMismatch(recognizer, (InputMismatchException) e); } else if (e instanceof FailedPredicateException) { reportFailedPredicate(recognizer, (FailedPredicateException) e); } else { LOG.error("unknown recognition error type: " + e.getClass().getName()); recognizer.notifyErrorListeners(e.getOffendingToken(), e.getMessage(), e); } }  @Override void reportError(Parser recognizer, RecognitionException e);  }### Answer:
@Test void noViableAltExceptionTest() { Parser recognizer = mock(Parser.class); TokenStream stream = mock(TokenStream.class); Token token = mock(Token.class); NoViableAltException error = new NoViableAltException(recognizer, stream, token, token, null, null); CobolErrorStrategy strategy = new CobolErrorStrategy(); when(recognizer.getInputStream()).thenReturn(stream); when(stream.getText(token, token)).thenReturn("text"); when(recognizer.getRuleInvocationStack()).thenReturn(Collections.singletonList("rule")); strategy.reportError(recognizer, error); verify(recognizer).notifyErrorListeners(token, "No viable alternative at input text", error); }
@Test void failedPredicateExceptionTest() throws NullPointerException { Assertions.assertThrows( NullPointerException.class, () -> { Parser recognizer = mock(Parser.class); FailedPredicateException errorMock = mock(FailedPredicateException.class); CobolErrorStrategy strategy = new CobolErrorStrategy(); strategy.reportError(recognizer, errorMock); }); }
@Test void unknownErrorTest() { Parser recognizer = mock(Parser.class); Token token = mock(Token.class); RecognitionException errorMock = mock(RecognitionException.class); CobolErrorStrategy strategy = new CobolErrorStrategy(); strategy.reportError(recognizer, errorMock); verify(recognizer).notifyErrorListeners(null, null, errorMock); }