Skip to content

Commit

Permalink
Fix null key/value assertions (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
philipp94831 authored Dec 18, 2023
1 parent bb7fecd commit a274470
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2023 bakdata GmbH
* Copyright (c) 2023 bakdata
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand All @@ -24,6 +24,7 @@

package com.bakdata.fluent_kafka_streams_tests;

import java.util.Objects;
import java.util.function.Consumer;
import lombok.RequiredArgsConstructor;
import org.apache.kafka.clients.producer.ProducerRecord;
Expand Down Expand Up @@ -57,7 +58,7 @@ public Expectation<K, V> isPresent() {
*/
public Expectation<K, V> hasKey(final K expectedKey) {
this.isPresent();
if (!this.lastRecord.key().equals(expectedKey)) {
if (!Objects.equals(this.lastRecord.key(), expectedKey)) {
throw new AssertionError("Record key does not match");
}
return this.and();
Expand All @@ -83,7 +84,7 @@ public Expectation<K, V> hasKeySatisfying(final Consumer<? super K> requirements
*/
public Expectation<K, V> hasValue(final V expectedValue) {
this.isPresent();
if (!this.lastRecord.value().equals(expectedValue)) {
if (!Objects.equals(this.lastRecord.value(), expectedValue)) {
throw new AssertionError("Record value does not match");
}
return this.and();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* The MIT License
* MIT License
*
* Copyright (c) 2022 bakdata GmbH
* Copyright (c) 2023 bakdata
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -82,4 +82,24 @@ void shouldUseKeyTypes() {
.expectNextRecord().hasKey(new City("City1", 2)).hasValue(new City("City1", 2))
.expectNoMoreRecord();
}

@Test
void shouldVerifyNullKeys() {
this.testTopology.input()
.add(null, new City("City1", 2));

this.testTopology.streamOutput()
.expectNextRecord().hasKey(null).hasValue(new City("City1", 2))
.expectNoMoreRecord();
}

@Test
void shouldVerifyNullValues() {
this.testTopology.input()
.add(new Person("Huey", "City1"), null);

this.testTopology.streamOutput()
.expectNextRecord().hasKey(new Person("Huey", "City1")).hasValue(null)
.expectNoMoreRecord();
}
}

0 comments on commit a274470

Please sign in to comment.