Skip to content

Commit

Permalink
use junit5 to test all the modules (#957)
Browse files Browse the repository at this point in the history
also:
- bump testcontainers to 1.15.3 (as it can't find old ryuk)
- bump liiklus container in examples
  • Loading branch information
lanwen committed Jul 10, 2021
1 parent 699f4ec commit d3c8213
Show file tree
Hide file tree
Showing 43 changed files with 190 additions and 207 deletions.
5 changes: 0 additions & 5 deletions api/build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
sourceCompatibility = targetCompatibility = 8

test {
useJUnit()
}

dependencies {
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
Expand All @@ -13,6 +9,5 @@ dependencies {

testCompileOnly 'org.projectlombok:lombok'
testAnnotationProcessor 'org.projectlombok:lombok'
testCompile 'junit:junit'
testCompile 'org.assertj:assertj-core'
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
package com.github.bsideup.liiklus.positions;

import lombok.RequiredArgsConstructor;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

import java.util.Arrays;
import java.util.Collection;
import java.util.Optional;

import static org.assertj.core.api.Assertions.assertThat;

@RunWith(Parameterized.class)
@RequiredArgsConstructor
public class GroupIdTest {
class GroupIdTest {

@Parameterized.Parameters(name = "{index}: {0}")
public static Collection<Object[]> data() {
static Collection<Object[]> data() {
return Arrays.asList(new Object[][]{
{"hello", GroupId.of("hello", Optional.empty())},
{"hello-", GroupId.of("hello-", Optional.empty())},
Expand All @@ -33,17 +30,15 @@ public static Collection<Object[]> data() {
});
}

final String string;

final GroupId object;

@Test
public void testParsing() {
@ParameterizedTest
@MethodSource("data")
void testParsing(String string, GroupId object) {
assertThat(GroupId.ofString(string)).isEqualTo(object);
}

@Test
public void testStringRepresentation() {
@ParameterizedTest
@MethodSource("data")
void testStringRepresentation(String string, GroupId object) {
assertThat(object.asString()).isEqualTo(string);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.github.bsideup.liiklus.positions;

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

import java.util.Optional;

Expand All @@ -9,14 +9,14 @@
public class GroupIdValidationTest {

@Test
public void testWrongExplicitVersion() {
void testWrongExplicitVersion() {
assertThatThrownBy(
() -> GroupId.of("test", -1)
).isInstanceOf(IllegalArgumentException.class);
}

@Test
public void testWrongExplicitOptionalVersion() {
void testWrongExplicitOptionalVersion() {
assertThatThrownBy(
() -> GroupId.of("test", Optional.of(-1))
).isInstanceOf(IllegalArgumentException.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.github.bsideup.liiklus.records;

import org.assertj.core.data.MapEntry;
import org.junit.Test;
import org.junit.experimental.runners.Enclosed;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;

import java.util.Map;
import java.util.UUID;
Expand All @@ -16,13 +15,12 @@
/**
* See <a href="https://github.com/cloudevents/spec/blob/v1.0/kafka-protocol-binding.md">Kafka Protocol Binding</a>
*/
@RunWith(Enclosed.class)
public class LiiklusCloudEventTest {

public static class Attributes {
class LiiklusCloudEventTest {

@Nested
class Attributes {
@Test
public void serialization() {
void serialization() {
LiiklusCloudEvent event = newBuilder()
.mediaType("text/plain")
.build();
Expand All @@ -37,7 +35,7 @@ public void serialization() {
}

@Test
public void deserialization() {
void deserialization() {
String id = UUID.randomUUID().toString();
Map<String, String> headers = Stream.of(
entry("ce_specversion", "1.0"),
Expand All @@ -57,10 +55,11 @@ public void deserialization() {
}
}

public static class Extensions {
@Nested
class Extensions {

@Test
public void serialization() {
void serialization() {
LiiklusCloudEvent event = newBuilder()
.rawExtension("comexamplefoo", "foo")
.rawExtension("comexamplebar", "bar")
Expand All @@ -73,7 +72,7 @@ public void serialization() {
}

@Test
public void deserialization() {
void deserialization() {
String id = UUID.randomUUID().toString();
Map<String, String> headers = Stream.of(
entry("ce_specversion", "1.0"),
Expand Down
4 changes: 0 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
apply plugin: 'org.springframework.boot'

test {
useJUnit()
}

jar {
enabled = true
}
Expand Down
24 changes: 13 additions & 11 deletions app/src/test/java/com/github/bsideup/liiklus/AckTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import com.github.bsideup.liiklus.protocol.*;
import com.github.bsideup.liiklus.test.AbstractIntegrationTest;
import com.google.protobuf.ByteString;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Flux;

import java.lang.reflect.Method;
import java.time.Duration;
import java.util.HashMap;
import java.util.Map;
Expand All @@ -16,15 +18,15 @@

import static org.assertj.core.api.Assertions.assertThat;

public class AckTest extends AbstractIntegrationTest {
class AckTest extends AbstractIntegrationTest {

SubscribeRequest subscribeRequest;

@Before
public void setUpAckTest() throws Exception {
@BeforeEach
void setUpAckTest(TestInfo info) throws Exception {
subscribeRequest = SubscribeRequest.newBuilder()
.setTopic(testName.getMethodName())
.setGroup(testName.getMethodName())
.setTopic(info.getTestMethod().map(Method::getName).orElse("unknown"))
.setGroup(info.getTestMethod().map(Method::getName).orElse("unknown"))
.setAutoOffsetReset(SubscribeRequest.AutoOffsetReset.EARLIEST)
.build();

Expand All @@ -40,7 +42,7 @@ public void setUpAckTest() throws Exception {
}

@Test
public void testManualAck() throws Exception {
void testManualAck() throws Exception {
Integer partition = stub.subscribe(subscribeRequest)
.take(1)
.delayUntil(it -> {
Expand Down Expand Up @@ -73,7 +75,7 @@ public void testManualAck() throws Exception {
}

@Test
public void testStatelessAck() throws Exception {
void testStatelessAck() throws Exception {
int partition = 1;
int groupVersion = 1;
AckRequest ackRequest = AckRequest.newBuilder()
Expand Down Expand Up @@ -103,7 +105,7 @@ public void testStatelessAck() throws Exception {
}

@Test
public void testAlwaysLatest() throws Exception {
void testAlwaysLatest() throws Exception {
Integer partition = stub.subscribe(subscribeRequest)
.map(SubscribeReply::getAssignment)
.delayUntil(new Function<>() {
Expand Down Expand Up @@ -135,7 +137,7 @@ public Publisher<?> apply(Assignment assignment) {
}

@Test
public void testInterruption() throws Exception {
void testInterruption() throws Exception {
String key = "some key";
int partition = getPartitionByKey(key);
ByteString keyBytes = ByteString.copyFromUtf8(key);
Expand Down
18 changes: 10 additions & 8 deletions app/src/test/java/com/github/bsideup/liiklus/CloudEventsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
import com.github.bsideup.liiklus.records.LiiklusCloudEvent;
import com.github.bsideup.liiklus.test.AbstractIntegrationTest;
import com.google.protobuf.ByteString;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
import reactor.core.publisher.SignalType;

import java.io.IOException;
import java.lang.reflect.Method;
import java.nio.ByteBuffer;
import java.time.Duration;
import java.util.Collections;
Expand All @@ -21,12 +23,12 @@

import static org.assertj.core.api.Assertions.assertThat;

public class CloudEventsTest extends AbstractIntegrationTest {
class CloudEventsTest extends AbstractIntegrationTest {

private static final ObjectMapper MAPPER = new ObjectMapper();

@Before
public void setUpCloudEventsTest() throws Exception {
@BeforeEach
void setUpCloudEventsTest() throws Exception {
processorPluginMock.getPreProcessors().add(envelope -> {
var rawValue = envelope.getRawValue();

Expand Down Expand Up @@ -61,10 +63,10 @@ public void setUpCloudEventsTest() throws Exception {
}

@Test
public void shouldSupportLegacyFormat() throws Exception {
void shouldSupportLegacyFormat(TestInfo info) throws Exception {
var subscribeAction = SubscribeRequest.newBuilder()
.setTopic(testName.getMethodName())
.setGroup(testName.getMethodName())
.setTopic(info.getTestMethod().map(Method::getName).orElse("unknown"))
.setGroup(info.getTestMethod().map(Method::getName).orElse("unknown"))
.setAutoOffsetReset(SubscribeRequest.AutoOffsetReset.EARLIEST)
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,26 @@
import com.github.bsideup.liiklus.protocol.SubscribeRequest;
import com.github.bsideup.liiklus.test.AbstractIntegrationTest;
import com.google.protobuf.ByteString;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
import reactor.core.publisher.Flux;

import java.lang.reflect.Method;
import java.time.Duration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;

public class ConsumerGroupsTest extends AbstractIntegrationTest {
class ConsumerGroupsTest extends AbstractIntegrationTest {

SubscribeRequest subscribeRequest;

@Before
public void setUpConsumerGroupsTest() throws Exception {
@BeforeEach
void setUpConsumerGroupsTest(TestInfo info) throws Exception {
subscribeRequest = SubscribeRequest.newBuilder()
.setTopic(testName.getMethodName())
.setGroup(testName.getMethodName())
.setTopic(info.getTestMethod().map(Method::getName).orElse("unknown"))
.setGroup(info.getTestMethod().map(Method::getName).orElse("unknown"))
.setAutoOffsetReset(SubscribeRequest.AutoOffsetReset.EARLIEST)
.build();

Expand All @@ -40,7 +42,7 @@ public void setUpConsumerGroupsTest() throws Exception {
}

@Test
public void testConsumerGroups() {
void testConsumerGroups() {
Flux
.merge(
stub.subscribe(subscribeRequest),
Expand Down
18 changes: 10 additions & 8 deletions app/src/test/java/com/github/bsideup/liiklus/EndOffsetsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,26 @@
import com.github.bsideup.liiklus.protocol.PublishRequest;
import com.github.bsideup.liiklus.test.AbstractIntegrationTest;
import com.google.protobuf.ByteString;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;

import java.lang.reflect.Method;
import java.util.UUID;

import static org.assertj.core.api.Assertions.assertThat;

public class EndOffsetsTest extends AbstractIntegrationTest {
class EndOffsetsTest extends AbstractIntegrationTest {

private String topic;

@Before
public final void setUpEndOffsetsTest() {
topic = testName.getMethodName();
@BeforeEach
final void setUpEndOffsetsTest(TestInfo info) {
topic = info.getTestMethod().map(Method::getName).orElse("unknown");
}

@Test
public void testEndOffsets() {
void testEndOffsets() {
for (int partition = 0; partition < NUM_PARTITIONS; partition++) {
for (int i = 0; i < partition + 1; i++) {
stub.publish(PublishRequest.newBuilder()
Expand All @@ -45,7 +47,7 @@ public void testEndOffsets() {
}

@Test
public void testEndOffsets_unknownTopic() {
void testEndOffsets_unknownTopic() {
var randomTopic = UUID.randomUUID().toString();
var reply = stub.getEndOffsets(GetEndOffsetsRequest.newBuilder().setTopic(randomTopic).build()).block();

Expand Down
Loading

0 comments on commit d3c8213

Please sign in to comment.