brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [02/26] git commit: minor test utils fixes, including `assertThat`
Date Fri, 29 Aug 2014 23:01:02 GMT
minor test utils fixes, including `assertThat`


Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/141751b9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/141751b9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/141751b9

Branch: refs/heads/master
Commit: 141751b9213a28943b90e767349d11973a278083
Parents: a8bff36
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Wed Aug 6 22:04:45 2014 -0400
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Committed: Mon Aug 25 09:32:26 2014 +0100

----------------------------------------------------------------------
 .../src/main/java/brooklyn/test/TestUtils.groovy             | 8 ++++++--
 utils/common/src/main/java/brooklyn/test/Asserts.java        | 7 ++++++-
 .../brooklyn/util/collections/CollectionFunctionals.java     | 3 +++
 3 files changed, 15 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/141751b9/usage/test-support/src/main/java/brooklyn/test/TestUtils.groovy
----------------------------------------------------------------------
diff --git a/usage/test-support/src/main/java/brooklyn/test/TestUtils.groovy b/usage/test-support/src/main/java/brooklyn/test/TestUtils.groovy
index e163fad..78fefeb 100644
--- a/usage/test-support/src/main/java/brooklyn/test/TestUtils.groovy
+++ b/usage/test-support/src/main/java/brooklyn/test/TestUtils.groovy
@@ -24,7 +24,6 @@ import groovy.time.TimeDuration
 import java.util.concurrent.Callable
 import java.util.concurrent.ExecutionException
 import java.util.concurrent.Executors
-import java.util.concurrent.TimeUnit
 
 import org.codehaus.groovy.runtime.InvokerInvocationException
 import org.slf4j.Logger
@@ -32,7 +31,8 @@ import org.slf4j.LoggerFactory
 
 import brooklyn.entity.Entity
 import brooklyn.event.AttributeSensor
-import brooklyn.util.time.Duration;
+import brooklyn.util.text.StringFunctions;
+import brooklyn.util.time.Duration
 
 import com.google.common.base.Predicate
 import com.google.common.base.Supplier
@@ -526,6 +526,10 @@ public class TestUtils {
         fail("Expected collection of size "+expectedSize+" but got size "+actualSize+": "+c);
     }
 
+    /**
+     * @deprecated since 0.7.0; use {@link Asserts#assertThat(Object, Predicate)} with {@link
StringFunctions})}
+     */
+    @Deprecated
     public static void assertStringContainsLiteral(String string, String substring) {
         if (string==null) fail("String is null");
         if (substring==null) fail("Substring is null");

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/141751b9/utils/common/src/main/java/brooklyn/test/Asserts.java
----------------------------------------------------------------------
diff --git a/utils/common/src/main/java/brooklyn/test/Asserts.java b/utils/common/src/main/java/brooklyn/test/Asserts.java
index 68a414f..d52c347 100644
--- a/utils/common/src/main/java/brooklyn/test/Asserts.java
+++ b/utils/common/src/main/java/brooklyn/test/Asserts.java
@@ -420,7 +420,12 @@ public class Asserts {
             throw new ExecutionException(throwable.get());
         }
     }
-    
+
+    public static <T> void assertThat(T object, Predicate<T> condition) {
+        if (condition.apply(object)) return;
+        fail("Failed "+condition+": "+object);
+    }
+
     @SuppressWarnings("rawtypes")
     private static boolean groovyTruth(Object o) {
         // TODO Doesn't handle matchers (see http://docs.codehaus.org/display/GROOVY/Groovy+Truth)

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/141751b9/utils/common/src/main/java/brooklyn/util/collections/CollectionFunctionals.java
----------------------------------------------------------------------
diff --git a/utils/common/src/main/java/brooklyn/util/collections/CollectionFunctionals.java
b/utils/common/src/main/java/brooklyn/util/collections/CollectionFunctionals.java
index 1e7ffb5..07088b5 100644
--- a/utils/common/src/main/java/brooklyn/util/collections/CollectionFunctionals.java
+++ b/utils/common/src/main/java/brooklyn/util/collections/CollectionFunctionals.java
@@ -42,6 +42,7 @@ public class CollectionFunctionals {
             public Integer get() {
                 return Iterables.size(collection);
             }
+            @Override public String toString() { return "sizeSupplier("+collection+")"; }
         };
     }
     
@@ -51,6 +52,7 @@ public class CollectionFunctionals {
             public Integer apply(Iterable<?> input) {
                 return Iterables.size(input);
             }
+            @Override public String toString() { return "sizeFunction"; }
         };
     }
 
@@ -60,6 +62,7 @@ public class CollectionFunctionals {
             public Set<K> apply(Map<K, ?> input) {
                 return input.keySet();
             }
+            @Override public String toString() { return "keys"; }
         };
     }
 


Mime
View raw message