java.lang.IllegalStateException

tip

If you're using boot 1.4.x you need to modify the @springBootTest annotation to @SpringBootTest(classes = DataFlowServerConfiguration.class). 1.3.8 doesn't have this problem as well.

tip

Spring Boot 1.4 changed their annotation system a little. Try using the @SpringBootApplication annotation for better results.


rafael

You have a different solution? A short tip here would help you and many other users who saw this issue last week.

  • I am investigating the option of adding a {{@RestClientTest}} annotation in Spring Boot that would automatically configure a {{RestTemplate}} and {{MockRestServiceServer}}. The default expectation managers throw an exception if you try to add a request after you have validated one, something like: {noformat} java.lang.IllegalStateException: Cannot add more expectations after actual requests are made. at org.springframework.util.Assert.state(Assert.java:392) at org.springframework.test.web.client.AbstractRequestExpectationManager.expectRequest(AbstractRequestExpectationManager.java:60) at org.springframework.test.web.client.MockRestServiceServer.expect(MockRestServiceServer.java:112) at org.springframework.test.web.client.MockRestServiceServer.expect(MockRestServiceServer.java:95) {noformat} There is no way to "reset" the mock server at the end of the test so it looks like the only way to make this work is to create a new server instance per test. My next move was to try to share the builder and simply call build in a {{Before}} annotated method but that does not work either as the builder shares an expectation manager by default, which means that every created server using the same builder share the same expectation manager. Looking at the API, I find it weird that we can both use {{ignoreExpectOrder}} and {{expectationManager}} as those are mutually exclusive. Perhaps removing the latter and creating a fresh expectation manager would help? It also would be nice if a server instance could be reused for multiple tests with a public {{reset}} method that would reset the expectation manager.
    via by Stéphane Nicoll,
  • I am investigating the option of adding a {{@RestClientTest}} annotation in Spring Boot that would automatically configure a {{RestTemplate}} and {{MockRestServiceServer}}. The default expectation managers throw an exception if you try to add a request after you have validated one, something like: {noformat} java.lang.IllegalStateException: Cannot add more expectations after actual requests are made. at org.springframework.util.Assert.state(Assert.java:392) at org.springframework.test.web.client.AbstractRequestExpectationManager.expectRequest(AbstractRequestExpectationManager.java:60) at org.springframework.test.web.client.MockRestServiceServer.expect(MockRestServiceServer.java:112) at org.springframework.test.web.client.MockRestServiceServer.expect(MockRestServiceServer.java:95) {noformat} There is no way to "reset" the mock server at the end of the test so it looks like the only way to make this work is to create a new server instance per test. My next move was to try to share the builder and simply call build in a {{Before}} annotated method but that does not work either as the builder shares an expectation manager by default, which means that every created server using the same builder share the same expectation manager. Looking at the API, I find it weird that we can both use {{ignoreExpectOrder}} and {{expectationManager}} as those are mutually exclusive. Perhaps removing the latter and creating a fresh expectation manager would help? It also would be nice if a server instance could be reused for multiple tests with a public {{reset}} method that would reset the expectation manager.
    via by Stéphane Nicoll,
  • GitHub comment 11#155290898
    via GitHub by artembilan
    ,
    • java.lang.IllegalStateException: Cannot add more expectations after actual requests are made. at org.springframework.util.Assert.state(Assert.java:392) at org.springframework.test.web.client.AbstractRequestExpectationManager.expectRequest(AbstractRequestExpectationManager.java:60) at org.springframework.test.web.client.MockRestServiceServer.expect(MockRestServiceServer.java:112) at org.springframework.test.web.client.MockRestServiceServer.expect(MockRestServiceServer.java:95)

    Users with the same issue

    tvrmsmith
    22 times, last one,
    bernardpaulus
    18 times, last one,
    Dunmer
    1 times, last one,
    SteVio1989
    8 times, last one,
    jpvee
    4 times, last one,
    62 more bugmates