Merge branch '2.1.x'

This commit is contained in:
Marcin Grzejszczak
2019-10-02 14:53:58 +02:00
3 changed files with 68 additions and 16 deletions

View File

@@ -179,7 +179,7 @@ public class CollectionAssert<ELEMENT> extends IterableAssert<ELEMENT> {
if (object instanceof Map) {
return counter + ((Map) object).size();
}
else if (object instanceof Iterator) {
if (object instanceof Iterator) {
Iterator iterator = ((Iterator) object);
while (iterator.hasNext()) {
Object next = iterator.next();
@@ -187,10 +187,10 @@ public class CollectionAssert<ELEMENT> extends IterableAssert<ELEMENT> {
}
return counter;
}
else if (object instanceof Collection) {
return flattenedSize(counter, ((Collection) object).iterator());
if (object instanceof Iterable) {
return flattenedSize(counter, ((Iterable) object).iterator());
}
return counter;
return ++counter;
}
private int size(Iterable iterable) {

View File

@@ -17,6 +17,7 @@
package org.springframework.cloud.contract.verifier.assertion;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
@@ -101,7 +102,7 @@ public class CollectionAssertTests {
SpringCloudContractAssertions.assertThat(collection)
.hasFlattenedSizeGreaterThanOrEqualTo(0)
.hasFlattenedSizeGreaterThanOrEqualTo(4);
.hasFlattenedSizeGreaterThanOrEqualTo(7);
}
@Test
@@ -110,12 +111,12 @@ public class CollectionAssertTests {
try {
SpringCloudContractAssertions.assertThat(collection)
.hasFlattenedSizeGreaterThanOrEqualTo(5);
.hasFlattenedSizeGreaterThanOrEqualTo(8);
Assertions.fail("should throw exception");
}
catch (AssertionError e) {
Assertions.assertThat(e).hasMessageContaining(
"The flattened size <4> is not greater or equal to <5>");
"The flattened size <7> is not greater or equal to <8>");
}
}
@@ -139,8 +140,8 @@ public class CollectionAssertTests {
Collection collection = nestedCollection();
SpringCloudContractAssertions.assertThat(collection)
.hasFlattenedSizeLessThanOrEqualTo(5)
.hasFlattenedSizeLessThanOrEqualTo(4);
.hasFlattenedSizeLessThanOrEqualTo(8)
.hasFlattenedSizeLessThanOrEqualTo(7);
}
@Test
@@ -154,7 +155,7 @@ public class CollectionAssertTests {
}
catch (AssertionError e) {
Assertions.assertThat(e).hasMessageContaining(
"The flattened size <4> is not less or equal to <1>");
"The flattened size <7> is not less or equal to <1>");
}
}
@@ -177,8 +178,8 @@ public class CollectionAssertTests {
public void should_not_throw_an_exception_when_flattened_size_is_between_the_provided_sizes() {
Collection collection = nestedCollection();
SpringCloudContractAssertions.assertThat(collection).hasFlattenedSizeBetween(1, 5)
.hasFlattenedSizeBetween(4, 4);
SpringCloudContractAssertions.assertThat(collection).hasFlattenedSizeBetween(1, 8)
.hasFlattenedSizeBetween(7, 7);
}
@Test
@@ -187,12 +188,12 @@ public class CollectionAssertTests {
try {
SpringCloudContractAssertions.assertThat(collection)
.hasFlattenedSizeBetween(5, 7);
.hasFlattenedSizeBetween(8, 9);
Assertions.fail("should throw exception");
}
catch (AssertionError e) {
Assertions.assertThat(e).hasMessageContaining(
"The flattened size <4> is not between <5> and <7>");
"The flattened size <7> is not between <8> and <9>");
}
}
@@ -353,8 +354,8 @@ public class CollectionAssertTests {
}
private Collection nestedCollection() {
List list = new ArrayList<>();
List list1 = new ArrayList<>();
List list = new ArrayList();
List list1 = new ArrayList();
Map<String, String> map1 = new HashMap<>();
map1.put("a", "1");
map1.put("b", "2");
@@ -362,10 +363,14 @@ public class CollectionAssertTests {
List list2 = new ArrayList<>();
Map<String, String> map2 = new HashMap<>();
map2.put("d", "4");
List list3 = new ArrayList();
List innerList = Arrays.asList("A", "B", "C");
list.add(list1);
list.add(list2);
list.add(list3);
list1.add(map1);
list2.add(map2);
list3.add(innerList);
return list;
}

View File

@@ -536,4 +536,51 @@ public class WireMockSnippetTests {
};
}
private OperationRequest requestGetWithQueryParam() {
return new OperationRequest() {
@Override
public byte[] getContent() {
return new byte[0];
}
@Override
public String getContentAsString() {
return "";
}
@Override
public HttpHeaders getHeaders() {
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.add(HttpHeaders.CONTENT_TYPE,
MediaType.APPLICATION_JSON_VALUE);
return httpHeaders;
}
@Override
public HttpMethod getMethod() {
return HttpMethod.GET;
}
@Override
public Parameters getParameters() {
return null;
}
@Override
public Collection<OperationRequestPart> getParts() {
return null;
}
@Override
public URI getUri() {
return URI.create("https://foo/bar?myParam=myValue");
}
@Override
public Collection<RequestCookie> getCookies() {
return Collections.emptySet();
}
};
}
}