Asserting on the payload before converting it

without this change an NPE is thrown instead of a meaningful message

fixes #307
This commit is contained in:
Marcin Grzejszczak
2017-05-26 18:45:53 +02:00
parent 76de9cec36
commit 459448cb27
3 changed files with 22 additions and 1 deletions

View File

@@ -37,7 +37,7 @@ public class ContractVerifierMessage {
public ContractVerifierMessage(Object payload, Map<String, Object> headers) {
this.payload = payload;
if (headers!=null) {
if (headers != null) {
this.headers.putAll(headers);
}
}

View File

@@ -30,6 +30,7 @@ import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.Message;
import org.springframework.util.Assert;
/**
* @author Marcin Grzejszczak
@@ -64,6 +65,7 @@ class ContractVerifierHelper extends ContractVerifierMessaging<Message<?>> {
@Override
protected ContractVerifierMessage convert(Message<?> receive) {
Assert.notNull(receive, "Message must not be null!");
return new ContractVerifierMessage(receive.getPayload(), receive.getHeaders());
}
}

View File

@@ -0,0 +1,19 @@
package org.springframework.cloud.contract.verifier.messaging.stream
import spock.lang.Specification
/**
* @author Marcin Grzejszczak
*/
class ContractVerifierHelperForStreamTest extends Specification {
def 'should throw exception when a null payload was sent'() {
given:
ContractVerifierHelper helper = new ContractVerifierHelper(null)
when:
helper.convert(null)
then:
IllegalArgumentException e = thrown(IllegalArgumentException)
e.message.contains("Message must not be null")
}
}