KAFKA-12172 Migrate streams:examples module to JUnit 5 (#9857)

This PR includes following changes.
1. replace org.junit.Assert by org.junit.jupiter.api.Assertions
2. replace org.junit by org.junit.jupiter.api
3. replace Before by BeforeEach
4. replace After by AfterEach

Reviewers: Ismael Juma <ismael@confluent.io>
This commit is contained in:
Chia-Ping Tsai 2021-01-13 21:02:13 +08:00 committed by GitHub
parent 474ad1eebd
commit bed4c6a33b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 19 additions and 19 deletions

View File

@ -241,7 +241,7 @@ subprojects {
} }
} }
def shouldUseJUnit5 = ["tools", "raft", "log4j-appender"].contains(it.project.name) def shouldUseJUnit5 = ["tools", "raft", "log4j-appender", "examples"].contains(it.project.name)
def testLoggingEvents = ["passed", "skipped", "failed"] def testLoggingEvents = ["passed", "skipped", "failed"]
def testShowStandardStreams = false def testShowStandardStreams = false
def testExceptionFormat = 'full' def testExceptionFormat = 'full'
@ -1527,8 +1527,8 @@ project(':streams:examples') {
testCompile project(':streams:test-utils') testCompile project(':streams:test-utils')
testCompile project(':clients').sourceSets.test.output // for org.apache.kafka.test.IntegrationTest testCompile project(':clients').sourceSets.test.output // for org.apache.kafka.test.IntegrationTest
testCompile libs.junitJupiterApi testCompile libs.junitJupiter
testCompile libs.junitVintageEngine testCompile libs.hamcrest
} }
javadoc { javadoc {

View File

@ -32,9 +32,9 @@ import org.apache.kafka.streams.processor.api.Record;
import org.apache.kafka.streams.state.KeyValueIterator; import org.apache.kafka.streams.state.KeyValueIterator;
import org.apache.kafka.streams.state.KeyValueStore; import org.apache.kafka.streams.state.KeyValueStore;
import org.apache.kafka.streams.state.Stores; import org.apache.kafka.streams.state.Stores;
import org.junit.After; import org.junit.jupiter.api.AfterEach;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.time.Duration; import java.time.Duration;
import java.time.Instant; import java.time.Instant;
@ -57,7 +57,7 @@ public class DeveloperGuideTesting {
private Serde<String> stringSerde = new Serdes.StringSerde(); private Serde<String> stringSerde = new Serdes.StringSerde();
private Serde<Long> longSerde = new Serdes.LongSerde(); private Serde<Long> longSerde = new Serdes.LongSerde();
@Before @BeforeEach
public void setup() { public void setup() {
final Topology topology = new Topology(); final Topology topology = new Topology();
topology.addSource("sourceProcessor", "input-topic"); topology.addSource("sourceProcessor", "input-topic");
@ -85,7 +85,7 @@ public class DeveloperGuideTesting {
store.put("a", 21L); store.put("a", 21L);
} }
@After @AfterEach
public void tearDown() { public void tearDown() {
testDriver.close(); testDriver.close();
} }

View File

@ -26,9 +26,9 @@ import org.apache.kafka.streams.TopologyTestDriver;
import org.apache.kafka.streams.TestInputTopic; import org.apache.kafka.streams.TestInputTopic;
import org.apache.kafka.streams.TestOutputTopic; import org.apache.kafka.streams.TestOutputTopic;
import org.apache.kafka.test.TestUtils; import org.apache.kafka.test.TestUtils;
import org.junit.After; import org.junit.jupiter.api.AfterEach;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -52,7 +52,7 @@ public class WordCountDemoTest {
private TestInputTopic<String, String> inputTopic; private TestInputTopic<String, String> inputTopic;
private TestOutputTopic<String, Long> outputTopic; private TestOutputTopic<String, Long> outputTopic;
@Before @BeforeEach
public void setup() throws IOException { public void setup() throws IOException {
final StreamsBuilder builder = new StreamsBuilder(); final StreamsBuilder builder = new StreamsBuilder();
//Create Actual Stream Processing pipeline //Create Actual Stream Processing pipeline
@ -62,7 +62,7 @@ public class WordCountDemoTest {
outputTopic = testDriver.createOutputTopic(WordCountDemo.OUTPUT_TOPIC, new StringDeserializer(), new LongDeserializer()); outputTopic = testDriver.createOutputTopic(WordCountDemo.OUTPUT_TOPIC, new StringDeserializer(), new LongDeserializer());
} }
@After @AfterEach
public void tearDown() { public void tearDown() {
try { try {
testDriver.close(); testDriver.close();

View File

@ -22,14 +22,14 @@ import org.apache.kafka.streams.processor.api.Processor;
import org.apache.kafka.streams.processor.api.Record; import org.apache.kafka.streams.processor.api.Record;
import org.apache.kafka.streams.state.KeyValueStore; import org.apache.kafka.streams.state.KeyValueStore;
import org.apache.kafka.streams.state.Stores; import org.apache.kafka.streams.state.Stores;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
/** /**
* Demonstrate the use of {@link MockProcessorContext} for testing the {@link Processor} in the {@link WordCountProcessorDemo}. * Demonstrate the use of {@link MockProcessorContext} for testing the {@link Processor} in the {@link WordCountProcessorDemo}.

View File

@ -21,13 +21,13 @@ import org.apache.kafka.streams.kstream.Transformer;
import org.apache.kafka.streams.processor.MockProcessorContext; import org.apache.kafka.streams.processor.MockProcessorContext;
import org.apache.kafka.streams.processor.StateStore; import org.apache.kafka.streams.processor.StateStore;
import org.apache.kafka.streams.state.StoreBuilder; import org.apache.kafka.streams.state.StoreBuilder;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.util.Iterator; import java.util.Iterator;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
/** /**
* Demonstrate the use of {@link MockProcessorContext} for testing the {@link Transformer} in the {@link WordCountTransformerDemo}. * Demonstrate the use of {@link MockProcessorContext} for testing the {@link Transformer} in the {@link WordCountTransformerDemo}.