Coverage Report - org.apache.camel.impl.BinaryPredicateSupport
 
Classes in this File Line Coverage Branch Coverage Complexity
BinaryPredicateSupport
100% 
100% 
0
 
 1  
 /**
 2  
  *
 3  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 4  
  * contributor license agreements.  See the NOTICE file distributed with
 5  
  * this work for additional information regarding copyright ownership.
 6  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 7  
  * (the "License"); you may not use this file except in compliance with
 8  
  * the License.  You may obtain a copy of the License at
 9  
  *
 10  
  * http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing, software
 13  
  * distributed under the License is distributed on an "AS IS" BASIS,
 14  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15  
  * See the License for the specific language governing permissions and
 16  
  * limitations under the License.
 17  
  */
 18  
 package org.apache.camel.impl;
 19  
 
 20  
 import org.apache.camel.Predicate;
 21  
 import org.apache.camel.Exchange;
 22  
 import org.apache.camel.Expression;
 23  
 import org.apache.camel.util.ObjectHelper;
 24  
 import static org.apache.camel.util.ObjectHelper.notNull;
 25  
 
 26  
 /**
 27  
  * A useful base class for {@link Predicate} implementations
 28  
  *
 29  
  * @version $Revision: 1.1 $
 30  
  */
 31  25
 public abstract class BinaryPredicateSupport<E extends Exchange> implements Predicate<E> {
 32  
 
 33  
     private final Expression<E> left;
 34  
     private final Expression<E> right;
 35  
 
 36  25
     protected BinaryPredicateSupport(Expression<E> left, Expression<E> right) {
 37  25
         notNull(left, "left");
 38  25
         notNull(right, "right");
 39  
 
 40  25
         this.left = left;
 41  25
         this.right = right;
 42  25
     }
 43  
 
 44  
     @Override
 45  
     public String toString() {
 46  46
         return left + " " + getOperationText() + " " + right;
 47  
     }
 48  
 
 49  
     public boolean matches(E exchange) {
 50  17
         Object leftValue = left.evaluate(exchange);
 51  17
         Object rightValue = right.evaluate(exchange);
 52  17
         return matches(exchange, leftValue, rightValue);
 53  
     }
 54  
 
 55  
     public void assertMatches(String text, E exchange) {
 56  8
         Object leftValue = left.evaluate(exchange);
 57  8
         Object rightValue = right.evaluate(exchange);
 58  8
         if (!matches(exchange, leftValue, rightValue)) {
 59  2
             throw new AssertionError(assertionFailureMessage(exchange, leftValue, rightValue));
 60  
         }
 61  6
     }
 62  
 
 63  
     protected abstract boolean matches(E exchange, Object leftValue, Object rightValue);
 64  
 
 65  
     protected abstract String getOperationText();
 66  
 
 67  
     protected String assertionFailureMessage(E exchange, Object leftValue, Object rightValue) {
 68  2
         return this + " failed on " + exchange + " with left value <" + leftValue + "> right value <" + rightValue + ">";
 69  
     }
 70  
 }