Skip to content
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

Upgrade to JUnit 5 #75

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

language: java
jdk: openjdk8
dist: xenial

cache:
directories:
Expand Down
26 changes: 19 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,33 @@
</exclusions>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
<version>2.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>1.3</version>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>3.11.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.7.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.7.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.22.0</version>
<version>3.11.0</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@
package com.salesforce.mirus;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;

import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class ByteArrayConverterTest {

private static final byte[] TEST_BYTES = "TEST".getBytes(StandardCharsets.UTF_8);
private ByteArrayConverter byteArrayConverter;

@Before
@BeforeEach
public void setUp() {
byteArrayConverter = new ByteArrayConverter();
byteArrayConverter.configure(new HashMap<>(), false);
Expand Down
52 changes: 28 additions & 24 deletions src/test/java/com/salesforce/mirus/KafkaMonitorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

package com.salesforce.mirus;

import static org.hamcrest.CoreMatchers.hasItem;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.mock;

import com.salesforce.mirus.assignment.RoundRobinTaskAssignor;
Expand All @@ -36,16 +36,16 @@
import org.apache.kafka.common.TopicPartition;
import org.apache.kafka.common.errors.TimeoutException;
import org.apache.kafka.connect.connector.ConnectorContext;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class KafkaMonitorTest {

private KafkaMonitor kafkaMonitor;
private MockConsumer<byte[], byte[]> mockSourceConsumer;
private MockConsumer<byte[], byte[]> mockDestinationConsumer;

@Before
@BeforeEach
public void setUp() {
Map<String, String> properties = getBaseProperties();
SourceConfig config = new SourceConfig(properties);
Expand Down Expand Up @@ -327,22 +327,26 @@ public void shouldAlwaysReplicateWhenCheckingDisabled() {
assertThat(partitions, hasItem(new TopicPartition("topic5", 0)));
}

@Test(expected = IllegalArgumentException.class)
@Test
public void shouldThrowWhenUnsupportedTransformationEncountered() {
Map<String, String> properties = getBaseProperties();
properties.put("transforms", "reroute");
properties.put(
"transforms.reroute.type", "org.apache.kafka.connect.transforms.TimestampRouter");
SourceConfig config = new SourceConfig(properties);
TaskConfigBuilder taskConfigBuilder =
new TaskConfigBuilder(new RoundRobinTaskAssignor(), config);

new KafkaMonitor(
mock(ConnectorContext.class),
config,
mockSourceConsumer,
mockDestinationConsumer,
taskConfigBuilder);
assertThrows(
IllegalArgumentException.class,
() -> {
Map<String, String> properties = getBaseProperties();
properties.put("transforms", "reroute");
properties.put(
"transforms.reroute.type", "org.apache.kafka.connect.transforms.TimestampRouter");
SourceConfig config = new SourceConfig(properties);
TaskConfigBuilder taskConfigBuilder =
new TaskConfigBuilder(new RoundRobinTaskAssignor(), config);

new KafkaMonitor(
mock(ConnectorContext.class),
config,
mockSourceConsumer,
mockDestinationConsumer,
taskConfigBuilder);
});
}

@Test
Expand Down
14 changes: 7 additions & 7 deletions src/test/java/com/salesforce/mirus/MirusSourceConnectorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
package com.salesforce.mirus;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.IsCollectionContaining.hasItem;
import static org.hamcrest.core.IsNot.not;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand All @@ -22,14 +22,14 @@
import java.util.List;
import java.util.Map;
import org.apache.kafka.common.config.ConfigDef;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class MirusSourceConnectorTest {

private MirusSourceConnector mirusSourceConnector;

@Before
@BeforeEach
public void setUp() {
this.mirusSourceConnector = new MirusSourceConnector();
}
Expand All @@ -38,8 +38,8 @@ public void setUp() {
public void testVersionStringIsValid() {
String version = mirusSourceConnector.version();
assertTrue(
String.format("Version %s does not match", version),
version.matches("^\\d+\\.\\d+\\.\\d+.*$"));
version.matches("^\\d+\\.\\d+\\.\\d+.*$"),
String.format("Version %s does not match", version));
}

@Test
Expand Down
12 changes: 5 additions & 7 deletions src/test/java/com/salesforce/mirus/MirusSourceTaskTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@

package com.salesforce.mirus;

import static org.hamcrest.CoreMatchers.hasItems;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThat;

import com.salesforce.mirus.config.SourceConfigDefinition;
import com.salesforce.mirus.config.TaskConfig.ReplayPolicy;
Expand Down Expand Up @@ -44,16 +42,16 @@
import org.apache.kafka.connect.source.SourceRecord;
import org.apache.kafka.connect.source.SourceTaskContext;
import org.apache.kafka.connect.storage.OffsetStorageReader;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class MirusSourceTaskTest {

private static final String TOPIC = "topic1";
private MirusSourceTask mirusSourceTask;
private MockConsumer<byte[], byte[]> mockConsumer;

@Before
@BeforeEach
public void setUp() {
mockConsumer = new MockConsumer<>(OffsetResetStrategy.EARLIEST);
mockConsumer.updatePartitions(
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/com/salesforce/mirus/MirusTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
package com.salesforce.mirus;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;

import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class MirusTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
package com.salesforce.mirus;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;

import java.util.Arrays;
import java.util.List;
Expand All @@ -18,14 +18,14 @@
import org.apache.kafka.clients.consumer.OffsetResetStrategy;
import org.apache.kafka.common.PartitionInfo;
import org.apache.kafka.common.TopicPartition;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class SourcePartitionValidatorTest {

private MockConsumer<byte[], byte[]> mockConsumer;

@Before
@BeforeEach
public void setUp() {
this.mockConsumer = new MockConsumer<>(OffsetResetStrategy.EARLIEST);
List<PartitionInfo> partitionInfoList =
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/com/salesforce/mirus/TaskConfigBuilderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
package com.salesforce.mirus;

import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;

import com.salesforce.mirus.assignment.RoundRobinTaskAssignor;
import com.salesforce.mirus.config.SourceConfig;
Expand All @@ -22,8 +22,8 @@
import java.util.Map;
import org.apache.kafka.common.TopicPartition;
import org.apache.kafka.connect.runtime.ConnectorConfig;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class TaskConfigBuilderTest {

Expand All @@ -35,7 +35,7 @@ private TaskConfigBuilder newBuilder(Map<String, String> properties) {
return new TaskConfigBuilder(new RoundRobinTaskAssignor(), new SourceConfig(properties));
}

@Before
@BeforeEach
public void setUp() {
topicPartitionList = new ArrayList<>();
topicPartitionList.add(new TopicPartition("a", 1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@
package com.salesforce.mirus;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;

import java.util.Arrays;
import java.util.List;
import org.apache.kafka.common.TopicPartition;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class TopicPartitionSerDeTest {

private List<TopicPartition> topicPartitionList;

@Before
@BeforeEach
public void setUp() {
topicPartitionList =
Arrays.asList(new TopicPartition("test", 0), new TopicPartition("test", 1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@
package com.salesforce.mirus.assignment;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;

import java.util.Arrays;
import java.util.List;
import org.apache.kafka.common.TopicPartition;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class RangeTaskAssignorTest {

private SourceTaskAssignor sourceTaskAssignor;

@Before
@BeforeEach
public void setUp() {
sourceTaskAssignor = new RangeTaskAssignor();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@
package com.salesforce.mirus.assignment;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;

import java.util.Arrays;
import java.util.List;
import org.apache.kafka.common.TopicPartition;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class RoundRobinTaskAssignorTest {

private SourceTaskAssignor sourceTaskAssignor;

@Before
@BeforeEach
public void setUp() {
sourceTaskAssignor = new RoundRobinTaskAssignor();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
package com.salesforce.mirus.config;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;

import java.util.Collections;
import java.util.Map;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class MirusConfigTest {

Expand Down
Loading