Skip to content

Commit c339c39

Browse files
committed
Revert "Add a requiredExchange extension to RestClient"
This reverts commit dcb9383. See spring-projectsgh-34692
1 parent fbaeaf1 commit c339c39

File tree

2 files changed

+3
-36
lines changed

2 files changed

+3
-36
lines changed

spring-web/src/main/kotlin/org/springframework/web/client/RestClientExtensions.kt

+2-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2025 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,8 +18,6 @@ package org.springframework.web.client
1818

1919
import org.springframework.core.ParameterizedTypeReference
2020
import org.springframework.http.ResponseEntity
21-
import org.springframework.web.client.RestClient.RequestHeadersSpec
22-
import org.springframework.web.client.RestClient.RequestHeadersSpec.ExchangeFunction
2321

2422
/**
2523
* Extension for [RestClient.RequestBodySpec.body] providing a `bodyWithType<Foo>(...)` variant
@@ -53,15 +51,6 @@ inline fun <reified T : Any> RestClient.ResponseSpec.body(): T? =
5351
inline fun <reified T : Any> RestClient.ResponseSpec.requiredBody(): T =
5452
body(object : ParameterizedTypeReference<T>() {}) ?: throw NoSuchElementException("Response body is required")
5553

56-
/**
57-
* Extension for [RestClient.RequestHeadersSpec.exchange] providing a `requiredExchange(...)` variant with a
58-
* non-nullable return value.
59-
* @throws NoSuchElementException if there is no response value
60-
* @since 6.2.6
61-
*/
62-
fun <T: Any> RequestHeadersSpec<*>.requiredExchange(exchangeFunction: ExchangeFunction<T>, close: Boolean = true): T =
63-
exchange(exchangeFunction, close) ?: throw NoSuchElementException("Response value is required")
64-
6554
/**
6655
* Extension for [RestClient.ResponseSpec.toEntity] providing a `toEntity<Foo>()` variant
6756
* leveraging Kotlin reified type parameters. This extension is not subject to type
@@ -71,5 +60,4 @@ fun <T: Any> RequestHeadersSpec<*>.requiredExchange(exchangeFunction: ExchangeFu
7160
* @since 6.1
7261
*/
7362
inline fun <reified T : Any> RestClient.ResponseSpec.toEntity(): ResponseEntity<T> =
74-
toEntity(object : ParameterizedTypeReference<T>() {})
75-
63+
toEntity(object : ParameterizedTypeReference<T>() {})

spring-web/src/test/kotlin/org/springframework/web/client/RestClientExtensionsTests.kt

+1-22
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2025 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,12 +19,9 @@ package org.springframework.web.client
1919
import io.mockk.every
2020
import io.mockk.mockk
2121
import io.mockk.verify
22-
import org.assertj.core.api.Assertions.assertThat
2322
import org.junit.jupiter.api.Test
2423
import org.junit.jupiter.api.assertThrows
2524
import org.springframework.core.ParameterizedTypeReference
26-
import org.springframework.http.HttpRequest
27-
import org.springframework.web.client.RestClient.RequestHeadersSpec
2825

2926
/**
3027
* Mock object based tests for [RestClient] Kotlin extensions
@@ -62,24 +59,6 @@ class RestClientExtensionsTests {
6259
assertThrows<NoSuchElementException> { responseSpec.requiredBody<Foo>() }
6360
}
6461

65-
@Test
66-
fun `RequestHeadersSpec#requiredExchange`() {
67-
val foo = Foo()
68-
every { requestBodySpec.exchange(any<RequestHeadersSpec.ExchangeFunction<Foo>>(), any()) } returns foo
69-
val exchangeFunction: (HttpRequest, RequestHeadersSpec.ConvertibleClientHttpResponse) -> Foo? =
70-
{ _, _ -> foo }
71-
val value = requestBodySpec.requiredExchange(exchangeFunction)
72-
assertThat(value).isEqualTo(foo)
73-
}
74-
75-
@Test
76-
fun `RequestHeadersSpec#requiredExchange with null response throws NoSuchElementException`() {
77-
every { requestBodySpec.exchange(any<RequestHeadersSpec.ExchangeFunction<Foo>>(), any()) } returns null
78-
val exchangeFunction: (HttpRequest, RequestHeadersSpec.ConvertibleClientHttpResponse) -> Foo? =
79-
{ _, _ -> null }
80-
assertThrows<NoSuchElementException> { requestBodySpec.requiredExchange(exchangeFunction) }
81-
}
82-
8362
@Test
8463
fun `ResponseSpec#toEntity with reified type parameters`() {
8564
responseSpec.toEntity<List<Foo>>()

0 commit comments

Comments
 (0)