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 e33122e Assertions tests.
e33122e is described below
commit e33122e31128f42d944a2a62bc085c3e20b64d57
Author: JamesBognar <[email protected]>
AuthorDate: Thu Jul 9 17:08:32 2020 -0400
Assertions tests.
---
.../juneau/assertions/ArrayAssertion_Test.java | 12 ---
.../juneau/assertions/ListAssertion_Test.java | 10 ---
.../juneau/assertions/FluentArrayAssertion.java | 91 +---------------------
.../apache/juneau/assertions/FluentAssertion.java | 9 ---
.../assertions/FluentCollectionAssertion.java | 3 +-
.../juneau/assertions/FluentListAssertion.java | 91 +---------------------
.../juneau/assertions/FluentObjectAssertion.java | 31 +++-----
.../juneau/assertions/FluentStringAssertion.java | 3 +-
.../assertions/FluentThrowableAssertion.java | 3 +-
.../client2/RestResponseStatusLineAssertion.java | 2 +-
10 files changed, 16 insertions(+), 239 deletions(-)
diff --git
a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/assertions/ArrayAssertion_Test.java
b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/assertions/ArrayAssertion_Test.java
index 9d00e3a..a863e0a 100644
---
a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/assertions/ArrayAssertion_Test.java
+++
b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/assertions/ArrayAssertion_Test.java
@@ -15,9 +15,6 @@ package org.apache.juneau.assertions;
import static org.apache.juneau.assertions.Assertions.*;
import static org.junit.runners.MethodSorters.*;
-import java.util.*;
-
-import org.apache.juneau.collections.*;
import org.junit.*;
@FixMethodOrder(NAME_ASCENDING)
@@ -50,15 +47,6 @@ public class ArrayAssertion_Test {
assertArray(null).item(0).doesNotExist();
assertArray(x1).item(0).doesNotExist();
assertArray(x2).item(0).exists();
-
- assertArray(new String[]{"foo"}).stringItem(0).is("foo");
- assertArray(new Date[]{new Date(0)}).dateItem(0).isBeforeNow();
- assertArray(new Integer[]{1}).integerItem(0).is(1);
- assertArray(new Long[]{1l}).longItem(0).is(1l);
- assertArray(new
List[]{AList.of("foo")}).listItem(0).stringItem(0).is("foo");
- assertArray(new
List[]{AList.of("foo")}).collectionItem(0).isSize(1);
-
- assertThrown(()->assertArray(new
Integer[]{1}).listItem(0)).is("Object was not expected type.
Expected=java.util.List, Actual=java.lang.Integer.");
}
@Test
diff --git
a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/assertions/ListAssertion_Test.java
b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/assertions/ListAssertion_Test.java
index e70cb13..46ce35b 100644
---
a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/assertions/ListAssertion_Test.java
+++
b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/assertions/ListAssertion_Test.java
@@ -23,7 +23,6 @@ import org.junit.*;
@FixMethodOrder(NAME_ASCENDING)
public class ListAssertion_Test {
- @SuppressWarnings("unchecked")
@Test
public void a01_basic() throws Exception {
List<String> x1 = AList.of(), x2 = AList.of("a","b");
@@ -51,15 +50,6 @@ public class ListAssertion_Test {
assertList(null).item(0).doesNotExist();
assertList(x1).item(0).doesNotExist();
assertList(x2).item(0).exists();
-
- assertList(AList.of("foo")).stringItem(0).is("foo");
- assertList(AList.of(new Date(0))).dateItem(0).isBeforeNow();
- assertList(AList.of(1)).integerItem(0).is(1);
- assertList(AList.of(1l)).longItem(0).is(1l);
-
assertList(AList.ofa(AList.of("foo"))).listItem(0).stringItem(0).is("foo");
-
assertList(AList.ofa(AList.of("foo"))).collectionItem(0).isSize(1);
-
-
assertThrown(()->assertList(AList.of(1)).listItem(0)).is("Object was not
expected type. Expected=java.util.List, Actual=java.lang.Integer.");
}
@Test
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 aff9e92..a777039 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
@@ -13,7 +13,6 @@
package org.apache.juneau.assertions;
import java.lang.reflect.*;
-import java.util.*;
import org.apache.juneau.internal.*;
@@ -34,7 +33,7 @@ public class FluentArrayAssertion<R> extends
FluentObjectAssertion<R> {
* @param returns The object to return after the test.
*/
public FluentArrayAssertion(Object contents, R returns) {
- this((Assertion)null, contents, returns);
+ this(null, contents, returns);
}
/**
@@ -103,100 +102,12 @@ public class FluentArrayAssertion<R> extends
FluentObjectAssertion<R> {
return new FluentObjectAssertion<>(this, getItem(index),
returns());
}
- /**
- * Returns a string assertion on the item specified at the specified
index.
- *
- * <p>
- * If the array is <jk>null</jk> or the index is out-of-bounds, the
returned assertion is a null assertion
- * (meaning {@link FluentObjectAssertion#exists()} returns
<jk>false</jk>).
- *
- * @param index The index of the item to retrieve from the array.
- * @return A new assertion.
- */
- public FluentStringAssertion<R> stringItem(int index) {
- return new FluentStringAssertion<>(this,
StringUtils.stringify(getItem(index)), returns());
- }
-
- /**
- * Returns a date assertion on the item specified at the specified
index.
- *
- * <p>
- * If the array is <jk>null</jk> or the index is out-of-bounds, the
returned assertion is a null assertion
- * (meaning {@link FluentObjectAssertion#exists()} returns
<jk>false</jk>).
- *
- * @param index The index of the item to retrieve from the array.
- * @return A new assertion.
- */
- public FluentDateAssertion<R> dateItem(int index) {
- return new FluentDateAssertion<>(this, getItem(Date.class,
index), returns());
- }
-
- /**
- * Returns an integer assertion on the item specified at the specified
index.
- *
- * <p>
- * If the array is <jk>null</jk> or the index is out-of-bounds, the
returned assertion is a null assertion
- * (meaning {@link FluentObjectAssertion#exists()} returns
<jk>false</jk>).
- *
- * @param index The index of the item to retrieve from the array.
- * @return A new assertion.
- */
- public FluentIntegerAssertion<R> integerItem(int index) {
- return new FluentIntegerAssertion<>(this,
getItem(Integer.class, index), returns());
- }
-
- /**
- * Returns a long assertion on the item specified at the specified
index.
- *
- * <p>
- * If the array is <jk>null</jk> or the index is out-of-bounds, the
returned assertion is a null assertion
- * (meaning {@link FluentObjectAssertion#exists()} returns
<jk>false</jk>).
- *
- * @param index The index of the item to retrieve from the array.
- * @return A new assertion.
- */
- public FluentLongAssertion<R> longItem(int index) {
- return new FluentLongAssertion<>(this, getItem(Long.class,
index), returns());
- }
-
- /**
- * Returns a list assertion on the item specified at the specified
index.
- *
- * <p>
- * If the array is <jk>null</jk> or the index is out-of-bounds, the
returned assertion is a null assertion
- * (meaning {@link FluentObjectAssertion#exists()} returns
<jk>false</jk>).
- *
- * @param index The index of the item to retrieve from the array.
- * @return A new assertion.
- */
- public FluentListAssertion<R> listItem(int index) {
- return new FluentListAssertion<>(this, getItem(List.class,
index), returns());
- }
-
- /**
- * Returns a collection assertion on the item specified at the
specified index.
- *
- * <p>
- * If the array is <jk>null</jk> or the index is out-of-bounds, the
returned assertion is a null assertion
- * (meaning {@link FluentObjectAssertion#exists()} returns
<jk>false</jk>).
- *
- * @param index The index of the item to retrieve from the array.
- * @return A new assertion.
- */
- public FluentCollectionAssertion<R> collectionItem(int index) {
- return new FluentCollectionAssertion<>(this,
getItem(Collection.class, index), returns());
- }
-
private Object getItem(int index) {
if (value != null && Array.getLength(value) > index)
return Array.get(value, index);
return null;
}
- private <T> T getItem(Class<T> c, int index) {
- return cast(c, getItem(index));
- }
-
// <FluentSetters>
@Override /* GENERATED - Assertion */
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentAssertion.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentAssertion.java
index ef95776..23605a2 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentAssertion.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentAssertion.java
@@ -27,15 +27,6 @@ public abstract class FluentAssertion<R> extends Assertion {
/**
* Constructor.
*
- * @param returns The object to return after the test.
- */
- protected FluentAssertion(R returns) {
- this.returns = returns;
- }
-
- /**
- * Constructor.
- *
* @param creator The assertion that created this assertion.
* @param returns The object to return after the test.
*/
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 474c28d..a7762a5 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
@@ -34,8 +34,7 @@ public class FluentCollectionAssertion<R> extends
FluentObjectAssertion<R> {
* @param returns The object to return after the test.
*/
public FluentCollectionAssertion(Collection contents, R returns) {
- super(contents, returns);
- this.value = contents;
+ this(null, contents, returns);
}
/**
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentListAssertion.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentListAssertion.java
index cbb0d72..12ac159 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentListAssertion.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentListAssertion.java
@@ -34,8 +34,7 @@ public class FluentListAssertion<R> extends
FluentCollectionAssertion<R> {
* @param returns The object to return after the test.
*/
public FluentListAssertion(List contents, R returns) {
- super(contents, returns);
- this.value = contents;
+ this(null, contents, returns);
}
/**
@@ -64,100 +63,12 @@ public class FluentListAssertion<R> extends
FluentCollectionAssertion<R> {
return new FluentObjectAssertion<>(this, getItem(index),
returns());
}
- /**
- * Returns a string assertion on the item specified at the specified
index.
- *
- * <p>
- * If the list is <jk>null</jk> or the index is out-of-bounds, the
returned assertion is a null assertion
- * (meaning {@link FluentObjectAssertion#exists()} returns
<jk>false</jk>).
- *
- * @param index The index of the item to retrieve from the list.
- * @return A new assertion.
- */
- public FluentStringAssertion<R> stringItem(int index) {
- return new FluentStringAssertion<>(this,
StringUtils.stringify(getItem(index)), returns());
- }
-
- /**
- * Returns a date assertion on the item specified at the specified
index.
- *
- * <p>
- * If the list is <jk>null</jk> or the index is out-of-bounds, the
returned assertion is a null assertion
- * (meaning {@link FluentObjectAssertion#exists()} returns
<jk>false</jk>).
- *
- * @param index The index of the item to retrieve from the list.
- * @return A new assertion.
- */
- public FluentDateAssertion<R> dateItem(int index) {
- return new FluentDateAssertion<>(this, getItem(Date.class,
index), returns());
- }
-
- /**
- * Returns an integer assertion on the item specified at the specified
index.
- *
- * <p>
- * If the list is <jk>null</jk> or the index is out-of-bounds, the
returned assertion is a null assertion
- * (meaning {@link FluentObjectAssertion#exists()} returns
<jk>false</jk>).
- *
- * @param index The index of the item to retrieve from the list.
- * @return A new assertion.
- */
- public FluentIntegerAssertion<R> integerItem(int index) {
- return new FluentIntegerAssertion<>(this,
getItem(Integer.class, index), returns());
- }
-
- /**
- * Returns a long assertion on the item specified at the specified
index.
- *
- * <p>
- * If the list is <jk>null</jk> or the index is out-of-bounds, the
returned assertion is a null assertion
- * (meaning {@link FluentObjectAssertion#exists()} returns
<jk>false</jk>).
- *
- * @param index The index of the item to retrieve from the list.
- * @return A new assertion.
- */
- public FluentLongAssertion<R> longItem(int index) {
- return new FluentLongAssertion<>(this, getItem(Long.class,
index), returns());
- }
-
- /**
- * Returns a list assertion on the item specified at the specified
index.
- *
- * <p>
- * If the list is <jk>null</jk> or the index is out-of-bounds, the
returned assertion is a null assertion
- * (meaning {@link FluentObjectAssertion#exists()} returns
<jk>false</jk>).
- *
- * @param index The index of the item to retrieve from the list.
- * @return A new assertion.
- */
- public FluentListAssertion<R> listItem(int index) {
- return new FluentListAssertion<>(this, getItem(List.class,
index), returns());
- }
-
- /**
- * Returns a collection assertion on the item specified at the
specified index.
- *
- * <p>
- * If the list is <jk>null</jk> or the index is out-of-bounds, the
returned assertion is a null assertion
- * (meaning {@link FluentObjectAssertion#exists()} returns
<jk>false</jk>).
- *
- * @param index The index of the item to retrieve from the list.
- * @return A new assertion.
- */
- public FluentCollectionAssertion<R> collectionItem(int index) {
- return new FluentCollectionAssertion<>(this,
getItem(Collection.class, index), returns());
- }
-
private Object getItem(int index) {
if (value != null && value.size() > index)
return value.get(index);
return null;
}
- private <T> T getItem(Class<T> c, int index) {
- return cast(c, getItem(index));
- }
-
// <FluentSetters>
@Override /* GENERATED - Assertion */
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 6c5a3f1..d32509f 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
@@ -30,18 +30,6 @@ public class FluentObjectAssertion<R> extends
FluentAssertion<R> {
private final Object value;
- private static JsonSerializer JSON_BEANCOMPARE = JsonSerializer.create()
- .ssq()
- .keepNullProperties()
- .build();
-
- private static JsonSerializer JSON_BEANCOMPARESORTED =
JsonSerializer.create()
- .ssq()
- .sortCollections()
- .sortMaps()
- .keepNullProperties()
- .build();
-
private static JsonSerializer JSON = JsonSerializer.create()
.ssq()
.build();
@@ -49,29 +37,30 @@ public class FluentObjectAssertion<R> extends
FluentAssertion<R> {
private static JsonSerializer JSON_SORTED = JsonSerializer.create()
.ssq()
.sortProperties()
+ .sortCollections()
+ .sortMaps()
.build();
/**
* Constructor.
*
- * @param o The object being tested.
+ * @param value The object being tested.
* @param returns The object to return after the test.
*/
- public FluentObjectAssertion(Object o, R returns) {
- super(returns);
- this.value = o;
+ public FluentObjectAssertion(Object value, R returns) {
+ this(null, value, returns);
}
/**
* Constructor.
*
* @param creator The assertion that created this assertion.
- * @param o The object being tested.
+ * @param value The object being tested.
* @param returns The object to return after the test.
*/
- public FluentObjectAssertion(Assertion creator, Object o, R returns) {
+ public FluentObjectAssertion(Assertion creator, Object value, R
returns) {
super(creator, returns);
- this.value = o;
+ this.value = value;
}
/**
@@ -154,7 +143,7 @@ public class FluentObjectAssertion<R> extends
FluentAssertion<R> {
* @throws AssertionError If assertion failed.
*/
public R sameAs(Object o) throws AssertionError {
- return sameAsSerialized(o, JSON_BEANCOMPARE);
+ return sameAsSerialized(o, JSON);
}
/**
@@ -165,7 +154,7 @@ public class FluentObjectAssertion<R> extends
FluentAssertion<R> {
* @throws AssertionError If assertion failed.
*/
public R sameAsSorted(Object o) {
- return sameAsSerialized(o, JSON_BEANCOMPARESORTED);
+ return sameAsSerialized(o, JSON_SORTED);
}
/**
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 12c6eb9..135c5c0 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
@@ -48,8 +48,7 @@ public class FluentStringAssertion<R> extends
FluentObjectAssertion<R> {
* @param returns The object to return after the test.
*/
public FluentStringAssertion(String text, R returns) {
- super(text, returns);
- this.text = text;
+ this(null, text, returns);
}
/**
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 c914fc9..0b76594 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
@@ -33,8 +33,7 @@ public class FluentThrowableAssertion<R> extends
FluentAssertion<R> {
* @param returns The object to return after the test.
*/
public FluentThrowableAssertion(Throwable value, R returns) {
- super(returns);
- this.value = value;
+ this(null, value, returns);
}
/**
diff --git
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestResponseStatusLineAssertion.java
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestResponseStatusLineAssertion.java
index e7089ff..3bc26da 100644
---
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestResponseStatusLineAssertion.java
+++
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestResponseStatusLineAssertion.java
@@ -38,7 +38,7 @@ public class RestResponseStatusLineAssertion extends
FluentAssertion<RestRespons
* @param returns The object to return after the test.
*/
public RestResponseStatusLineAssertion(StatusLine statusLine,
RestResponse returns) {
- super(returns);
+ super(null, returns);
this.statusLine = statusLine;
}