|
| 1 | +/* |
| 2 | + * Copyright 2023-2024 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package org.springframework.ai.chat.client |
| 18 | + |
| 19 | +import io.mockk.every |
| 20 | +import io.mockk.mockk |
| 21 | +import io.mockk.verify |
| 22 | +import org.junit.jupiter.api.Test |
| 23 | +import org.springframework.ai.chat.model.ChatResponse |
| 24 | +import org.springframework.core.ParameterizedTypeReference |
| 25 | + |
| 26 | +class ChatClientExtensionsTests { |
| 27 | + |
| 28 | + data class Joke(val setup: String, val punchline: String) |
| 29 | + |
| 30 | + @Test |
| 31 | + fun responseEntity() { |
| 32 | + val crs = mockk<ChatClient.CallResponseSpec>() |
| 33 | + val re = mockk<ResponseEntity<ChatResponse, Joke>>() |
| 34 | + every { crs.responseEntity<Joke>() } returns re |
| 35 | + crs.responseEntity<Joke>() |
| 36 | + verify { crs.responseEntity(object : ParameterizedTypeReference<Joke>() {}) } |
| 37 | + } |
| 38 | + |
| 39 | + @Test |
| 40 | + fun entity() { |
| 41 | + val crs = mockk<ChatClient.CallResponseSpec>() |
| 42 | + val joke = mockk<Joke>() |
| 43 | + every { crs.entity(any<ParameterizedTypeReference<Joke>>()) } returns joke |
| 44 | + crs.entity<Joke>() |
| 45 | + verify { crs.entity(object : ParameterizedTypeReference<Joke>(){}) } |
| 46 | + } |
| 47 | +} |
0 commit comments