-
Notifications
You must be signed in to change notification settings - Fork 1.7k
GH-3873: Deprecate JUnit 4 utilities in the project #3878
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
2da4d5d
077adbe
c8839a5
6fe5470
53a7686
7ea24ac
f48c8cd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,8 +56,7 @@ If this is not possible for some reason, note that the `consumeFromEmbeddedTopic | |
| Since it does not have access to the consumer properties, you must use the overloaded method that takes a `seekToEnd` boolean parameter to seek to the end instead of the beginning. | ||
| ==== | ||
|
|
||
| NOTE: The `EmbeddedKafkaRule` JUnit 4 rule has been removed in version 4.0. | ||
| For JUnit 4, you should use the `EmbeddedKafkaKraftBroker` directly or migrate to JUnit 5 with the `@EmbeddedKafka` annotation. | ||
| NOTE: `Spring Kafka` no longer supports JUnit4. Please consider migrating from JUnit4 to JUnit5. | ||
|
||
|
|
||
| The `EmbeddedKafkaBroker` class has a utility method that lets you consume for all the topics it created. | ||
| The following example shows how to use it: | ||
|
|
@@ -121,15 +120,19 @@ The following example configuration creates topics called `cat` and `hat` with f | |
|
|
||
| [source, java] | ||
| ---- | ||
| @SpringJUnitConfig | ||
| @EmbeddedKafka( | ||
| partitions = 5, | ||
|
||
| topics = {"cat", "hat"} | ||
| ) | ||
| public class MyTests { | ||
|
|
||
| @ClassRule | ||
| private static EmbeddedKafkaRule embeddedKafka = new EmbeddedKafkaRule(1, false, 5, "cat", "hat"); | ||
| @Autowired | ||
| private EmbeddedKafkaBroker broker; | ||
|
|
||
| @Test | ||
| public void test() { | ||
| embeddedKafkaRule.getEmbeddedKafka() | ||
| .addTopics(new NewTopic("thing1", 10, (short) 1), new NewTopic("thing2", 15, (short) 1)); | ||
| broker.addTopics(new NewTopic("thing1", 10, (short) 1), new NewTopic("thing2", 15, (short) 1)); | ||
| ... | ||
| } | ||
|
|
||
|
|
@@ -225,7 +228,7 @@ The following example shows how to use it: | |
|
|
||
| [source, java] | ||
| ---- | ||
| @RunWith(SpringRunner.class) | ||
| @SpringJUnitConfig | ||
| @DirtiesContext | ||
| @EmbeddedKafka(partitions = 1, | ||
| topics = { | ||
|
|
@@ -237,7 +240,7 @@ public class KafkaStreamsTests { | |
| private EmbeddedKafkaBroker embeddedKafka; | ||
|
|
||
| @Test | ||
| public void someTest() { | ||
| void someTest() { | ||
| Map<String, Object> consumerProps = KafkaTestUtils.consumerProps("testGroup", "true", this.embeddedKafka); | ||
| consumerProps.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest"); | ||
| ConsumerFactory<Integer, String> cf = new DefaultKafkaConsumerFactory<>(consumerProps); | ||
|
|
@@ -288,7 +291,7 @@ In addition, the broker properties are loaded from the `broker.properties` class | |
| Property placeholders are resolved for the `brokerPropertiesLocation` URL and for any property placeholders found in the resource. | ||
| Properties defined by `brokerProperties` override properties found in `brokerPropertiesLocation`. | ||
|
|
||
| You can use the `@EmbeddedKafka` annotation with JUnit 4 or JUnit 5. | ||
| You can use the `@EmbeddedKafka` annotation with JUnit 5. | ||
|
|
||
| [[embedded-kafka-junit5]] | ||
| == `@EmbeddedKafka` Annotation with JUnit5 | ||
|
|
@@ -333,7 +336,7 @@ The following example shows how to do so: | |
| ===== | ||
| [source, java] | ||
| ---- | ||
| @RunWith(SpringRunner.class) | ||
| @SpringJUnitConfig | ||
| @SpringBootTest(properties = "spring.autoconfigure.exclude=" | ||
| + "org.springframework.cloud.stream.test.binder.TestSupportBinderAutoConfiguration") | ||
| public class MyApplicationTests { | ||
|
|
@@ -347,37 +350,8 @@ There are several ways to use an embedded broker in a Spring Boot application te | |
|
|
||
| They include: | ||
|
|
||
| * xref:testing.adoc#kafka-testing-junit4-class-rule[JUnit4 Class Rule] | ||
| * xref:testing.adoc#kafka-testing-embeddedkafka-annotation[`@EmbeddedKafka` Annotation or `EmbeddedKafkaBroker` Bean] | ||
|
|
||
| [[kafka-testing-junit4-class-rule]] | ||
| === JUnit4 Class Rule | ||
|
|
||
| The following example shows how to use a JUnit4 class rule to create an embedded broker: | ||
|
|
||
| [source, java] | ||
| ---- | ||
| @RunWith(SpringRunner.class) | ||
| @SpringBootTest | ||
| public class MyApplicationTests { | ||
|
|
||
| @ClassRule | ||
| public static EmbeddedKafkaRule broker = new EmbeddedKafkaRule(1, false, "someTopic") | ||
| .brokerListProperty("spring.kafka.bootstrap-servers"); | ||
|
|
||
| @Autowired | ||
| private KafkaTemplate<String, String> template; | ||
|
|
||
| @Test | ||
| public void test() { | ||
| ... | ||
| } | ||
|
|
||
| } | ||
| ---- | ||
|
|
||
| Notice that, since this is a Spring Boot application, we override the broker list property to set Spring Boot's property. | ||
|
|
||
| [[embedded-broker-with-springjunitconfig-annotations]] | ||
| == `@EmbeddedKafka` with `@SpringJunitConfig` | ||
|
|
||
|
|
@@ -395,7 +369,7 @@ The following example shows how to use an `@EmbeddedKafka` Annotation to create | |
|
|
||
| [source, java] | ||
| ---- | ||
| @RunWith(SpringRunner.class) | ||
| @SpringJUnitConfig | ||
| @EmbeddedKafka(topics = "someTopic", | ||
| bootstrapServersProperty = "spring.kafka.bootstrap-servers") // this is now the default | ||
| public class MyApplicationTests { | ||
|
|
@@ -404,7 +378,7 @@ public class MyApplicationTests { | |
| private KafkaTemplate<String, String> template; | ||
|
|
||
| @Test | ||
| public void test() { | ||
| void test() { | ||
| ... | ||
| } | ||
|
|
||
|
|
||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our rule is
One sentence per line: https://asciidoctor.org/docs/asciidoc-recommended-practices/And another nit-pick.
Since this is a technical documentation it has to be in a business language and impersonal.
Therefore words, like
you,we,pleasehave to be avoided.I know we have a lot like this in our doc, but that doesn't mean that we have to pollute more.