### Question:
RuleTypeEvaluator { public IrodsRuleInvocationTypeEnum detectTypeFromRuleTextAnnotation(final String ruleText) { log.info("detectTypeFromRuleTextAnnotation()"); if (ruleText == null || ruleText.isEmpty()) { throw new IllegalArgumentException("null or empty ruleText"); } log.info("ruleText:{}", ruleText); IrodsRuleInvocationTypeEnum enumVal; int reAnnotationIndex = ruleText.indexOf(RULE_ENGINE_ANNOTATION); if (reAnnotationIndex > -1) { log.debug("found an annotation!"); int endOfAnnotation = reAnnotationIndex + RULE_ENGINE_ANNOTATION.length(); int nextSpace = ruleText.indexOf("\"", endOfAnnotation); if (nextSpace == -1) { log.warn("couldn't find end of annotation, just bail"); return null; } String annotationType = ruleText.substring(endOfAnnotation, nextSpace).trim(); log.debug("annotationType:{}", annotationType); if (annotationType.equals(IrodsRuleInvocationTypeEnum.IRODS.toString())) { enumVal = IrodsRuleInvocationTypeEnum.IRODS; } else if (annotationType.equals(IrodsRuleInvocationTypeEnum.PYTHON.toString())) { enumVal = IrodsRuleInvocationTypeEnum.PYTHON; } else if (annotationType.equals(IrodsRuleInvocationTypeEnum.OTHER.toString())) { enumVal = IrodsRuleInvocationTypeEnum.OTHER; } else { enumVal = null; } } else { enumVal = null; } return enumVal; } 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 testDetectTypeFromTextWithIrodsAnnotation() throws Exception { RuleTypeEvaluator detector = new RuleTypeEvaluator(); String ruleText = "# @RuleEngine=\"IRODS\""; IrodsRuleInvocationTypeEnum actual = detector.detectTypeFromRuleTextAnnotation(ruleText); Assert.assertEquals(IrodsRuleInvocationTypeEnum.IRODS, actual); }
@Test public void testDetectTypeFromTextWithOtherAnnotation() throws Exception { RuleTypeEvaluator detector = new RuleTypeEvaluator(); String ruleText = "# @RuleEngine=\"OTHER\""; IrodsRuleInvocationTypeEnum actual = detector.detectTypeFromRuleTextAnnotation(ruleText); Assert.assertEquals(IrodsRuleInvocationTypeEnum.OTHER, actual); }
@Test public void testDetectTypeFromTextWithPythonAnnotation() throws Exception { RuleTypeEvaluator detector = new RuleTypeEvaluator(); String ruleText = "# @RuleEngine=\"PYTHON\""; IrodsRuleInvocationTypeEnum actual = detector.detectTypeFromRuleTextAnnotation(ruleText); Assert.assertEquals(IrodsRuleInvocationTypeEnum.PYTHON, actual); }
@Test public void testDetectTypeFromTextWithIrodsSpacey() throws Exception { RuleTypeEvaluator detector = new RuleTypeEvaluator(); String ruleText = "# @RuleEngine=\" IRODS \" "; IrodsRuleInvocationTypeEnum actual = detector.detectTypeFromRuleTextAnnotation(ruleText); Assert.assertEquals(IrodsRuleInvocationTypeEnum.IRODS, actual); }