Merge branch '2.0.x'
This commit is contained in:
@@ -30,14 +30,21 @@ public class CollectionAssert<ELEMENT> extends IterableAssert<ELEMENT> {
|
||||
isNotNull();
|
||||
isNotEmpty();
|
||||
for (Object anActual : this.actual) {
|
||||
if (anActual == null) {
|
||||
failWithMessageRelatedToRegex(regex, anActual);
|
||||
}
|
||||
String value = anActual.toString();
|
||||
if (!value.matches(regex)) {
|
||||
failWithMessage("The value <%s> doesn't match the regex <%s>", value, regex);
|
||||
failWithMessageRelatedToRegex(regex, value);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
private void failWithMessageRelatedToRegex(String regex, Object value) {
|
||||
failWithMessage("The value <%s> doesn't match the regex <%s>", value, regex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Flattens the collection and checks whether size is greater than or equal to the provided value
|
||||
* @param size - the flattened collection should have size greater than or equal to this value
|
||||
|
||||
@@ -33,6 +33,18 @@ public class CollectionAssertTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_throw_an_exception_when_element_is_null() {
|
||||
Collection collection = collectionWithNulls();
|
||||
|
||||
try {
|
||||
SpringCloudContractAssertions.assertThat(collection).allElementsMatch("[0-9]");
|
||||
Assertions.fail("should throw exception");
|
||||
} catch (AssertionError e) {
|
||||
Assertions.assertThat(e).hasMessageContaining("The value <null> doesn't match the regex <[0-9]>");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_throw_an_exception_when_collection_is_null() {
|
||||
Collection collection = null;
|
||||
@@ -277,6 +289,12 @@ public class CollectionAssertTests {
|
||||
return list;
|
||||
}
|
||||
|
||||
private Collection<String> collectionWithNulls() {
|
||||
List<String> list = new ArrayList<>();
|
||||
list.add(null);
|
||||
return list;
|
||||
}
|
||||
|
||||
private Collection nestedCollection() {
|
||||
List list = new ArrayList<>();
|
||||
List list1 = new ArrayList<>();
|
||||
|
||||
@@ -16,18 +16,16 @@
|
||||
|
||||
package org.springframework.cloud.contract.wiremock;
|
||||
|
||||
import com.github.tomakehurst.wiremock.WireMockServer;
|
||||
import com.github.tomakehurst.wiremock.client.WireMock;
|
||||
import com.github.tomakehurst.wiremock.common.Slf4jNotifier;
|
||||
import com.github.tomakehurst.wiremock.core.Options;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import com.github.tomakehurst.wiremock.WireMockServer;
|
||||
import com.github.tomakehurst.wiremock.client.WireMock;
|
||||
import com.github.tomakehurst.wiremock.common.Slf4jNotifier;
|
||||
import com.github.tomakehurst.wiremock.core.Options;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -43,10 +41,6 @@ import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StreamUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.github.tomakehurst.wiremock.WireMockServer;
|
||||
import com.github.tomakehurst.wiremock.client.WireMock;
|
||||
import com.github.tomakehurst.wiremock.core.Options;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user