This is an automated email from the ASF dual-hosted git repository.
jamesbognar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/juneau.git
The following commit(s) were added to refs/heads/master by this push:
new ffb7dbc REST refactoring.
ffb7dbc is described below
commit ffb7dbc613b70a9d947c2978472d2a8a214d1e6f
Author: JamesBognar <[email protected]>
AuthorDate: Tue Feb 16 13:36:40 2021 -0500
REST refactoring.
---
.../juneau/assertions/ComparableAssertion.java | 2 +-
.../juneau/assertions/FluentArrayAssertion.java | 2 +-
...jectAssertion.java => FluentBaseAssertion.java} | 140 +-------
.../juneau/assertions/FluentBeanAssertion.java | 2 +-
.../juneau/assertions/FluentBooleanAssertion.java | 2 +-
.../assertions/FluentCollectionAssertion.java | 2 +-
.../assertions/FluentComparableAssertion.java | 16 +-
.../juneau/assertions/FluentDateAssertion.java | 2 +-
.../juneau/assertions/FluentIntegerAssertion.java | 2 +-
.../juneau/assertions/FluentLongAssertion.java | 3 +-
.../juneau/assertions/FluentMapAssertion.java | 2 +-
.../juneau/assertions/FluentObjectAssertion.java | 387 +--------------------
.../juneau/assertions/FluentStringAssertion.java | 2 +-
.../assertions/FluentThrowableAssertion.java | 39 +--
.../assertions/FluentZonedDateTimeAssertion.java | 2 +-
.../assertion/FluentResponseHeaderAssertion.java | 7 +-
.../assertions/FluentRequestHeaderAssertion.java | 18 +-
.../FluentRequestQueryParamAssertion.java | 7 +-
18 files changed, 41 insertions(+), 596 deletions(-)
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/ComparableAssertion.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/ComparableAssertion.java
index ec62f71..350df8d 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/ComparableAssertion.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/ComparableAssertion.java
@@ -19,7 +19,7 @@ import org.apache.juneau.internal.*;
*/
@FluentSetters(returns="ComparableAssertion")
@SuppressWarnings("rawtypes")
-public class ComparableAssertion extends
FluentComparableAssertion<ComparableAssertion> {
+public class ComparableAssertion extends
FluentComparableAssertion<Comparable,ComparableAssertion> {
/**
* Creator.
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentArrayAssertion.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentArrayAssertion.java
index e0b3383..3468ec9 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentArrayAssertion.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentArrayAssertion.java
@@ -26,7 +26,7 @@ import org.apache.juneau.marshall.*;
* @param <R> The return type.
*/
@FluentSetters(returns="FluentArrayAssertion<R>")
-public class FluentArrayAssertion<R> extends FluentObjectAssertion<R> {
+public class FluentArrayAssertion<R> extends FluentBaseAssertion<Object,R> {
private Object value;
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentObjectAssertion.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentBaseAssertion.java
similarity index 78%
copy from
juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentObjectAssertion.java
copy to
juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentBaseAssertion.java
index f67f853..26dc70e 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentObjectAssertion.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentBaseAssertion.java
@@ -12,11 +12,8 @@
//
***************************************************************************************************************************
package org.apache.juneau.assertions;
-import java.time.*;
-import java.util.*;
import java.util.function.*;
-import org.apache.juneau.*;
import org.apache.juneau.internal.*;
import org.apache.juneau.json.*;
import org.apache.juneau.marshall.*;
@@ -26,12 +23,13 @@ import org.apache.juneau.serializer.*;
/**
* Used for fluent assertion calls against POJOs.
*
+ * @param <V> The object type.
* @param <R> The return type.
*/
-@FluentSetters(returns="FluentObjectAssertion<R>")
-public class FluentObjectAssertion<R> extends FluentAssertion<R> {
+@FluentSetters(returns="FluentBaseAssertion<V,R>")
+public class FluentBaseAssertion<V,R> extends FluentAssertion<R> {
- private final Object value;
+ private final V value;
private static JsonSerializer JSON = JsonSerializer.create()
.ssq()
@@ -50,7 +48,7 @@ public class FluentObjectAssertion<R> extends
FluentAssertion<R> {
* @param value The object being tested.
* @param returns The object to return after the test.
*/
- public FluentObjectAssertion(Object value, R returns) {
+ public FluentBaseAssertion(V value, R returns) {
this(null, value, returns);
}
@@ -61,7 +59,7 @@ public class FluentObjectAssertion<R> extends
FluentAssertion<R> {
* @param value The object being tested.
* @param returns The object to return after the test.
*/
- public FluentObjectAssertion(Assertion creator, Object value, R
returns) {
+ public FluentBaseAssertion(Assertion creator, V value, R returns) {
super(creator, returns);
this.value = value;
}
@@ -298,7 +296,7 @@ public class FluentObjectAssertion<R> extends
FluentAssertion<R> {
* @return The response object (for method chaining).
* @throws AssertionError If assertion failed.
*/
- public R passes(Predicate<Object> test) throws AssertionError {
+ public R passes(Predicate<V> test) throws AssertionError {
if (! test.test(value))
throw error("Value did not pass predicate
test.\n\tValue=[{0}]", value);
return returns();
@@ -431,140 +429,22 @@ public class FluentObjectAssertion<R> extends
FluentAssertion<R> {
return o;
}
- @SuppressWarnings("unchecked")
- private <T> T cast(Class<T> c) throws AssertionError {
- Object o = value;
- if (value == null || c.isInstance(value))
- return (T)o;
- throw new BasicAssertionError("Object was not type ''{0}''.
Actual=''{1}''", c, o.getClass());
- }
-
- /**
- * Converts this object assertion into an array assertion.
- *
- * @return A new assertion.
- * @throws AssertionError If object is not an array.
- */
- public FluentArrayAssertion<R> asArray() throws AssertionError {
- return new FluentArrayAssertion<>(this, value, returns());
- }
-
- /**
- * Converts this object assertion into a boolean assertion.
- *
- * @return A new assertion.
- * @throws AssertionError If object is not a boolean.
- */
- public FluentBooleanAssertion<R> asBoolean() {
- return new FluentBooleanAssertion<>(this, cast(Boolean.class),
returns());
- }
-
- /**
- * Converts this object assertion into a byte array assertion.
- *
- * @return A new assertion.
- * @throws AssertionError If object is not a byte array.
- */
- public FluentByteArrayAssertion<R> asByteArray() {
- return new FluentByteArrayAssertion<>(this, cast(byte[].class),
returns());
- }
-
- /**
- * Converts this object assertion into a collection assertion.
- *
- * @return A new assertion.
- * @throws AssertionError If object is not a collection.
- */
- public FluentCollectionAssertion<R> asCollection() {
- return new FluentCollectionAssertion<>(this,
cast(Collection.class), returns());
- }
-
- /**
- * Converts this object assertion into a comparable object assertion.
- *
- * @return A new assertion.
- * @throws AssertionError If object is not an instance of {@link
Comparable}.
- */
- public FluentComparableAssertion<R> asComparable() {
- return new FluentComparableAssertion<>(this,
cast(Comparable.class), returns());
- }
-
- /**
- * Converts this object assertion into a date assertion.
- *
- * @return A new assertion.
- * @throws AssertionError If object is not a date.
- */
- public FluentDateAssertion<R> asDate() {
- return new FluentDateAssertion<>(this, cast(Date.class),
returns());
- }
-
- /**
- * Converts this object assertion into an integer assertion.
- *
- * @return A new assertion.
- * @throws AssertionError If object is not an integer.
- */
- public FluentIntegerAssertion<R> asInteger() {
- return new FluentIntegerAssertion<>(this, cast(Integer.class),
returns());
- }
-
- /**
- * Converts this object assertion into a list assertion.
- *
- * @return A new assertion.
- * @throws AssertionError If object is not a list.
- */
- public FluentListAssertion<R> asList() {
- return new FluentListAssertion<>(this, cast(List.class),
returns());
- }
-
- /**
- * Converts this object assertion into a long assertion.
- *
- * @return A new assertion.
- * @throws AssertionError If object is not a long.
- */
- public FluentLongAssertion<R> asLong() {
- return new FluentLongAssertion<>(this, cast(Long.class),
returns());
- }
-
- /**
- * Converts this object assertion into a map assertion.
- *
- * @return A new assertion.
- * @throws AssertionError If object is not a map.
- */
- public FluentMapAssertion<R> asMap() {
- return new FluentMapAssertion<>(this, cast(Map.class),
returns());
- }
-
- /**
- * Converts this object assertion into a zoned-datetime assertion.
- *
- * @return A new assertion.
- * @throws AssertionError If object is not a zoned-datetime.
- */
- public FluentZonedDateTimeAssertion<R> asZonedDateTime() {
- return new FluentZonedDateTimeAssertion<>(this,
cast(ZonedDateTime.class), returns());
- }
-
// <FluentSetters>
@Override /* GENERATED - Assertion */
- public FluentObjectAssertion<R> msg(String msg, Object...args) {
+ public FluentBaseAssertion<V,R> msg(String msg, Object...args) {
super.msg(msg, args);
return this;
}
@Override /* GENERATED - Assertion */
- public FluentObjectAssertion<R> stderr() {
+ public FluentBaseAssertion<V,R> stderr() {
super.stderr();
return this;
}
@Override /* GENERATED - Assertion */
- public FluentObjectAssertion<R> stdout() {
+ public FluentBaseAssertion<V,R> stdout() {
super.stdout();
return this;
}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentBeanAssertion.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentBeanAssertion.java
index 352f938..f4764fe 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentBeanAssertion.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentBeanAssertion.java
@@ -21,7 +21,7 @@ import org.apache.juneau.internal.*;
* @param <R> The return type.
*/
@FluentSetters(returns="FluentObjectAssertion<R>")
-public class FluentBeanAssertion<R> extends FluentObjectAssertion<R> {
+public class FluentBeanAssertion<R> extends FluentBaseAssertion<Object,R> {
private final Object value;
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentBooleanAssertion.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentBooleanAssertion.java
index 277fca2..2e0e14c 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentBooleanAssertion.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentBooleanAssertion.java
@@ -21,7 +21,7 @@ import org.apache.juneau.internal.*;
* @param <R> The return type.
*/
@FluentSetters(returns="FluentBooleanAssertion<R>")
-public class FluentBooleanAssertion<R> extends FluentComparableAssertion<R> {
+public class FluentBooleanAssertion<R> extends
FluentComparableAssertion<Boolean,R> {
private final Boolean value;
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentCollectionAssertion.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentCollectionAssertion.java
index 61eccbc..4f37ff2 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentCollectionAssertion.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentCollectionAssertion.java
@@ -26,7 +26,7 @@ import org.apache.juneau.marshall.*;
*/
@FluentSetters(returns="FluentCollectionAssertion<R>")
@SuppressWarnings("rawtypes")
-public class FluentCollectionAssertion<R> extends FluentObjectAssertion<R> {
+public class FluentCollectionAssertion<R> extends
FluentBaseAssertion<Collection,R> {
private Collection value;
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentComparableAssertion.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentComparableAssertion.java
index db307af..8343636 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentComparableAssertion.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentComparableAssertion.java
@@ -17,13 +17,14 @@ import org.apache.juneau.internal.*;
/**
* Used for fluent assertion calls against comparable objects.
*
+ * @param <V> The value type
* @param <R> The return type.
*/
@FluentSetters(returns="FluentComparableAssertion<R>")
@SuppressWarnings("rawtypes")
-public class FluentComparableAssertion<R> extends FluentObjectAssertion<R> {
+public class FluentComparableAssertion<V extends Comparable,R> extends
FluentBaseAssertion<V,R> {
- private final Comparable value;
+ private final V value;
/**
* Constructor.
@@ -31,7 +32,7 @@ public class FluentComparableAssertion<R> extends
FluentObjectAssertion<R> {
* @param value The value being tested.
* @param returns The object to return after the test.
*/
- public FluentComparableAssertion(Comparable value, R returns) {
+ public FluentComparableAssertion(V value, R returns) {
this(null, value, returns);
}
@@ -42,7 +43,7 @@ public class FluentComparableAssertion<R> extends
FluentObjectAssertion<R> {
* @param value The value being tested.
* @param returns The object to return after the test.
*/
- public FluentComparableAssertion(Assertion creator, Comparable value, R
returns) {
+ public FluentComparableAssertion(Assertion creator, V value, R returns)
{
super(creator, value, returns);
this.value = value;
}
@@ -186,6 +187,7 @@ public class FluentComparableAssertion<R> extends
FluentObjectAssertion<R> {
* @param value The object to compare against.
* @return The comparison value.
*/
+ @SuppressWarnings("unchecked")
protected int compareTo(Object value) {
return this.value.compareTo(equivalent(value));
}
@@ -193,19 +195,19 @@ public class FluentComparableAssertion<R> extends
FluentObjectAssertion<R> {
// <FluentSetters>
@Override /* GENERATED - Assertion */
- public FluentComparableAssertion<R> msg(String msg, Object...args) {
+ public FluentComparableAssertion<V,R> msg(String msg, Object...args) {
super.msg(msg, args);
return this;
}
@Override /* GENERATED - Assertion */
- public FluentComparableAssertion<R> stderr() {
+ public FluentComparableAssertion<V,R> stderr() {
super.stderr();
return this;
}
@Override /* GENERATED - Assertion */
- public FluentComparableAssertion<R> stdout() {
+ public FluentComparableAssertion<V,R> stdout() {
super.stdout();
return this;
}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentDateAssertion.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentDateAssertion.java
index 9c9641c..003ca2b 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentDateAssertion.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentDateAssertion.java
@@ -34,7 +34,7 @@ import org.apache.juneau.internal.*;
* @param <R> The return type.
*/
@FluentSetters(returns="FluentDateAssertion<R>")
-public class FluentDateAssertion<R> extends FluentComparableAssertion<R> {
+public class FluentDateAssertion<R> extends FluentComparableAssertion<Date,R> {
private final Date value;
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentIntegerAssertion.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentIntegerAssertion.java
index 856c27b..fb50067 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentIntegerAssertion.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentIntegerAssertion.java
@@ -30,7 +30,7 @@ import org.apache.juneau.internal.*;
* @param <R> The return type.
*/
@FluentSetters(returns="FluentIntegerAssertion<R>")
-public class FluentIntegerAssertion<R> extends FluentComparableAssertion<R> {
+public class FluentIntegerAssertion<R> extends
FluentComparableAssertion<Integer,R> {
private final Integer value;
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentLongAssertion.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentLongAssertion.java
index 2d14933..aa9eeca 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentLongAssertion.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentLongAssertion.java
@@ -30,7 +30,7 @@ import org.apache.juneau.internal.*;
* @param <R> The return type.
*/
@FluentSetters(returns="FluentLongAssertion<R>")
-public class FluentLongAssertion<R> extends FluentComparableAssertion<R> {
+public class FluentLongAssertion<R> extends FluentComparableAssertion<Long,R> {
private final Long value;
@@ -61,7 +61,6 @@ public class FluentLongAssertion<R> extends
FluentComparableAssertion<R> {
*
* @return A new assertion.
*/
- @Override
public FluentIntegerAssertion<R> asInteger() {
return new FluentIntegerAssertion<>(this, value == null ? null
: value.intValue(), returns());
}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentMapAssertion.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentMapAssertion.java
index dff8e76..bf0eab0 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentMapAssertion.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentMapAssertion.java
@@ -24,7 +24,7 @@ import org.apache.juneau.marshall.*;
*/
@FluentSetters(returns="FluentMapAssertion<R>")
@SuppressWarnings("rawtypes")
-public class FluentMapAssertion<R> extends FluentObjectAssertion<R> {
+public class FluentMapAssertion<R> extends FluentBaseAssertion<Map,R> {
private Map value;
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentObjectAssertion.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentObjectAssertion.java
index f67f853..98cfe49 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentObjectAssertion.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentObjectAssertion.java
@@ -14,14 +14,9 @@ package org.apache.juneau.assertions;
import java.time.*;
import java.util.*;
-import java.util.function.*;
import org.apache.juneau.*;
import org.apache.juneau.internal.*;
-import org.apache.juneau.json.*;
-import org.apache.juneau.marshall.*;
-import org.apache.juneau.reflect.*;
-import org.apache.juneau.serializer.*;
/**
* Used for fluent assertion calls against POJOs.
@@ -29,21 +24,10 @@ import org.apache.juneau.serializer.*;
* @param <R> The return type.
*/
@FluentSetters(returns="FluentObjectAssertion<R>")
-public class FluentObjectAssertion<R> extends FluentAssertion<R> {
+public class FluentObjectAssertion<R> extends FluentBaseAssertion<Object,R> {
private final Object value;
- private static JsonSerializer JSON = JsonSerializer.create()
- .ssq()
- .build();
-
- private static JsonSerializer JSON_SORTED = JsonSerializer.create()
- .ssq()
- .sortProperties()
- .sortCollections()
- .sortMaps()
- .build();
-
/**
* Constructor.
*
@@ -62,375 +46,10 @@ public class FluentObjectAssertion<R> extends
FluentAssertion<R> {
* @param returns The object to return after the test.
*/
public FluentObjectAssertion(Assertion creator, Object value, R
returns) {
- super(creator, returns);
+ super(creator, value, returns);
this.value = value;
}
- /**
- * Asserts that the object is an instance of the specified class.
- *
- * <h5 class='section'>Example:</h5>
- * <p class='bcode w800'>
- * <jc>// Validates that the specified object is an instance of
MyBean.</jc>
- * <jsm>assertObject<jsm>(myPojo).isType(MyBean.<jk>class</jk>);
- * </p>
- *
- * @param parent The value to check against.
- * @return The response object (for method chaining).
- * @throws AssertionError If assertion failed.
- */
- public R isType(Class<?> parent) throws AssertionError {
- exists();
- assertNotNull("parent", parent);
- if (! ClassInfo.of(value).isChildOf(parent))
- throw error("Unexpected
class.\n\tExpect=[{0}]\n\tActual=[{1}]", className(parent), className(value));
- return returns();
- }
-
- /**
- * Converts this object to text using the specified serializer and
returns it as a new assertion.
- *
- * <h5 class='section'>Example:</h5>
- * <p class='bcode w800'>
- * <jc>// Validates that the specified object is an instance of
MyBean.</jc>
- *
<jsm>assertObject<jsm>(myPojo).asString(XmlSerializer.<jsf>DEFAULT</jsf>).is(<js>"<object><foo>bar</foo><baz>qux</baz></object>"</js>);
- * </p>
- *
- * @param ws The serializer to use to convert the object to text.
- * @return A new fluent string assertion.
- */
- public FluentStringAssertion<R> asString(WriterSerializer ws) {
- try {
- String s = ws.serialize(this.value);
- return new FluentStringAssertion<>(this, s, returns());
- } catch (SerializeException e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * Converts this object to a string using {@link Object#toString} and
returns it as a new assertion.
- *
- * <h5 class='section'>Example:</h5>
- * <p class='bcode w800'>
- * <jc>// Validates that the specified object is "foobar" after
converting to a string.</jc>
- * <jsm>assertObject<jsm>(myPojo).asString().is(<js>"foobar"</js>);
- * </p>
- *
- * @return A new fluent string assertion.
- */
- public FluentStringAssertion<R> asString() {
- return new FluentStringAssertion<>(this, value == null ? null :
value.toString(), returns());
- }
-
- /**
- * Converts this object to a string using the specified function and
returns it as a new assertion.
- *
- * <h5 class='section'>Example:</h5>
- * <p class='bcode w800'>
- * <jc>// Validates that the specified object is "foobar" after
converting to a string.</jc>
- *
<jsm>assertObject<jsm>(myPojo).asString(<jv>x</jv>-><jv>x</jv>.toString()).is(<js>"foobar"</js>);
- * </p>
- *
- * @param function The conversion function.
- * @return A new fluent string assertion.
- */
- public FluentStringAssertion<R> asString(Function<Object,String>
function) {
- return new FluentStringAssertion<>(this, function.apply(value),
returns());
- }
-
- /**
- * Converts this object to a string using the specified function and
returns it as a new assertion.
- *
- * <h5 class='section'>Example:</h5>
- * <p class='bcode w800'>
- * <jc>// Validates that the specified object is "foobar" after
converting to a string.</jc>
- *
<jsm>assertObject<jsm>(myPojo).asString(MyBean.<jk>class</jk>,<jv>x</jv>-><jv>x</jv>.myBeanMethod()).is(<js>"foobar"</js>);
- * </p>
- *
- * @param c The class of the object being converted.
- * @param function The conversion function.
- * @param <T> The class of the object being converted.
- * @return A new fluent string assertion.
- */
- @SuppressWarnings("unchecked")
- public <T> FluentStringAssertion<R> asString(Class<T> c,
Function<T,String> function) {
- return new FluentStringAssertion<>(this,
function.apply((T)value), returns());
- }
-
- /**
- * Converts this object to simplified JSON and returns it as a new
assertion.
- *
- * <h5 class='section'>Example:</h5>
- * <p class='bcode w800'>
- * <jc>// Validates that the specified object is an instance of
MyBean.</jc>
- *
<jsm>assertObject<jsm>(myPojo).asJson().is(<js>"{foo:'bar',baz:'qux'}"</js>);
- * </p>
- *
- * @return A new fluent string assertion.
- */
- public FluentStringAssertion<R> asJson() {
- return asString(JSON);
- }
-
- /**
- * Converts this object to sorted simplified JSON and returns it as a
new assertion.
- *
- * <h5 class='section'>Example:</h5>
- * <p class='bcode w800'>
- * <jc>// Validates that the specified object is an instance of
MyBean.</jc>
- *
<jsm>assertObject<jsm>(myPojo).asJsonSorted().is(<js>"{baz:'qux',foo:'bar'}"</js>);
- * </p>
- *
- * @return A new fluent string assertion.
- */
- public FluentStringAssertion<R> asJsonSorted() {
- return asString(JSON_SORTED);
- }
-
- /**
- * Verifies that two objects are equivalent after converting them both
to JSON.
- *
- * @param o The object to compare against.
- * @return The response object (for method chaining).
- * @throws AssertionError If assertion failed.
- */
- public R isSameJsonAs(Object o) throws AssertionError {
- return isSameSerializedAs(o, JSON);
- }
-
- /**
- * Verifies that two objects are equivalent after converting them both
to sorted JSON.
- *
- * <p>
- * Properties, maps, and collections are all sorted on both objects
before comparison.
- *
- * @param o The object to compare against.
- * @return The response object (for method chaining).
- * @throws AssertionError If assertion failed.
- */
- public R isSameSortedAs(Object o) {
- return isSameSerializedAs(o, JSON_SORTED);
- }
-
- /**
- * Asserts that the specified object is the same as this object after
converting both to strings using the specified serializer.
- *
- * @param o The object to compare against.
- * @param serializer The serializer to use to serialize this object.
- * @return The response object (for method chaining).
- * @throws AssertionError If assertion failed.
- */
- public R isSameSerializedAs(Object o, WriterSerializer serializer) {
- try {
- String s1 = serializer.serialize(this.value);
- String s2 = serializer.serialize(o);
- if (! StringUtils.isEquals(s1, s2))
- throw error("Unexpected
comparison.\n\tExpect=[{0}]\n\tActual=[{1}]", s2, s1);
- } catch (SerializeException e) {
- throw new RuntimeException(e);
- }
- return returns();
- }
-
- /**
- * Asserts that the value equals the specified value.
- *
- * @param value The value to check against.
- * @return The response object (for method chaining).
- * @throws AssertionError If assertion failed.
- */
- public R isEqual(Object value) throws AssertionError {
- if (this.value == value)
- return returns();
- exists();
- if (! this.value.equals(equivalent(value)))
- throw error("Unexpected
value.\n\tExpect=[{0}]\n\tActual=[{1}]", value, this.value);
- return returns();
- }
-
- /**
- * Asserts that the value equals the specified value.
- *
- * <p>
- * Equivalent to {@link #isEqual(Object)}.
- *
- * @param value The value to check against.
- * @return The response object (for method chaining).
- * @throws AssertionError If assertion failed.
- */
- public R is(Object value) throws AssertionError {
- return isEqual(equivalent(value));
- }
-
- /**
- * Asserts that the value equals the specified value.
- *
- * @param value The value to check against.
- * @return The response object (for method chaining).
- * @throws AssertionError If assertion failed.
- */
- public R doesNotEqual(Object value) throws AssertionError {
- if (this.value == null && value != null || this.value != null
&& value == null)
- return returns();
- if (this.value == null || this.value.equals(equivalent(value)))
- throw error("Unexpected value.\n\tExpected
not=[{0}]\n\tActual=[{1}]", value, this.value);
- return returns();
- }
-
- /**
- * Asserts that the specified object is the same object as this object.
- *
- * @param value The value to check against.
- * @return The response object (for method chaining).
- * @throws AssertionError If assertion failed.
- */
- public R isSameObjectAs(Object value) throws AssertionError {
- if (this.value == value)
- return returns();
- throw error("Not the same
value.\n\tExpect=[{0}]\n\tActual=[{1}]", value, this.value);
- }
-
- /**
- * Asserts that the value passes the specified predicate test.
- *
- * @param test The predicate to use to test the value.
- * @return The response object (for method chaining).
- * @throws AssertionError If assertion failed.
- */
- public R passes(Predicate<Object> test) throws AssertionError {
- if (! test.test(value))
- throw error("Value did not pass predicate
test.\n\tValue=[{0}]", value);
- return returns();
- }
-
- /**
- * Asserts that the value passes the specified predicate test.
- *
- * @param c The class type of the object being tested.
- * @param <T> The class type of the object being tested.
- * @param test The predicate to use to test the value.
- * @return The response object (for method chaining).
- * @throws AssertionError If assertion failed.
- */
- @SuppressWarnings("unchecked")
- public <T> R passes(Class<T> c, Predicate<T> test) throws
AssertionError {
- isType(c);
- if (! test.test((T)value))
- throw error("Value did not pass predicate
test.\n\tValue=[{0}]", value);
- return returns();
- }
-
- /**
- * Asserts that the object is not null.
- *
- * <p>
- * Equivalent to {@link #isNotNull()}.
- *
- * @return The response object (for method chaining).
- * @throws AssertionError If assertion failed.
- */
- public R exists() throws AssertionError {
- return isNotNull();
- }
-
- /**
- * Asserts that the object is null.
- *
- * <p>
- * Equivalent to {@link #isNotNull()}.
- *
- * @return The response object (for method chaining).
- * @throws AssertionError If assertion failed.
- */
- public R doesNotExist() throws AssertionError {
- return isNull();
- }
-
- /**
- * Asserts that the object is not null.
- *
- * <p>
- * Equivalent to {@link #isNotNull()}.
- *
- * @return The response object (for method chaining).
- * @throws AssertionError If assertion failed.
- */
- public R isNotNull() throws AssertionError {
- if (value == null)
- throw error("Value was null.");
- return returns();
- }
-
- /**
- * Asserts that the object i null.
- *
- * <p>
- * Equivalent to {@link #isNotNull()}.
- *
- * @return The response object (for method chaining).
- * @throws AssertionError If assertion failed.
- */
- public R isNull() throws AssertionError {
- if (value != null)
- throw error("Value was not null.");
- return returns();
- }
-
- /**
- * Asserts that the value equals the specified value.
- *
- * <p>
- * Equivalent to {@link #doesNotEqual(Object)}.
- *
- * @param value The value to check against.
- * @return The response object (for method chaining).
- * @throws AssertionError If assertion failed.
- */
- public R isNot(Object value) throws AssertionError {
- return doesNotEqual(equivalent(value));
- }
-
- /**
- * Asserts that the value is one of the specified values.
- *
- * @param values The values to check against.
- * @return The response object (for method chaining).
- * @throws AssertionError If assertion failed.
- */
- public R isAny(Object...values) throws AssertionError {
- exists();
- for (Object v : values)
- if (this.value.equals(equivalent(v)))
- return returns();
- throw error("Expected value not
found.\n\tExpect=[{0}]\n\tActual=[{1}]", SimpleJson.DEFAULT.toString(values),
value);
- }
-
- /**
- * Asserts that the value is one of the specified values.
- *
- * @param values The values to check against.
- * @return The response object (for method chaining).
- * @throws AssertionError If assertion failed.
- */
- public R isNotAny(Object...values) throws AssertionError {
- exists();
- for (Object v : values)
- if (this.value.equals(equivalent(v)))
- throw error("Unexpected value
found.\n\tUnexpected=[{0}]\n\tActual=[{1}]", v, value);
- return returns();
- }
-
- /**
- * Subclasses can override this method to provide special conversions
on objects being compared.
- *
- * @param o The object to cast.
- * @return The cast object.
- */
- protected Object equivalent(Object o) {
- return o;
- }
-
@SuppressWarnings("unchecked")
private <T> T cast(Class<T> c) throws AssertionError {
Object o = value;
@@ -485,7 +104,7 @@ public class FluentObjectAssertion<R> extends
FluentAssertion<R> {
* @return A new assertion.
* @throws AssertionError If object is not an instance of {@link
Comparable}.
*/
- public FluentComparableAssertion<R> asComparable() {
+ public FluentComparableAssertion<Comparable<?>,R> asComparable() {
return new FluentComparableAssertion<>(this,
cast(Comparable.class), returns());
}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentStringAssertion.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentStringAssertion.java
index 2a29f8d..1438798 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentStringAssertion.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentStringAssertion.java
@@ -36,7 +36,7 @@ import org.apache.juneau.internal.*;
* @param <R> The return type.
*/
@FluentSetters(returns="FluentStringAssertion<R>")
-public class FluentStringAssertion<R> extends FluentObjectAssertion<R> {
+public class FluentStringAssertion<R> extends FluentBaseAssertion<String,R> {
private String text;
private boolean javaStrings;
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentThrowableAssertion.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentThrowableAssertion.java
index 7191936..c791d98 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentThrowableAssertion.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentThrowableAssertion.java
@@ -12,8 +12,6 @@
//
***************************************************************************************************************************
package org.apache.juneau.assertions;
-import java.util.function.*;
-
import org.apache.juneau.internal.*;
/**
@@ -22,7 +20,7 @@ import org.apache.juneau.internal.*;
* @param <R> The return type.
*/
@FluentSetters(returns="FluentThrowableAssertion<R>")
-public class FluentThrowableAssertion<R> extends FluentAssertion<R> {
+public class FluentThrowableAssertion<R> extends
FluentBaseAssertion<Throwable,R> {
private final Throwable value;
@@ -44,7 +42,7 @@ public class FluentThrowableAssertion<R> extends
FluentAssertion<R> {
* @param returns The object to return after the test.
*/
public FluentThrowableAssertion(Assertion creator, Throwable value, R
returns) {
- super(creator, returns);
+ super(creator, value, returns);
this.value = value;
}
@@ -61,6 +59,7 @@ public class FluentThrowableAssertion<R> extends
FluentAssertion<R> {
* @param type The type.
* @return This object (for method chaining).
*/
+ @Override
public R isType(Class<?> type) {
assertNotNull("type", type);
if (! type.isInstance(value))
@@ -126,6 +125,7 @@ public class FluentThrowableAssertion<R> extends
FluentAssertion<R> {
*
* @return This object (for method chaining).
*/
+ @Override
public R exists() {
if (value == null)
throw error("Exception was not thrown.");
@@ -143,6 +143,7 @@ public class FluentThrowableAssertion<R> extends
FluentAssertion<R> {
*
* @return This object (for method chaining).
*/
+ @Override
public R doesNotExist() {
if (value != null)
throw error("Exception was thrown.");
@@ -150,36 +151,6 @@ public class FluentThrowableAssertion<R> extends
FluentAssertion<R> {
}
/**
- * Asserts that the value passes the specified predicate test.
- *
- * @param test The predicate to use to test the value.
- * @return The response object (for method chaining).
- * @throws AssertionError If assertion failed.
- */
- public R passes(Predicate<Throwable> test) throws AssertionError {
- if (! test.test(value))
- throw error("Value did not pass predicate
test.\n\tValue=[{0}]", value);
- return returns();
- }
-
- /**
- * Asserts that the value passes the specified predicate test.
- *
- * @param c The class to cast to for the predicate.
- * @param <T> The class to cast to for the predicate.
- * @param test The predicate to use to test the value.
- * @return The response object (for method chaining).
- * @throws AssertionError If assertion failed.
- */
- @SuppressWarnings("unchecked")
- public <T extends Throwable> R passes(Class<T> c, Predicate<T> test)
throws AssertionError {
- isType(c);
- if (! test.test((T) value))
- throw error("Value did not pass predicate
test.\n\tValue=[{0}]", value);
- return returns();
- }
-
- /**
* Returns an assertion against the throwable message.
*
* <h5 class='section'>Example:</h5>
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentZonedDateTimeAssertion.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentZonedDateTimeAssertion.java
index 2c8380c..c3c1a0d 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentZonedDateTimeAssertion.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentZonedDateTimeAssertion.java
@@ -34,7 +34,7 @@ import org.apache.juneau.internal.*;
* @param <R> The return type.
*/
@FluentSetters(returns="FluentZonedDateTimeAssertion<R>")
-public class FluentZonedDateTimeAssertion<R> extends
FluentComparableAssertion<R> {
+public class FluentZonedDateTimeAssertion<R> extends
FluentComparableAssertion<ZonedDateTime,R> {
private final ZonedDateTime value;
diff --git
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/assertion/FluentResponseHeaderAssertion.java
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/assertion/FluentResponseHeaderAssertion.java
index 35fddcd..2a2c6cc 100644
---
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/assertion/FluentResponseHeaderAssertion.java
+++
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/assertion/FluentResponseHeaderAssertion.java
@@ -22,7 +22,7 @@ import org.apache.juneau.rest.client.*;
* @param <R> The return type.
*/
@FluentSetters(returns="FluentResponseHeaderAssertion<R>")
-public class FluentResponseHeaderAssertion<R> extends FluentStringAssertion<R>
{
+public class FluentResponseHeaderAssertion<R> extends
FluentBaseAssertion<String,R> {
private final ResponseHeader value;
@@ -54,7 +54,6 @@ public class FluentResponseHeaderAssertion<R> extends
FluentStringAssertion<R> {
* @return A new assertion.
* @throws AssertionError If object is not a boolean.
*/
- @Override
public FluentBooleanAssertion<R> asBoolean() {
return new FluentBooleanAssertion<>(this,
value.asBoolean().orElse(null), returns());
}
@@ -65,7 +64,6 @@ public class FluentResponseHeaderAssertion<R> extends
FluentStringAssertion<R> {
* @return A new assertion.
* @throws AssertionError If object is not a date.
*/
- @Override
public FluentDateAssertion<R> asDate() {
return new FluentDateAssertion<>(this,
value.asDateHeader().asDate().orElse(null), returns());
}
@@ -76,7 +74,6 @@ public class FluentResponseHeaderAssertion<R> extends
FluentStringAssertion<R> {
* @return A new assertion.
* @throws AssertionError If object is not an integer.
*/
- @Override
public FluentIntegerAssertion<R> asInteger() {
return new FluentIntegerAssertion<>(this,
value.asInteger().orElse(null), returns());
}
@@ -87,7 +84,6 @@ public class FluentResponseHeaderAssertion<R> extends
FluentStringAssertion<R> {
* @return A new assertion.
* @throws AssertionError If object is not a long.
*/
- @Override
public FluentLongAssertion<R> asLong() {
return new FluentLongAssertion<>(this,
value.asLong().orElse(null), returns());
}
@@ -98,7 +94,6 @@ public class FluentResponseHeaderAssertion<R> extends
FluentStringAssertion<R> {
* @return A new assertion.
* @throws AssertionError If object is not a zoned-datetime.
*/
- @Override
public FluentZonedDateTimeAssertion<R> asZonedDateTime() {
return new FluentZonedDateTimeAssertion<>(this,
value.asDateHeader().asZonedDateTime().orElse(null), returns());
}
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/assertions/FluentRequestHeaderAssertion.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/assertions/FluentRequestHeaderAssertion.java
index bd9c406..30087ce 100644
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/assertions/FluentRequestHeaderAssertion.java
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/assertions/FluentRequestHeaderAssertion.java
@@ -22,7 +22,7 @@ import org.apache.juneau.rest.*;
* @param <R> The return type.
*/
@FluentSetters(returns="FluentRequestHeaderAssertion<R>")
-public class FluentRequestHeaderAssertion<R> extends FluentStringAssertion<R> {
+public class FluentRequestHeaderAssertion<R> extends
FluentBaseAssertion<String,R> {
private final RequestHeader value;
@@ -49,23 +49,11 @@ public class FluentRequestHeaderAssertion<R> extends
FluentStringAssertion<R> {
}
/**
- * Converts this object assertion into a string assertion.
- *
- * @return A new assertion.
- * @throws AssertionError If object is not a string.
- */
- @Override
- public FluentStringAssertion<R> asString() {
- return new FluentStringAssertion<>(this,
value.asString().orElse(null), returns());
- }
-
- /**
* Converts this object assertion into a boolean assertion.
*
* @return A new assertion.
* @throws AssertionError If object is not a boolean.
*/
- @Override
public FluentBooleanAssertion<R> asBoolean() {
return new FluentBooleanAssertion<>(this,
value.asBoolean().orElse(null), returns());
}
@@ -76,7 +64,6 @@ public class FluentRequestHeaderAssertion<R> extends
FluentStringAssertion<R> {
* @return A new assertion.
* @throws AssertionError If object is not a date.
*/
- @Override
public FluentDateAssertion<R> asDate() {
return new FluentDateAssertion<>(this,
value.asDateHeader().asDate().orElse(null), returns());
}
@@ -87,7 +74,6 @@ public class FluentRequestHeaderAssertion<R> extends
FluentStringAssertion<R> {
* @return A new assertion.
* @throws AssertionError If object is not an integer.
*/
- @Override
public FluentIntegerAssertion<R> asInteger() {
return new FluentIntegerAssertion<>(this,
value.asInteger().orElse(null), returns());
}
@@ -98,7 +84,6 @@ public class FluentRequestHeaderAssertion<R> extends
FluentStringAssertion<R> {
* @return A new assertion.
* @throws AssertionError If object is not a long.
*/
- @Override
public FluentLongAssertion<R> asLong() {
return new FluentLongAssertion<>(this,
value.asLong().orElse(null), returns());
}
@@ -109,7 +94,6 @@ public class FluentRequestHeaderAssertion<R> extends
FluentStringAssertion<R> {
* @return A new assertion.
* @throws AssertionError If object is not a zoned-datetime.
*/
- @Override
public FluentZonedDateTimeAssertion<R> asZonedDateTime() {
return new FluentZonedDateTimeAssertion<>(this,
value.asDateHeader().asZonedDateTime().orElse(null), returns());
}
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/assertions/FluentRequestQueryParamAssertion.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/assertions/FluentRequestQueryParamAssertion.java
index 688cabc..f5ee03a 100644
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/assertions/FluentRequestQueryParamAssertion.java
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/assertions/FluentRequestQueryParamAssertion.java
@@ -22,7 +22,7 @@ import org.apache.juneau.rest.*;
* @param <R> The return type.
*/
@FluentSetters(returns="FluentRequestQueryParamAssertion<R>")
-public class FluentRequestQueryParamAssertion<R> extends
FluentStringAssertion<R> {
+public class FluentRequestQueryParamAssertion<R> extends
FluentBaseAssertion<String,R> {
private final RequestQueryParam value;
@@ -54,7 +54,6 @@ public class FluentRequestQueryParamAssertion<R> extends
FluentStringAssertion<R
* @return A new assertion.
* @throws AssertionError If object is not a boolean.
*/
- @Override
public FluentBooleanAssertion<R> asBoolean() {
return new FluentBooleanAssertion<>(this,
value.asBoolean().orElse(null), returns());
}
@@ -65,7 +64,6 @@ public class FluentRequestQueryParamAssertion<R> extends
FluentStringAssertion<R
* @return A new assertion.
* @throws AssertionError If object is not a date.
*/
- @Override
public FluentDateAssertion<R> asDate() {
return new FluentDateAssertion<>(this,
value.asNamedDate().asDate().orElse(null), returns());
}
@@ -76,7 +74,6 @@ public class FluentRequestQueryParamAssertion<R> extends
FluentStringAssertion<R
* @return A new assertion.
* @throws AssertionError If object is not an integer.
*/
- @Override
public FluentIntegerAssertion<R> asInteger() {
return new FluentIntegerAssertion<>(this,
value.asInteger().orElse(null), returns());
}
@@ -87,7 +84,6 @@ public class FluentRequestQueryParamAssertion<R> extends
FluentStringAssertion<R
* @return A new assertion.
* @throws AssertionError If object is not a long.
*/
- @Override
public FluentLongAssertion<R> asLong() {
return new FluentLongAssertion<>(this,
value.asLong().orElse(null), returns());
}
@@ -98,7 +94,6 @@ public class FluentRequestQueryParamAssertion<R> extends
FluentStringAssertion<R
* @return A new assertion.
* @throws AssertionError If object is not a zoned-datetime.
*/
- @Override
public FluentZonedDateTimeAssertion<R> asZonedDateTime() {
return new FluentZonedDateTimeAssertion<>(this,
value.asNamedDate().asZonedDateTime().orElse(null), returns());
}