Reactive Java
WebTestClient.bindToController
Create a mock HTTP client for a controller without an actual server. Source-reviewed Reactor or WebFlux example, NOT RUN.
Formal Syntax & Structure
java syntaxjava
WebTestClient.bindToController(controller).build()Working Example
Example Snippetjava
package lab;import java.time.Duration;import org.junit.jupiter.api.Test;import org.springframework.test.web.reactive.server.WebTestClient;class BoundaryTest { @Test void httpContractWithoutServer() { var client = WebTestClient.bindToController(new CatalogApplication()) .configureClient().responseTimeout(Duration.ofSeconds(2)).build(); client.get().uri("/items/B1").exchange().expectStatus().isOk() .expectBody().jsonPath("$.stock").isEqualTo(5); client.get().uri("/items/MISSING").exchange().expectStatus().isNotFound(); }}