verify() fails if there are failed requests

Normally failed requests fail the test but they're suppressed for some
reason (e.g. in async callback) then verify should still correctly
report the failures.

Closes gh-21799
This commit is contained in:
Rossen Stoyanchev
2019-04-04 16:49:46 -04:00
parent 4be605eb1e
commit ed70978071
3 changed files with 48 additions and 5 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,7 +23,9 @@ import org.junit.Test;
import org.springframework.test.web.client.MockRestServiceServer.MockRestServiceServerBuilder;
import org.springframework.web.client.RestTemplate;
import static org.assertj.core.api.Assertions.*;
import static org.springframework.http.HttpMethod.*;
import static org.springframework.test.web.client.ExpectedCount.*;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.*;
import static org.springframework.test.web.client.response.MockRestResponseCreators.*;
@@ -132,4 +134,25 @@ public class MockRestServiceServerTests {
server.verify();
}
@Test // gh-21799
public void verifyShouldFailIfRequestsFailed() {
MockRestServiceServer server = MockRestServiceServer.bindTo(this.restTemplate).build();
server.expect(once(), requestTo("/remoteurl")).andRespond(withSuccess());
this.restTemplate.postForEntity("/remoteurl", null, String.class);
try {
this.restTemplate.postForEntity("/remoteurl", null, String.class);
}
catch (AssertionError error) {
assertThat(error.getMessage()).startsWith("No further requests expected");
}
try {
server.verify();
fail("Expected verify failure");
}
catch (AssertionError error) {
assertThat(error.getMessage()).startsWith("Some requests did not execute successfully");
}
}
}