Skip to content

Commit 36a6e8d

Browse files
committed
Change method name bodyNotNull to requiredBody
1 parent 7884aba commit 36a6e8d

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ inline fun <reified T : Any> RestClient.ResponseSpec.body(): T? =
4343
body(object : ParameterizedTypeReference<T>() {})
4444

4545
/**
46-
* Extension for [RestClient.ResponseSpec.body] providing a `bodyNotNull<Foo>()` variant
46+
* Extension for [RestClient.ResponseSpec.body] providing a `requiredBody<Foo>()` variant
4747
* To leverage Kotlin null safety, this extension throws a [NoSuchElementException] if the response body is null.
4848
*/
49-
inline fun <reified T : Any> RestClient.ResponseSpec.bodyNotNull(): T =
49+
inline fun <reified T : Any> RestClient.ResponseSpec.requiredBody(): T =
5050
body(object : ParameterizedTypeReference<T>() {}) ?: throw NoSuchElementException("Response body is null when a non-null type was expected.")
5151

5252
/**

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@ class RestClientExtensionsTests {
4848
}
4949

5050
@Test
51-
fun `ResponseSpec#bodyNotNull with reified type parameters`() {
52-
responseSpec.bodyNotNull<List<Foo>>()
51+
fun `ResponseSpec#requiredBody with reified type parameters`() {
52+
responseSpec.requiredBody<List<Foo>>()
5353
verify { responseSpec.body(object : ParameterizedTypeReference<List<Foo>>() {}) }
5454
}
5555

5656
@Test
57-
fun `ResponseSpec#bodyNotNull with null response throws NoSuchElementException`() {
57+
fun `ResponseSpec#requiredBody with null response throws NoSuchElementException`() {
5858
every { responseSpec.body(any<ParameterizedTypeReference<Foo>>()) } returns null
59-
assertThrows<NoSuchElementException> { responseSpec.bodyNotNull<Foo>() }
59+
assertThrows<NoSuchElementException> { responseSpec.requiredBody<Foo>() }
6060
}
6161

6262
@Test

0 commit comments

Comments
 (0)