Skip to content

Commit

Permalink
Migration to JUnit 5
Browse files Browse the repository at this point in the history
  • Loading branch information
AnatolyPopov committed Mar 7, 2024
1 parent bd059d7 commit aed189c
Show file tree
Hide file tree
Showing 26 changed files with 452 additions and 532 deletions.
8 changes: 7 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,10 @@ dependencies {
implementation "com.google.guava:guava:33.0.0-jre"
implementation "org.slf4j:slf4j-api:$slf4jVersion"

testImplementation "junit:junit:4.13.2"
testImplementation "org.junit.jupiter:junit-jupiter:$jupiterVersion"
testImplementation "org.junit.vintage:junit-vintage-engine:$jupiterVersion"
testImplementation "org.mockito:mockito-core:$mockitoVersion"
testImplementation "org.mockito:mockito-junit-jupiter:$mockitoVersion"
testImplementation "org.apache.kafka:connect-api:$kafkaVersion"
testImplementation "commons-io:commons-io:2.14.0"
testImplementation "org.apache.derby:derby:$derbyVersion"
Expand Down Expand Up @@ -204,6 +206,10 @@ dependencies {
integrationTestImplementation sourceSets.test.output
}

test {
useJUnitPlatform()
}

task integrationTest(type: Test) {
description = 'Runs the integration tests.'
group = 'verification'
Expand Down
10 changes: 5 additions & 5 deletions src/test/java/io/aiven/connect/jdbc/JdbcSourceConnectorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
import io.aiven.connect.jdbc.util.ExpressionBuilder;
import io.aiven.connect.jdbc.util.TableId;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.MockedConstruction;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -55,7 +55,7 @@ public class JdbcSourceConnectorTest {
private EmbeddedDerby db;
private Map<String, String> connProps;

@Before
@BeforeEach
public void setup() {
connector = new JdbcSourceConnector();
db = new EmbeddedDerby();
Expand All @@ -65,7 +65,7 @@ public void setup() {
connProps.put(JdbcSourceConnectorConfig.TOPIC_PREFIX_CONFIG, "test-");
}

@After
@AfterEach
public void tearDown() throws Exception {
db.close();
db.dropDatabase();
Expand Down
34 changes: 22 additions & 12 deletions src/test/java/io/aiven/connect/jdbc/dialect/BaseDialectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.URL;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -64,8 +65,8 @@
import org.junit.runners.Parameterized;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

@RunWith(Parameterized.class)
Expand Down Expand Up @@ -356,7 +357,7 @@ public void bindFieldPrimitiveValues() throws SQLException {
verifyBindField(
++index,
Decimal.schema(0),
new BigDecimal("1.5").setScale(0, BigDecimal.ROUND_HALF_EVEN)
new BigDecimal("1.5").setScale(0, RoundingMode.HALF_EVEN)
).setBigDecimal(index, new BigDecimal(2));
final Calendar utcCalendar = DateTimeUtils.getTimeZoneCalendar(TimeZone.getTimeZone(ZoneOffset.UTC));
verifyBindField(
Expand Down Expand Up @@ -400,22 +401,31 @@ public void bindFieldNull() throws SQLException {
}
}

@Test(expected = ConnectException.class)
public void bindFieldStructUnsupported() throws SQLException {
@Test
public void bindFieldStructUnsupported() {
final Schema structSchema = SchemaBuilder.struct().field("test", Schema.BOOLEAN_SCHEMA).build();
dialect.bindField(mock(PreparedStatement.class), 1, structSchema, new Struct(structSchema));
assertThatThrownBy(() -> dialect.bindField(mock(PreparedStatement.class), 1, structSchema,
new Struct(structSchema)))
.isInstanceOf(ConnectException.class)
.hasMessage("Unsupported source data type: STRUCT");
}

@Test(expected = ConnectException.class)
public void bindFieldArrayUnsupported() throws SQLException {
@Test
public void bindFieldArrayUnsupported() {
final Schema arraySchema = SchemaBuilder.array(Schema.INT8_SCHEMA);
dialect.bindField(mock(PreparedStatement.class), 1, arraySchema, Collections.emptyList());
assertThatThrownBy(
() -> dialect.bindField(mock(PreparedStatement.class), 1, arraySchema, Collections.emptyList()))
.isInstanceOf(ConnectException.class)
.hasMessage("Unsupported source data type: ARRAY");
}

@Test(expected = ConnectException.class)
public void bindFieldMapUnsupported() throws SQLException {
@Test
public void bindFieldMapUnsupported() {
final Schema mapSchema = SchemaBuilder.map(Schema.INT8_SCHEMA, Schema.INT8_SCHEMA);
dialect.bindField(mock(PreparedStatement.class), 1, mapSchema, Collections.emptyMap());
assertThatThrownBy(
() -> dialect.bindField(mock(PreparedStatement.class), 1, mapSchema, Collections.emptyMap()))
.isInstanceOf(ConnectException.class)
.hasMessage("Unsupported source data type: MAP");
}

protected void assertSanitizedUrl(final String url, final String expectedSanitizedUrl) {
Expand All @@ -430,7 +440,7 @@ protected PreparedStatement verifyBindField(final int index, final Schema schema
throws SQLException {
final PreparedStatement statement = mock(PreparedStatement.class);
dialect.bindField(statement, index, schema, value);
return verify(statement, times(1));
return verify(statement);
}

/**
Expand Down
186 changes: 0 additions & 186 deletions src/test/java/io/aiven/connect/jdbc/dialect/BaseDialectTypeTest.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@
import io.aiven.connect.jdbc.config.JdbcConfig;
import io.aiven.connect.jdbc.source.JdbcSourceConnectorConfig;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import static junit.framework.TestCase.assertSame;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.jupiter.api.Assertions.assertSame;

public class DatabaseDialectsTest {

Expand Down Expand Up @@ -104,14 +105,16 @@ public void shouldFindMockDialect() {
assertDialect(MockDatabaseDialect.class, "jdbc:mock:argle");
}

@Test(expected = ConnectException.class)
@Test
public void shouldNotFindDialectForInvalidUrl() {
DatabaseDialects.extractJdbcUrlInfo("jdbc:protocolinvalid;field=value;");
assertThatThrownBy(() -> DatabaseDialects.extractJdbcUrlInfo("jdbc:protocolinvalid;field=value;"))
.isInstanceOf(ConnectException.class);
}

@Test(expected = ConnectException.class)
@Test
public void shouldNotFindDialectForInvalidUrlMissingJdbcPrefix() {
DatabaseDialects.extractJdbcUrlInfo("mysql://Server:port");
assertThatThrownBy(() -> DatabaseDialects.extractJdbcUrlInfo("mysql://Server:port"))
.isInstanceOf(ConnectException.class);
}

private void assertDialect(
Expand Down
Loading

0 comments on commit aed189c

Please sign in to comment.