RequireFailForTryCatchInJunitCheck extends AbstractCheck { @Override public void visitToken(DetailAST ast) { switch (ast.getType()) { case TokenTypes.IMPORT: final String imprt = getImportText(ast); if (FQ_JUNIT_TESTS.contains(imprt)) { importTest = true; } if ("org.junit.Assert".equals(imprt)) { importJunit4Assert = true; } if ("org.junit.jupiter.api.Assertions".equals(imprt)) { importJunit5Assertions = true; } break; case TokenTypes.STATIC_IMPORT: final String staticImprt = getImportText(ast); if (JUNIT_FAIL_STATIC_IMPORTS.contains(staticImprt)) { importStaticFail = true; } break; case TokenTypes.LITERAL_TRY: examineTry(ast); break; default: SevntuUtil.reportInvalidToken(ast.getType()); break; } }  @Override int[] getDefaultTokens(); @Override int[] getAcceptableTokens(); @Override int[] getRequiredTokens(); @Override void beginTree(DetailAST rootAST); @Override void visitToken(DetailAST ast); static final String MSG_KEY; }
@Test public void testUnsupportedNode() { final DetailAstImpl sync = new DetailAstImpl(); sync.setType(TokenTypes.LITERAL_SYNCHRONIZED); try { final RequireFailForTryCatchInJunitCheck check = new RequireFailForTryCatchInJunitCheck(); check.visitToken(sync); fail("exception expected"); } catch (IllegalArgumentException ex) { Assert.assertEquals("Found unsupported token: LITERAL_SYNCHRONIZED", ex.getMessage()); } }