Skip to content

Commit 39a116e

Browse files
authored
Merge pull request #783 from stainless-sdks/cameron/output-config-test-fix
fix: update failing test
2 parents b1c37b8 + 3765903 commit 39a116e

File tree

1 file changed

+29
-9
lines changed

1 file changed

+29
-9
lines changed

anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/StructuredMessageCreateParamsTest.kt

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,8 @@ internal class StructuredMessageCreateParamsTest {
280280
checkAllDelegatorWriteFunctionsAreTested(
281281
builderDelegator::class,
282282
builderDelegationTestCases(),
283-
exceptionalTestedFns = listOf("outputFormat"),
283+
// These functions have non-standard delegation and are tested separately below.
284+
exceptionalTestedFns = listOf("outputFormat", "outputConfig"),
284285
nonDelegatingFns = setOf("build", "wrap", "inject"),
285286
)
286287
}
@@ -294,19 +295,38 @@ internal class StructuredMessageCreateParamsTest {
294295
@Test
295296
fun `delegation of outputFormat`() {
296297
// Special unit test case as the delegator method signature does not match that of the
297-
// delegate method.
298+
// delegate method. The deprecated `outputFormat` now calls `outputConfig` and `addBeta`
299+
// internally instead of the delegate's `outputFormat`.
298300
val delegatorTestCase = DelegationWriteTestCase("outputFormat", X::class.java)
299301
val delegatorMethod = findDelegationMethod(builderDelegator, delegatorTestCase)
300-
val mockDelegateTestCase =
301-
DelegationWriteTestCase("outputFormat", betaOutputFormatFromClass(X::class.java))
302-
val mockDelegateMethod = findDelegationMethod(mockBuilderDelegate, mockDelegateTestCase)
303302

303+
@Suppress("DEPRECATION")
304304
delegatorMethod.invoke(builderDelegator, delegatorTestCase.inputValues[0])
305305

306-
// Verify that the corresponding method on the mock delegate was called exactly once.
307-
verify(mockBuilderDelegate, times(1)).apply {
308-
mockDelegateMethod.invoke(mockBuilderDelegate, mockDelegateTestCase.inputValues[0])
309-
}
306+
// Verify that outputConfig and addBeta were called on the mock delegate.
307+
val expectedFormat = betaOutputFormatFromClass(X::class.java)
308+
val expectedOutputConfig = BetaOutputConfig.builder().format(expectedFormat).build()
309+
verify(mockBuilderDelegate, times(1)).outputConfig(expectedOutputConfig)
310+
verify(mockBuilderDelegate, times(1))
311+
.addBeta(AnthropicBeta.of("structured-outputs-2025-12-15"))
312+
verifyNoMoreInteractions(mockBuilderDelegate)
313+
}
314+
315+
@Test
316+
fun `delegation of outputConfig with Class`() {
317+
// Special unit test case for the outputConfig(Class<T>, ...) overload which has
318+
// non-standard delegation behavior similar to outputFormat.
319+
val delegatorTestCase = DelegationWriteTestCase("outputConfig", X::class.java)
320+
val delegatorMethod = findDelegationMethod(builderDelegator, delegatorTestCase)
321+
322+
delegatorMethod.invoke(builderDelegator, delegatorTestCase.inputValues[0])
323+
324+
// Verify that outputConfig and addBeta were called on the mock delegate.
325+
val expectedFormat = betaOutputFormatFromClass(X::class.java)
326+
val expectedOutputConfig = BetaOutputConfig.builder().format(expectedFormat).build()
327+
verify(mockBuilderDelegate, times(1)).outputConfig(expectedOutputConfig)
328+
verify(mockBuilderDelegate, times(1))
329+
.addBeta(AnthropicBeta.of("structured-outputs-2025-12-15"))
310330
verifyNoMoreInteractions(mockBuilderDelegate)
311331
}
312332
}

0 commit comments

Comments
 (0)