You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by sv...@apache.org on 2016/10/31 12:24:27 UTC
[3/5] brooklyn-server git commit: fix Asserts missing import,
tidy following review comments
fix Asserts missing import, tidy following review comments
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/c8eb0de0
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/c8eb0de0
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/c8eb0de0
Branch: refs/heads/master
Commit: c8eb0de0445846fce3ef222227444cf2a2d8608f
Parents: 9c04001
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Wed Oct 19 11:01:17 2016 -0400
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Wed Oct 19 11:01:17 2016 -0400
----------------------------------------------------------------------
.../java/org/apache/brooklyn/test/Asserts.java | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/c8eb0de0/utils/common/src/main/java/org/apache/brooklyn/test/Asserts.java
----------------------------------------------------------------------
diff --git a/utils/common/src/main/java/org/apache/brooklyn/test/Asserts.java b/utils/common/src/main/java/org/apache/brooklyn/test/Asserts.java
index a4f8747..eee4e21 100644
--- a/utils/common/src/main/java/org/apache/brooklyn/test/Asserts.java
+++ b/utils/common/src/main/java/org/apache/brooklyn/test/Asserts.java
@@ -18,8 +18,6 @@
*/
package org.apache.brooklyn.test;
-import groovy.lang.Closure;
-
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Collection;
@@ -36,9 +34,11 @@ import java.util.concurrent.atomic.AtomicReference;
import org.apache.brooklyn.util.collections.MutableList;
import org.apache.brooklyn.util.collections.MutableSet;
import org.apache.brooklyn.util.exceptions.Exceptions;
+import org.apache.brooklyn.util.guava.Maybe;
import org.apache.brooklyn.util.javalang.JavaClassNames;
import org.apache.brooklyn.util.repeat.Repeater;
import org.apache.brooklyn.util.text.StringPredicates;
+import org.apache.brooklyn.util.text.Strings;
import org.apache.brooklyn.util.time.CountdownTimer;
import org.apache.brooklyn.util.time.Duration;
import org.slf4j.Logger;
@@ -55,6 +55,8 @@ import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
+import groovy.lang.Closure;
+
/**
* TODO should move this to new package brooklyn.util.assertions
* and TODO should add a repeating() method which returns an AssertingRepeater extending Repeater
@@ -690,7 +692,7 @@ public class Asserts {
* @param condition the condition to evaluate
*/
public static void assertTrue(boolean condition) {
- if (!condition) fail(null);
+ if (!condition) fail();
}
/**
@@ -723,6 +725,9 @@ public class Asserts {
public static AssertionError fail(String message) {
throw new AssertionError(message);
}
+ public static AssertionError fail(Throwable error) {
+ throw new AssertionError(error);
+ }
public static AssertionError fail() { throw new AssertionError(); }
public static void assertEqualsIgnoringOrder(Iterable<?> actual, Iterable<?> expected) {
@@ -1097,8 +1102,11 @@ public class Asserts {
}
public static <T> void assertThat(T object, Predicate<T> condition) {
+ assertThat(object, condition, null);
+ }
+ public static <T> void assertThat(T object, Predicate<T> condition, String message) {
if (condition.apply(object)) return;
- fail("Failed "+condition+": "+object);
+ fail(Strings.isBlank(message) ? "Failed "+condition+": "+object : message);
}
public static void assertStringContains(String input, String phrase1ToContain, String ...optionalOtherPhrasesToContain) {
@@ -1382,7 +1390,7 @@ public class Asserts {
}
public static void assertInstanceOf(Object obj, Class<?> type) {
- assertThat(obj, Predicates.instanceOf(type));
+ assertThat(obj, Predicates.instanceOf(type), "Expected "+type+" but found "+(obj==null ? "null" : obj+" ("+obj.getClass()+")"));
}
public static <T> void assertPresent(Maybe<T> candidate) {