Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit af8b75c

Browse files
authored
Merge pull request #298 from Aiven-Open/jeqo/refactor-use-assertj-only
refactor: use only assertj on tests
2 parents b67ea04 + 3a498fa commit af8b75c

File tree

11 files changed

+555
-720
lines changed

11 files changed

+555
-720
lines changed

build.gradle

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,10 @@ dependencies {
136136
testImplementation "org.slf4j:slf4j-simple:$slf4jVersion"
137137

138138
testImplementation "org.junit.jupiter:junit-jupiter:$junitVersion"
139+
testImplementation 'org.assertj:assertj-core:3.24.2'
139140

140141
testImplementation "io.findify:s3mock_2.11:0.2.6"
141142

142-
testImplementation "org.hamcrest:hamcrest:2.2"
143143
testImplementation "org.mockito:mockito-core:$mockitoVersion"
144144

145145
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junitVersion"
@@ -204,8 +204,6 @@ dependencies {
204204
// Make test utils from 'test' available in 'integration-test'
205205
integrationTestImplementation sourceSets.test.output
206206
integrationTestImplementation "org.awaitility:awaitility:4.2.0"
207-
208-
testImplementation 'org.assertj:assertj-core:3.24.2'
209207
}
210208

211209
checkstyle {

checkstyle/checkstyle.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,5 +338,9 @@
338338
<property name="tagOrder" value="@param, @return, @throws, @deprecated"/>
339339
<property name="target" value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, METHOD_DEF, CTOR_DEF, VARIABLE_DEF"/>
340340
</module>
341+
342+
<module name="ImportControl">
343+
<property name="file" value="${config_loc}/import-control.xml" default="checkstyle/import-control.xml"/>
344+
</module>
341345
</module>
342346
</module>

checkstyle/import-control.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<!DOCTYPE import-control PUBLIC
2+
"-//Checkstyle//DTD ImportControl Configuration 1.4//EN"
3+
"https://checkstyle.org/dtds/import_control_1_4.dtd">
4+
<import-control pkg="io.aiven.kafka.connect">
5+
<disallow class="org\.junit\.jupiter\.api\.Assertions.*" regex="true"/> <!--AssertJ's assertions are preferred-->
6+
<allow pkg=".*" regex="true"/>
7+
</import-control>

src/integration-test/java/io/aiven/kafka/connect/AvroIntegrationTest.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@
6262
import org.testcontainers.junit.jupiter.Container;
6363
import org.testcontainers.junit.jupiter.Testcontainers;
6464

65-
import static org.junit.jupiter.api.Assertions.assertEquals;
66-
import static org.junit.jupiter.api.Assertions.assertTrue;
65+
import static org.assertj.core.api.Assertions.assertThat;
6766

6867
@Testcontainers
6968
public class AvroIntegrationTest implements IntegrationBase {
@@ -159,8 +158,9 @@ void avroOutput(final String avroCodec, final String compression, final TestInfo
159158
getAvroBlobName(topicName, 1, 0, compression),
160159
getAvroBlobName(topicName, 2, 0, compression),
161160
getAvroBlobName(topicName, 3, 0, compression));
161+
162162
for (final String blobName : expectedBlobs) {
163-
assertTrue(testBucketAccessor.doesObjectExist(blobName));
163+
assertThat(testBucketAccessor.doesObjectExist(blobName)).isTrue();
164164
}
165165

166166
final Map<String, List<GenericRecord>> blobContents = new HashMap<>();
@@ -192,7 +192,7 @@ void avroOutput(final String avroCodec, final String compression, final TestInfo
192192
cnt += 1;
193193

194194
final GenericRecord actualRecord = blobContents.get(blobName).get(i);
195-
assertEquals(expectedRecord, actualRecord);
195+
assertThat(actualRecord).isEqualTo(expectedRecord);
196196
}
197197
}
198198
}
@@ -222,8 +222,9 @@ final void jsonlAvroOutputTest(final TestInfo testInfo)
222222
getBlobName(topicName, 1, 0, compression),
223223
getBlobName(topicName, 2, 0, compression),
224224
getBlobName(topicName, 3, 0, compression));
225+
225226
for (final String blobName : expectedBlobs) {
226-
assertTrue(testBucketAccessor.doesObjectExist(blobName));
227+
assertThat(testBucketAccessor.doesObjectExist(blobName)).isTrue();
227228
}
228229

229230
final Map<String, List<String>> blobContents = new HashMap<>();
@@ -240,9 +241,9 @@ final void jsonlAvroOutputTest(final TestInfo testInfo)
240241
cnt += 1;
241242

242243
final String blobName = getBlobName(topicName, partition, 0, "none");
243-
final String actualLine = blobContents.get(blobName).get(i);
244244
final String expectedLine = "{\"value\":" + value + ",\"key\":\"" + key + "\"}";
245-
assertEquals(expectedLine, actualLine);
245+
246+
assertThat(blobContents.get(blobName).get(i)).isEqualTo(expectedLine);
246247
}
247248
}
248249
}

src/integration-test/java/io/aiven/kafka/connect/AvroParquetIntegrationTest.java

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,7 @@
5858
import org.testcontainers.junit.jupiter.Container;
5959
import org.testcontainers.junit.jupiter.Testcontainers;
6060

61-
import static org.junit.jupiter.api.Assertions.assertEquals;
62-
import static org.junit.jupiter.api.Assertions.assertIterableEquals;
63-
import static org.junit.jupiter.api.Assertions.assertNotNull;
64-
import static org.junit.jupiter.api.Assertions.assertNull;
65-
import static org.junit.jupiter.api.Assertions.assertTrue;
61+
import static org.assertj.core.api.Assertions.assertThat;
6662

6763
@Testcontainers
6864
class AvroParquetIntegrationTest implements IntegrationBase {
@@ -170,7 +166,7 @@ final void allOutputFields(@TempDir final Path tmpDir, final TestInfo testInfo)
170166
getBlobName(topicName, 3, 0, compression));
171167
final Map<String, List<GenericRecord>> blobContents = new HashMap<>();
172168
for (final String blobName : expectedBlobs) {
173-
assertTrue(testBucketAccessor.doesObjectExist(blobName));
169+
assertThat(testBucketAccessor.doesObjectExist(blobName)).isTrue();
174170
final var records =
175171
ParquetUtils.readRecords(
176172
tmpDir.resolve(Paths.get(blobName)),
@@ -188,11 +184,13 @@ final void allOutputFields(@TempDir final Path tmpDir, final TestInfo testInfo)
188184
final GenericRecord record = blobContents.get(blobName).get(i);
189185
final var expectedKey = "key-" + cnt;
190186
final var expectedValue = "{\"name\": \"" + name + "\", \"value\": \"" + value + "\"}";
191-
assertEquals(expectedKey, record.get("key").toString());
192-
assertEquals(expectedValue, record.get("value").toString());
193-
assertNotNull(record.get("offset"));
194-
assertNotNull(record.get("timestamp"));
195-
assertNull(record.get("headers"));
187+
188+
assertThat(record.get("key").toString()).isEqualTo(expectedKey);
189+
assertThat(record.get("value").toString()).isEqualTo(expectedValue);
190+
assertThat(record.get("offset")).isNotNull();
191+
assertThat(record.get("timestamp")).isNotNull();
192+
assertThat(record.get("headers")).isNull();
193+
196194
cnt += 1;
197195
}
198196
}
@@ -257,8 +255,10 @@ final void valueComplexType(@TempDir final Path tmpDir, final TestInfo testInfo)
257255
final String blobName = getBlobName(topicName, partition, 0, "none");
258256
final var record = blobContents.get(blobName).get(i);
259257
final var avroRecord = (GenericRecord) record.get("value");
260-
assertEquals(name, avroRecord.get("name").toString());
261-
assertEquals(value, avroRecord.get("value").toString());
258+
259+
assertThat(avroRecord.get("name").toString()).isEqualTo(name);
260+
assertThat(avroRecord.get("value").toString()).isEqualTo(value);
261+
262262
cnt += 1;
263263
}
264264
}
@@ -338,10 +338,9 @@ final void schemaChanged(@TempDir final Path tmpDir, final TestInfo testInfo)
338338
);
339339
blobContents.addAll(records.stream().map(r -> r.get("value").toString()).collect(Collectors.toList()));
340340
}
341-
assertIterableEquals(
342-
expectedRecords.stream().sorted().collect(Collectors.toList()),
343-
blobContents.stream().sorted().collect(Collectors.toList())
344-
);
341+
342+
assertThat(blobContents)
343+
.containsExactlyInAnyOrderElementsOf(expectedRecords);
345344
}
346345

347346
private KafkaProducer<String, GenericRecord> newProducer() {

src/integration-test/java/io/aiven/kafka/connect/IntegrationTest.java

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,7 @@
6565

6666
import static com.amazonaws.SDKGlobalConfiguration.DISABLE_CERT_CHECKING_SYSTEM_PROPERTY;
6767
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
68-
import static org.hamcrest.MatcherAssert.assertThat;
69-
import static org.hamcrest.Matchers.containsInAnyOrder;
70-
import static org.junit.jupiter.api.Assertions.assertEquals;
71-
import static org.junit.jupiter.api.Assertions.assertTrue;
68+
import static org.assertj.core.api.Assertions.assertThat;
7269

7370
@Testcontainers
7471
final class IntegrationTest implements IntegrationBase {
@@ -166,7 +163,7 @@ void basicTest(final String compression, final TestInfo testInfo)
166163
getOldBlobName(topicName, 2, 0, compression),
167164
getOldBlobName(topicName, 3, 0, compression));
168165
for (final String blobName : expectedBlobs) {
169-
assertTrue(testBucketAccessor.doesObjectExist(blobName));
166+
assertThat(testBucketAccessor.doesObjectExist(blobName)).isTrue();
170167
}
171168

172169
final Map<String, List<String>> blobContents = new HashMap<>();
@@ -180,9 +177,8 @@ void basicTest(final String compression, final TestInfo testInfo)
180177

181178
for (final KeyValueMessage msg : new KeyValueGenerator(4, 10, keyGen, valueGen)) {
182179
final String blobName = getOldBlobName(topicName, msg.partition, 0, compression);
183-
final String actualLine = blobContents.get(blobName).get(msg.epoch);
184-
final String expectedLine = msg.key + "," + msg.value;
185-
assertEquals(expectedLine, actualLine);
180+
181+
assertThat(blobContents.get(blobName).get(msg.epoch)).isEqualTo(msg.key + "," + msg.value);
186182
}
187183
}
188184

@@ -234,16 +230,15 @@ void groupByTimestampVariable(final String compression, final TestInfo testInfo)
234230
final List<String> expectedBlobs =
235231
expectedBlobsAndContent.keySet().stream().sorted().collect(Collectors.toList());
236232
for (final String blobName : expectedBlobs) {
237-
assertTrue(testBucketAccessor.doesObjectExist(blobName));
233+
assertThat(testBucketAccessor.doesObjectExist(blobName)).isTrue();
238234
}
239235

240236
for (final String blobName : expectedBlobs) {
241237
final List<String> blobContent =
242238
testBucketAccessor.readAndDecodeLines(blobName, compression, 0, 1).stream()
243239
.map(fields -> String.join(",", fields))
244240
.collect(Collectors.toList());
245-
assertThat(blobContent, containsInAnyOrder(expectedBlobsAndContent.get(blobName)));
246-
241+
assertThat(blobContent).containsExactlyInAnyOrder(expectedBlobsAndContent.get(blobName));
247242
}
248243
}
249244

@@ -300,14 +295,12 @@ void oneFilePerRecordWithPlainValues(final String compression, final TestInfo te
300295

301296

302297
for (final String blobName : expectedBlobs) {
303-
assertTrue(testBucketAccessor.doesObjectExist(blobName));
298+
assertThat(testBucketAccessor.doesObjectExist(blobName)).isTrue();
304299
}
305300

306301
for (final String blobName : expectedBlobsAndContent.keySet()) {
307-
assertEquals(
308-
expectedBlobsAndContent.get(blobName),
309-
testBucketAccessor.readLines(blobName, compression).get(0)
310-
);
302+
assertThat(testBucketAccessor.readLines(blobName, compression).get(0))
303+
.isEqualTo(expectedBlobsAndContent.get(blobName));
311304
}
312305
}
313306

@@ -366,7 +359,7 @@ void groupByKey(final String compression, final TestInfo testInfo)
366359
.collect(Collectors.toList());
367360

368361
for (final String blobName : expectedBlobs) {
369-
assertTrue(testBucketAccessor.doesObjectExist(blobName));
362+
assertThat(testBucketAccessor.doesObjectExist(blobName)).isTrue();
370363
}
371364

372365
for (final String blobName : expectedBlobs) {
@@ -384,7 +377,7 @@ void groupByKey(final String compression, final TestInfo testInfo)
384377
value = lastValuePerKey.get(keyInBlobName);
385378
expectedBlobContent = String.format("%s,%s", keyInBlobName, value);
386379
}
387-
assertEquals(expectedBlobContent, blobContent);
380+
assertThat(blobContent).isEqualTo(expectedBlobContent);
388381
}
389382
}
390383

@@ -428,7 +421,7 @@ void jsonlOutputTest(final TestInfo testInfo) throws ExecutionException, Interru
428421
getNewBlobName(topicName, 2, 0, compression),
429422
getNewBlobName(topicName, 3, 0, compression));
430423
for (final String blobName : expectedBlobs) {
431-
assertTrue(testBucketAccessor.doesObjectExist(blobName));
424+
assertThat(testBucketAccessor.doesObjectExist(blobName)).isTrue();
432425
}
433426

434427
final Map<String, List<String>> blobContents = new HashMap<>();
@@ -445,9 +438,9 @@ void jsonlOutputTest(final TestInfo testInfo) throws ExecutionException, Interru
445438
cnt += 1;
446439

447440
final String blobName = getNewBlobName(topicName, partition, 0, "none");
448-
final String actualLine = blobContents.get(blobName).get(i);
449441
final String expectedLine = "{\"value\":" + value + ",\"key\":\"" + key + "\"}";
450-
assertEquals(expectedLine, actualLine);
442+
443+
assertThat(blobContents.get(blobName).get(i)).isEqualTo(expectedLine);
451444
}
452445
}
453446
}
@@ -497,29 +490,33 @@ void jsonOutput(final TestInfo testInfo) throws ExecutionException, InterruptedE
497490
getNewBlobName(topicName, 2, 0, compression),
498491
getNewBlobName(topicName, 3, 0, compression));
499492
for (final String blobName : expectedBlobs) {
500-
assertTrue(testBucketAccessor.doesObjectExist(blobName));
493+
assertThat(testBucketAccessor.doesObjectExist(blobName)).isTrue();
501494
}
502495

503496
final Map<String, List<String>> blobContents = new HashMap<>();
504497
for (final String blobName : expectedBlobs) {
505498
final List<String> items = new ArrayList<>(testBucketAccessor.readLines(blobName, compression));
506-
assertEquals(numEpochs + 2, items.size());
499+
500+
assertThat(items).hasSize(numEpochs + 2);
501+
507502
blobContents.put(blobName, items);
508503
}
509504

510505
// Each blob must be a JSON array.
511506
for (final KeyValueMessage msg : new KeyValueGenerator(numPartitions, numEpochs, keyGen, valueGen)) {
512507
final String blobName = getNewBlobName(topicName, msg.partition, 0, compression);
513508
final List<String> blobContent = blobContents.get(blobName);
514-
assertEquals("[", blobContent.get(0));
515-
assertEquals("]", blobContent.get(blobContent.size() - 1));
509+
510+
assertThat(blobContent.get(0)).isEqualTo("[");
511+
assertThat(blobContent.get(blobContent.size() - 1)).isEqualTo("]");
512+
516513
final String actualLine = blobContent.get(msg.epoch + 1); // 0 is '['
517514

518515
String expectedLine = "{\"value\":" + msg.value + ",\"key\":\"" + msg.key + "\"}";
519516
if (actualLine.endsWith(",")) {
520517
expectedLine += ",";
521518
}
522-
assertEquals(expectedLine, actualLine);
519+
assertThat(actualLine).isEqualTo(expectedLine);
523520
}
524521
}
525522

0 commit comments

Comments
 (0)