### Question:
RuleTypeEvaluator { public IrodsRuleInvocationTypeEnum guessRuleLanguageType(final String ruleText) throws UnknownRuleTypeException { if (ruleText == null || ruleText.isEmpty()) { throw new IllegalArgumentException("Cannot determine the rule type"); } log.debug("first look for a rule annotation..."); IrodsRuleInvocationTypeEnum enumFromAnnotation = detectTypeFromRuleTextAnnotation(ruleText); if (enumFromAnnotation != null) { log.debug("found type from annotation:{}", enumFromAnnotation); return enumFromAnnotation; } Matcher m = irodsRulePattern.matcher(ruleText); Matcher m2 = irodsRulePattern2.matcher(ruleText); boolean irodsMatcher = m.find(); boolean irodsMatcher2 = m2.find(); if (irodsMatcher && irodsMatcher2) { return IrodsRuleInvocationTypeEnum.IRODS; } m = pythonRulePattern.matcher(ruleText); boolean pythonMatcher = m.find(); if (pythonMatcher) { return IrodsRuleInvocationTypeEnum.PYTHON; } return IrodsRuleInvocationTypeEnum.OTHER; } RuleTypeEvaluator(); IrodsRuleInvocationTypeEnum guessRuleLanguageType(final String ruleText); IrodsRuleInvocationTypeEnum detectTypeFromExtension(final String fileName); IrodsRuleInvocationTypeEnum detectTypeFromRuleTextAnnotation(final String ruleText); static final String RULE_ENGINE_ANNOTATION; }### Answer:
@Test public void testIrodsText() throws Exception { String ruleText = "myTestRule { \n hello; \n }"; RuleTypeEvaluator ruleTypeEvaluator = new RuleTypeEvaluator(); IrodsRuleInvocationTypeEnum actual = ruleTypeEvaluator.guessRuleLanguageType(ruleText); Assert.assertEquals(IrodsRuleInvocationTypeEnum.IRODS, actual); }
@Test public void testOtherText() throws Exception { String ruleText = "{ \n hello:'goodbye' \n }"; RuleTypeEvaluator ruleTypeEvaluator = new RuleTypeEvaluator(); IrodsRuleInvocationTypeEnum actual = ruleTypeEvaluator.guessRuleLanguageType(ruleText); Assert.assertEquals(IrodsRuleInvocationTypeEnum.OTHER, actual); }
@Test public void testPythonText() throws Exception { String ruleText = " def hello :"; RuleTypeEvaluator ruleTypeEvaluator = new RuleTypeEvaluator(); IrodsRuleInvocationTypeEnum actual = ruleTypeEvaluator.guessRuleLanguageType(ruleText); Assert.assertEquals(IrodsRuleInvocationTypeEnum.PYTHON, actual); }
@Test public void testDetectIrodsNewFormatWithExternal() throws Exception { RuleTypeEvaluator detector = new RuleTypeEvaluator(); String ruleString = LocalFileUtils.getClasspathResourceFileAsString("/rules/rulemsiGetIcatTimeWithExternal.r"); IrodsRuleInvocationTypeEnum actual = detector.guessRuleLanguageType(ruleString); Assert.assertEquals(IrodsRuleInvocationTypeEnum.IRODS, actual); }