You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2011/01/28 17:59:48 UTC

svn commit: r1064776 - /camel/trunk/camel-core/src/main/java/org/apache/camel/component/mock/AssertionClause.java

Author: davsclaus
Date: Fri Jan 28 16:59:48 2011
New Revision: 1064776

URL: http://svn.apache.org/viewvc?rev=1064776&view=rev
Log:
Fixed CS

Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/mock/AssertionClause.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/mock/AssertionClause.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/mock/AssertionClause.java?rev=1064776&r1=1064775&r2=1064776&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/mock/AssertionClause.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/mock/AssertionClause.java Fri Jan 28 16:59:48 2011
@@ -35,9 +35,11 @@ import org.apache.camel.util.PredicateAs
  */
 public abstract class AssertionClause extends ExpressionClauseSupport<ValueBuilder> implements Runnable {
 
-    private List<Predicate> predicates = new ArrayList<Predicate>();
     protected final MockEndpoint mock;
     protected volatile int currentIndex;
+    private final List<Predicate> predicates = new ArrayList<Predicate>();
+    private final Expression previous = new PreviousTimestamp();
+    private final Expression next = new NextTimestamp();
 
     public AssertionClause(MockEndpoint mock) {
         super(null);
@@ -72,26 +74,6 @@ public abstract class AssertionClause ex
      * Adds a {@link TimeClause} predicate for message arriving.
      */
     public TimeClause arrives() {
-        Expression next = new Expression() {
-            public <T> T evaluate(Exchange exchange, Class<T> type) {
-                Date answer = null;
-                if (currentIndex < mock.getReceivedCounter() - 1) {
-                    answer = mock.getReceivedExchanges().get(currentIndex + 1).getProperty(Exchange.RECEIVED_TIMESTAMP, Date.class);
-                }
-                return (T) answer;
-            }
-        };
-
-        Expression previous = new Expression() {
-            public <T> T evaluate(Exchange exchange, Class<T> type) {
-                Date answer = null;
-                if (currentIndex > 0 && mock.getReceivedCounter() > 0) {
-                    answer = mock.getReceivedExchanges().get(currentIndex - 1).getProperty(Exchange.RECEIVED_TIMESTAMP, Date.class);
-                }
-                return (T) answer;
-            }
-        };
-
         final TimeClause clause = new TimeClause(previous, next);
         addPredicate(new Predicate() {
             public boolean matches(Exchange exchange) {
@@ -120,6 +102,28 @@ public abstract class AssertionClause ex
         predicates.add(predicate);
     }
 
+    @SuppressWarnings("unchecked")
+    private final class PreviousTimestamp implements Expression {
+        public <T> T evaluate(Exchange exchange, Class<T> type) {
+            Date answer = null;
+            if (currentIndex > 0 && mock.getReceivedCounter() > 0) {
+                answer = mock.getReceivedExchanges().get(currentIndex - 1).getProperty(Exchange.RECEIVED_TIMESTAMP, Date.class);
+            }
+            return (T) answer;
+        }
+    }
+
+    @SuppressWarnings("unchecked")
+    private final class NextTimestamp implements Expression {
+        public <T> T evaluate(Exchange exchange, Class<T> type) {
+            Date answer = null;
+            if (currentIndex < mock.getReceivedCounter() - 1) {
+                answer = mock.getReceivedExchanges().get(currentIndex + 1).getProperty(Exchange.RECEIVED_TIMESTAMP, Date.class);
+            }
+            return (T) answer;
+        }
+    }
+
     /**
      * Public class needed for fluent builders
      */