GH-2927: Subclasses for EmbeddedKafkaBroker param
Fixes: #2927 Starting a test without spring context with Embeded Lafka without `kraft` enabled and `EmbeddedKafkaZKBroker` as a test's parameter results in an exception: ``` No ParameterResolver registered for parameter [org.springframework.kafka.test.EmbeddedKafkaZKBroker broker] in method [public void test.SomeTest.test(org.springframework.kafka.test.EmbeddedKafkaZKBroker)]. org.junit.jupiter.api.extension.ParameterResolutionException: No ParameterResolver registered for parameter [org.springframework.kafka.test.EmbeddedKafkaZKBroker broker] in method [public void test.SomeTest.test(org.springframework.kafka.test.EmbeddedKafkaZKBroker)]. ``` For test config: ``` @Test public void test(EmbeddedKafkaZKBroker broker) ``` * Fix `EmbeddedKafkaCondition` to use `EmbeddedKafkaBroker.class.isAssignableFrom(parameterContext.getParameter().getType());` instead of just `parameterContext.getParameter().getType().equals(EmbeddedKafkaBroker.class)`
This commit is contained in:
@@ -54,6 +54,7 @@ import org.springframework.util.StringUtils;
|
||||
* @author Artem Bilan
|
||||
* @author Pawel Lozinski
|
||||
* @author Adrian Chlebosz
|
||||
* @author Michał Padula
|
||||
*
|
||||
* @since 2.3
|
||||
*
|
||||
@@ -72,7 +73,7 @@ public class EmbeddedKafkaCondition implements ExecutionCondition, AfterAllCallb
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return parameterContext.getParameter().getType().equals(EmbeddedKafkaBroker.class);
|
||||
return EmbeddedKafkaBroker.class.isAssignableFrom(parameterContext.getParameter().getType());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,11 +21,14 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.kafka.test.EmbeddedKafkaBroker;
|
||||
import org.springframework.kafka.test.EmbeddedKafkaZKBroker;
|
||||
import org.springframework.kafka.test.context.EmbeddedKafka;
|
||||
import org.springframework.kafka.test.utils.KafkaTestUtils;
|
||||
|
||||
/**
|
||||
* @author Gary Russell
|
||||
* @author Michał Padula
|
||||
*
|
||||
* @since 2.3
|
||||
*
|
||||
*/
|
||||
@@ -41,4 +44,9 @@ public class EmbeddedKafkaConditionTests {
|
||||
assertThat(broker.getPartitionsPerTopic()).isEqualTo(3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolver(EmbeddedKafkaZKBroker broker) {
|
||||
assertThat(broker).isNotNull();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user