Beispiel #1
0
 public TextStream explain(String input) {
   TextStream stream = new TextStream(input);
   for (Letter letter : stream) {
     evaluator.evaluate(letter);
   }
   for (Letter letter : stream) {
     evaluator.evaluate(letter);
   }
   for (Letter letter : stream) {
     evaluator.evaluate(letter);
   }
   return stream;
 }
Beispiel #2
0
 public WordExplainator() {
   evaluator.addRule(new PrefixVowel());
   evaluator.addRule(new FloatingVowel());
   evaluator.addRule(new Syllable());
   evaluator.addRule(new FinalConsonant());
   evaluator.addRule(new SuffixLetterFromVowel());
   evaluator.addRule(new FinalVowel());
   evaluator.addRule(new Vowel());
   evaluator.addRule(new ClusterConsonant());
   evaluator.addRule(new PrefixConsonant());
 }
Beispiel #3
0
  private static boolean evaluatePayloadValidator(
      @Nonnull final RuleEvaluator ruleEvaluator, final String rule, @Nonnull final Payload payload)
      throws IncompatibleTestMatrixException {
    Map<String, Object> values = Collections.singletonMap("value", payload.fetchAValue());

    try {
      return ruleEvaluator.evaluateBooleanRule(rule, values);
    } catch (@Nonnull final IllegalArgumentException e) {
      LOGGER.error("Unable to evaluate rule ${" + rule + "} with payload " + payload, e);
    }

    return false;
  }
  @Test
  public void testExceptionsDealtWith() {
    final String testName = "test";

    final ConsumableTestDefinition testDefinition = new ConsumableTestDefinition();
    testDefinition.setConstants(Collections.<String, Object>emptyMap());
    testDefinition.setRule("${lang == 'en'}");

    testDefinition.setTestType(TestType.ANONYMOUS_USER);

    // most tests just set the salt to be the same as the test name
    testDefinition.setSalt(testName);
    testDefinition.setBuckets(Collections.<TestBucket>emptyList());

    final RuleEvaluator ruleEvaluator = EasyMock.createMock(RuleEvaluator.class);
    EasyMock.expect(
            ruleEvaluator.evaluateBooleanRule(
                EasyMock.<String>anyObject(), EasyMock.<Map<String, Object>>anyObject()))
        // throw an unexpected type of runtime exception
        .andThrow(new RuntimeException() {})
        // Must be evaluated, or this was not a valid test
        .once();
    EasyMock.replay(ruleEvaluator);

    final TestRangeSelector selector =
        new TestRangeSelector(ruleEvaluator, testName, testDefinition);

    // Ensure no exceptions thrown.
    final TestBucket bucket =
        new StandardTestChooser(selector)
            .choose("identifier", Collections.<String, Object>emptyMap());

    assertEquals("Expected no bucket to be found ", null, bucket);

    EasyMock.verify(ruleEvaluator);
  }