Skip to content

Commit

Permalink
KAFKA-13066: Replace EasyMock with Mockito for FileStreamSinkConnecto…
Browse files Browse the repository at this point in the history
…rTest (apache#11027)

Reviewers: Ismael Juma <[email protected]>
  • Loading branch information
tang7526 authored Sep 6, 2021
1 parent 89ee72b commit 81667e2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 17 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2467,6 +2467,7 @@ project(':connect:file') {

testImplementation libs.easymock
testImplementation libs.junitJupiter
testImplementation libs.mockitoInline // supports mocking static methods, final classes, etc.

testRuntimeOnly libs.slf4jlog4j
testImplementation project(':clients').sourceSets.test.output
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@
import org.apache.kafka.common.config.ConfigValue;
import org.apache.kafka.connect.connector.ConnectorContext;
import org.apache.kafka.connect.sink.SinkConnector;
import org.easymock.EasyMockSupport;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.mockito.Mockito.mock;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class FileStreamSinkConnectorTest extends EasyMockSupport {
public class FileStreamSinkConnectorTest {

private static final String MULTIPLE_TOPICS = "test1,test2";
private static final String FILENAME = "/afilename";
Expand All @@ -42,7 +42,7 @@ public class FileStreamSinkConnectorTest extends EasyMockSupport {
@BeforeEach
public void setup() {
connector = new FileStreamSinkConnector();
ctx = createMock(ConnectorContext.class);
ctx = mock(ConnectorContext.class);
connector.initialize(ctx);

sinkProperties = new HashMap<>();
Expand All @@ -52,18 +52,14 @@ public void setup() {

@Test
public void testConnectorConfigValidation() {
replayAll();
List<ConfigValue> configValues = connector.config().validate(sinkProperties);
for (ConfigValue val : configValues) {
assertEquals(0, val.errorMessages().size(), "Config property errors: " + val.errorMessages());
}
verifyAll();
}

@Test
public void testSinkTasks() {
replayAll();

connector.start(sinkProperties);
List<Map<String, String>> taskConfigs = connector.taskConfigs(1);
assertEquals(1, taskConfigs.size());
Expand All @@ -74,30 +70,20 @@ public void testSinkTasks() {
for (int i = 0; i < 2; i++) {
assertEquals(FILENAME, taskConfigs.get(0).get(FileStreamSinkConnector.FILE_CONFIG));
}

verifyAll();
}

@Test
public void testSinkTasksStdout() {
replayAll();

sinkProperties.remove(FileStreamSourceConnector.FILE_CONFIG);
connector.start(sinkProperties);
List<Map<String, String>> taskConfigs = connector.taskConfigs(1);
assertEquals(1, taskConfigs.size());
assertNull(taskConfigs.get(0).get(FileStreamSourceConnector.FILE_CONFIG));

verifyAll();
}

@Test
public void testTaskClass() {
replayAll();

connector.start(sinkProperties);
assertEquals(FileStreamSinkTask.class, connector.taskClass());

verifyAll();
}
}

0 comments on commit 81667e2

Please sign in to comment.