Skip to content

Add an example showing how to use AutoConfigureRestDocs with WebTestClient #15976

Closed
@jnizet

Description

@jnizet

@AutoConfigureRestDocs used with WebTestClient causes the following NullPointerException:

java.lang.NullPointerException
	at java.util.HashMap.putMapEntries(HashMap.java:501)
	at java.util.HashMap.<init>(HashMap.java:490)
	at org.springframework.restdocs.webtestclient.WebTestClientRestDocumentation.retrieveConfiguration(WebTestClientRestDocumentation.java:143)
	at org.springframework.restdocs.webtestclient.WebTestClientRestDocumentation.lambda$document$0(WebTestClientRestDocumentation.java:80)
	at org.springframework.test.web.reactive.server.DefaultWebTestClient$DefaultBodyContentSpec.lambda$consumeWith$3(DefaultWebTestClient.java:540)
	at org.springframework.test.web.reactive.server.ExchangeResult.assertWithDiagnostics(ExchangeResult.java:197)
	at org.springframework.test.web.reactive.server.DefaultWebTestClient$DefaultBodyContentSpec.consumeWith(DefaultWebTestClient.java:540)
	at com.example.demo.web.UserControllerWithAutoconfigureDocTest.shouldGetUser(UserControllerWithAutoconfigureDocTest.java:31)

Here's a complete minimal test case reproducing the problem: https://github.com/jnizet/webtestclientrestdocsissue

See the failing test, with the complete stack trace, in https://github.com/jnizet/webtestclientrestdocsissue/blob/master/src/test/java/com/example/demo/web/UserControllerWithAutoconfigureDocTest.java

The same test not using REST Docs passes: https://github.com/jnizet/webtestclientrestdocsissue/blob/master/src/test/java/com/example/demo/web/UserControllerTest.java

And the same test using REST docs but configuring it manually also passes: https://github.com/jnizet/webtestclientrestdocsissue/blob/master/src/test/java/com/example/demo/web/UserControllerWithApplicationContextDocTest.java

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions