Consequence { public static boolean containsWord(String word, String body) { final String wordWithDollarReplaced = word.replace("$", "犬"); final String bodyWithDollarReplaced = body.replace("$", "犬"); Pattern p = Pattern.compile("\\b" + wordWithDollarReplaced + "\\b"); Matcher m = p.matcher(bodyWithDollarReplaced); return m.find(); } Consequence(RuleContext context); MethodCallExpr createCall(RuleDescr ruleDescr, String consequenceString, BlockStmt ruleVariablesBlock, boolean isBreaking); static boolean containsWord(String word, String body); static final Set<String> knowledgeHelperMethods; static final Set<String> implicitDroolsMethods; }
@Test public void containsWordTest() throws Exception { assertFalse(containsWord("$cheesery", "results.add($cheeseryResult);\n")); assertTrue(containsWord("$cheeseryResult", "results.add($cheeseryResult);\n")); assertFalse(containsWord("cheesery", "results.add($cheesery);\n")); }