Skip to content

Commit

Permalink
fix: make KsqlAvroSerializerTest work with Java 16 (#7873)
Browse files Browse the repository at this point in the history
Apparently some small things around casting behavior
and error messages have changed. This change makes the
test more generic so that it works regardless of the JVM.

Reviewer: Almog Gavra
  • Loading branch information
vvcephei authored Aug 9, 2021
1 parent e77eca1 commit bab8874
Showing 1 changed file with 32 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import static org.apache.kafka.connect.data.Schema.OPTIONAL_INT64_SCHEMA;
import static org.apache.kafka.connect.data.Schema.OPTIONAL_STRING_SCHEMA;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
Expand Down Expand Up @@ -251,8 +252,16 @@ public void shouldThrowIfNotStruct() {
);

// Then:
assertThat(e.getCause(), (hasMessage(containsString(
"java.lang.Integer cannot be cast to org.apache.kafka.connect.data.Struct"))));
assertThat(
e.getCause(),
hasMessage(
allOf(
containsString("java.lang.Integer"),
containsString("cannot be cast"),
containsString("org.apache.kafka.connect.data.Struct")
)
)
);
}

@Test
Expand Down Expand Up @@ -480,8 +489,16 @@ public void shouldThrowIfNotArray() {
);

// Then:
assertThat(e.getCause(), (hasMessage(CoreMatchers.is(
"java.lang.Boolean cannot be cast to java.util.List"))));
assertThat(
e.getCause(),
hasMessage(
allOf(
containsString("java.lang.Boolean"),
containsString("cannot be cast"),
containsString("java.util.List")
)
)
);
}

@Test
Expand Down Expand Up @@ -612,7 +629,7 @@ public void shouldSerializeArrayOfStruct() {
final byte[] bytes = serializer.serialize(SOME_TOPIC, value);

// Then:
assertThat(deserialize(bytes), is(ImmutableList.of(avroOrder)));
assertThat(deserialize(bytes), is((List<GenericRecord>) ImmutableList.of(avroOrder)));
}

@Test
Expand Down Expand Up @@ -667,8 +684,16 @@ public void shouldThrowIfNotMap() {
);

// Then:
assertThat(e.getCause(), (hasMessage(CoreMatchers.is(
"java.lang.Boolean cannot be cast to java.util.Map"))));
assertThat(
e.getCause(),
hasMessage(
allOf(
containsString("java.lang.Boolean"),
containsString("cannot be cast"),
containsString("java.util.Map")
)
)
);
}

@Test
Expand Down

0 comments on commit bab8874

Please sign in to comment.