Add a requiredBody() extension to RestClient.ResponseSpec
Closes gh-32703
This commit is contained in:
committed by
Sébastien Deleuze
parent
3002813598
commit
a662f5e719
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,9 +16,11 @@
|
||||
|
||||
package org.springframework.web.client
|
||||
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import io.mockk.verify
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.assertThrows
|
||||
import org.springframework.core.ParameterizedTypeReference
|
||||
|
||||
/**
|
||||
@@ -45,6 +47,18 @@ class RestClientExtensionsTests {
|
||||
verify { responseSpec.body(object : ParameterizedTypeReference<List<Foo>>() {}) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `ResponseSpec#requiredBody with reified type parameters`() {
|
||||
responseSpec.requiredBody<List<Foo>>()
|
||||
verify { responseSpec.body(object : ParameterizedTypeReference<List<Foo>>() {}) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `ResponseSpec#requiredBody with null response throws NoSuchElementException`() {
|
||||
every { responseSpec.body(any<ParameterizedTypeReference<Foo>>()) } returns null
|
||||
assertThrows<NoSuchElementException> { responseSpec.requiredBody<Foo>() }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `ResponseSpec#toEntity with reified type parameters`() {
|
||||
responseSpec.toEntity<List<Foo>>()
|
||||
|
||||
Reference in New Issue
Block a user