commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r1519877 - in /commons/proper/proxy/branches/version-2.0-work: core/src/main/java/org/apache/commons/proxy2/interceptor/matcher/argument/ArgumentMatcherUtils.java stub/src/main/java/org/apache/commons/proxy2/stub/BaseTrainer.java
Date Tue, 03 Sep 2013 22:45:46 GMT
Author: mbenson
Date: Tue Sep  3 22:45:46 2013
New Revision: 1519877

URL: http://svn.apache.org/r1519877
Log:
expose argThat() API for stub training, make built-in argumentMatchers generic

Modified:
    commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy2/interceptor/matcher/argument/ArgumentMatcherUtils.java
    commons/proper/proxy/branches/version-2.0-work/stub/src/main/java/org/apache/commons/proxy2/stub/BaseTrainer.java

Modified: commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy2/interceptor/matcher/argument/ArgumentMatcherUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy2/interceptor/matcher/argument/ArgumentMatcherUtils.java?rev=1519877&r1=1519876&r2=1519877&view=diff
==============================================================================
--- commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy2/interceptor/matcher/argument/ArgumentMatcherUtils.java
(original)
+++ commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy2/interceptor/matcher/argument/ArgumentMatcherUtils.java
Tue Sep  3 22:45:46 2013
@@ -18,6 +18,7 @@
 package org.apache.commons.proxy2.interceptor.matcher.argument;
 
 import org.apache.commons.lang3.ObjectUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.Validate;
 import org.apache.commons.proxy2.interceptor.matcher.ArgumentMatcher;
 
@@ -27,9 +28,9 @@ public final class ArgumentMatcherUtils
 // Static Methods
 //----------------------------------------------------------------------------------------------------------------------
 
-    public static ArgumentMatcher<Object> any()
+    public static <T> ArgumentMatcher<T> any()
     {
-        return new AnyMatcher();
+        return new AnyMatcher<T>();
     }
 
     public static ArgumentMatcher<String> endsWith(String suffix)
@@ -52,14 +53,14 @@ public final class ArgumentMatcherUtils
         return new GreaterThanOrEqualMatcher<C>(comparable);
     }
 
-    public static ArgumentMatcher<Object> isA(final Class<?> type)
+    public static <T> ArgumentMatcher<T> isA(final Class<?> type)
     {
-        return new InstanceOfMatcher(type);
+        return new InstanceOfMatcher<T>(type);
     }
 
-    public static ArgumentMatcher<Object> isNull()
+    public static <T> ArgumentMatcher<T> isNull()
     {
-        return new IsNullMatcher();
+        return new IsNullMatcher<T>();
     }
 
     public static <C extends Comparable<?>> ArgumentMatcher<C> lt(C comparable)
@@ -100,10 +101,10 @@ public final class ArgumentMatcherUtils
 // Inner Classes
 //----------------------------------------------------------------------------------------------------------------------
 
-    private static final class AnyMatcher implements ArgumentMatcher<Object>
+    private static final class AnyMatcher<T> implements ArgumentMatcher<T>
     {
         @Override
-        public boolean matches(Object argument)
+        public boolean matches(T argument)
         {
             return true;
         }
@@ -146,7 +147,7 @@ public final class ArgumentMatcherUtils
         @Override
         public boolean matches(String argument)
         {
-            return argument != null && argument.endsWith(suffix);
+        	return StringUtils.endsWith(argument, suffix);
         }
     }
 
@@ -194,26 +195,26 @@ public final class ArgumentMatcherUtils
         }
     }
 
-    private static final class InstanceOfMatcher implements ArgumentMatcher<Object>
+    private static final class InstanceOfMatcher<T> implements ArgumentMatcher<T>
     {
         private final Class<?> type;
 
         public InstanceOfMatcher(Class<?> type)
         {
-            this.type = type;
+            this.type = Validate.notNull(type, "type");
         }
 
         @Override
-        public boolean matches(Object argument)
+        public boolean matches(T argument)
         {
             return type.isInstance(argument);
         }
     }
 
-    private static final class IsNullMatcher implements ArgumentMatcher<Object>
+    private static final class IsNullMatcher<T> implements ArgumentMatcher<T>
     {
         @Override
-        public boolean matches(Object argument)
+        public boolean matches(T argument)
         {
             return argument == null;
         }
@@ -284,7 +285,7 @@ public final class ArgumentMatcherUtils
         @Override
         public boolean matches(String argument)
         {
-            return argument != null && argument.startsWith(prefix);
+        	return StringUtils.startsWith(argument, prefix);
         }
     }
 }

Modified: commons/proper/proxy/branches/version-2.0-work/stub/src/main/java/org/apache/commons/proxy2/stub/BaseTrainer.java
URL: http://svn.apache.org/viewvc/commons/proper/proxy/branches/version-2.0-work/stub/src/main/java/org/apache/commons/proxy2/stub/BaseTrainer.java?rev=1519877&r1=1519876&r2=1519877&view=diff
==============================================================================
--- commons/proper/proxy/branches/version-2.0-work/stub/src/main/java/org/apache/commons/proxy2/stub/BaseTrainer.java
(original)
+++ commons/proper/proxy/branches/version-2.0-work/stub/src/main/java/org/apache/commons/proxy2/stub/BaseTrainer.java
Tue Sep  3 22:45:46 2013
@@ -75,25 +75,23 @@ public abstract class BaseTrainer<S exte
 
     protected <R> R any(Class<R> type)
     {
-        record(ArgumentMatcherUtils.any());
-        return null;
+        return argThat(ArgumentMatcherUtils.<R> any());
     }
 
-    private void record(ArgumentMatcher<?> matcher)
+    protected <R> R eq(R value)
     {
-        trainingContext().record(matcher);
+        return argThat(ArgumentMatcherUtils.eq(value));
     }
 
-    protected <R> R eq(R value)
+    protected <R> R isInstance(Class<R> type)
     {
-        record(ArgumentMatcherUtils.eq(value));
-        return value;
+        return argThat(ArgumentMatcherUtils.<R> isA(type));
     }
 
-    protected <R> R isInstance(Class<R> type)
+    protected <R> R argThat(ArgumentMatcher<R> matcher)
     {
-        record(ArgumentMatcherUtils.isA(type));
-        return ProxyUtils.nullValue(type);
+        trainingContext().record(matcher);
+        return null;
     }
 
     protected void thenThrow(Exception e)



Mime
View raw message