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:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user