diff --git a/kafka/src/test/groovy/docs/producer/fallback/MessageClient.java b/kafka/src/test/groovy/docs/producer/fallback/MessageClient.java index be1c8fcdc..522ada54f 100644 --- a/kafka/src/test/groovy/docs/producer/fallback/MessageClient.java +++ b/kafka/src/test/groovy/docs/producer/fallback/MessageClient.java @@ -2,7 +2,9 @@ import io.micronaut.configuration.kafka.annotation.KafkaClient; import io.micronaut.configuration.kafka.annotation.Topic; +import io.micronaut.context.annotation.Requires; +@Requires(property = "spec.name", value = "MessageClientFallbackSpec") @KafkaClient public interface MessageClient { diff --git a/kafka/src/test/groovy/docs/producer/fallback/MessageClientFallback.java b/kafka/src/test/groovy/docs/producer/fallback/MessageClientFallback.java index 8342c33fa..c8cb79e1b 100644 --- a/kafka/src/test/groovy/docs/producer/fallback/MessageClientFallback.java +++ b/kafka/src/test/groovy/docs/producer/fallback/MessageClientFallback.java @@ -7,6 +7,7 @@ import jakarta.inject.Singleton; // end::imports[] +@Requires(property = "spec.name", value = "MessageClientFallbackSpec") // tag::clazz[] @Requires(property = "kafka.enabled", notEquals = StringUtils.TRUE, defaultValue = StringUtils.TRUE) // <1> @Replaces(MessageClient.class) // <2> diff --git a/kafka/src/test/groovy/docs/producer/fallback/MessageClientFallbackSpec.groovy b/kafka/src/test/groovy/docs/producer/fallback/MessageClientFallbackSpec.groovy new file mode 100644 index 000000000..193320bb3 --- /dev/null +++ b/kafka/src/test/groovy/docs/producer/fallback/MessageClientFallbackSpec.groovy @@ -0,0 +1,30 @@ +package docs.producer.fallback + +import io.micronaut.context.ApplicationContext +import io.micronaut.context.annotation.Property +import io.micronaut.test.extensions.spock.annotation.MicronautTest +import jakarta.inject.Inject +import spock.lang.Specification + +@MicronautTest +@Property(name = "spec.name", value = "MessageClientFallbackSpec") +@Property(name = "kafka.enabled", value = "false") +class MessageClientFallbackSpec extends Specification { + + @Inject + ApplicationContext context + + void "test that context contains the fallback bean"() { + when: + MessageClientFallback bean = context.getBean(MessageClientFallback) + + then: + bean != null + + when: + bean.send('message') + + then: + thrown(UnsupportedOperationException) + } +}