Emit Kotlin array literal for single-element @MockBean(types = ...)#1026
Merged
Conversation
…yntax The existing kotlinSingleInnerAnnotation test asserted the buggy behaviour (Java single-element shorthand emitted for Kotlin). Update it to assert the correct array-literal form, and add a Java sibling that confirms Java keeps its shorthand. Without the fix the Kotlin case fails: expected: @MockBean(types = [Foo::class]) actual: @MockBean(types = Foo::class) Refs moderneinc/customer-requests#2435
When UnwrapMockAndSpyBeanContainers merges a one-element container (e.g. @MockBeans(MockBean(Foo::class))) it previously emitted the Java single-element shorthand `types = Foo::class` in both Java and Kotlin output. Kotlin requires an array literal for Array<KClass<*>> attributes, so the rewritten file did not compile. Restrict the shorthand path to Java; let the Kotlin branch handle size==1 by wrapping in K.ListLiteral, matching the existing N>=2 path. Resolves moderneinc/customer-requests#2435
@MockBean(types = ...)
timtebeek
approved these changes
May 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
UnwrapMockAndSpyBeanContainerspreviously emitted the Java single-element annotation-array shorthand (types = Foo::class) when a@MockBeans/@SpyBeanscontainer collapsed to one inner annotation, regardless of source language. Kotlin rejects that shape:The fix restricts the shorthand path to Java and lets the existing Kotlin
K.ListLiteralbranch handlesize == 1. Java output is unchanged.Before / after (Kotlin):
PR Make UnwrapMockAndSpyBeanContainers Kotlin-aware #1023 made the multi-element Kotlin case correct; this PR completes the single-element case.
Resolves moderneinc/customer-requests#2435.
Test plan
kotlinSingleInnerAnnotationto assert the array-literal form — fails without the fix.javaSingleInnerAnnotationKeepsShorthandconfirming Java shorthand is preserved../gradlew test --tests UnwrapMockAndSpyBeanContainersTest— 8/8 pass (3 Java + 5 Kotlin).Scope note
This PR is intentionally narrow to the recipe that produced the reported failure; a broader sweep would be a separate piece of work.