Skip to content

Commit

Permalink
feat(core): add Optional to extractable classes (#525)
Browse files Browse the repository at this point in the history
  • Loading branch information
timonback authored Jan 12, 2024
1 parent 77ec272 commit 3bdcd51
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ public static class Payload {
"org.apache.kafka.streams.kstream.KStream",
1,
"java.util.List",
0,
"java.util.Optional",
0);

public void setExtractableClasses(Map<String, Integer> extractableClasses) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import org.springframework.messaging.support.GenericMessage;

import java.lang.reflect.Method;
import java.util.Collection;
import java.util.List;
import java.util.Optional;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
Expand Down Expand Up @@ -62,16 +62,16 @@ void getPayloadTypeWithMessageOfInterfaces() throws NoSuchMethodException {

Class<?> result = extractor.extractFrom(m);

assertEquals(Optional.class, result);
assertEquals(Collection.class, result);
}

@Test
void getPayloadTypeWithInterface() throws NoSuchMethodException {
Method m = TestClass.class.getDeclaredMethod("consumeWithGenericClass", Optional.class);
Method m = TestClass.class.getDeclaredMethod("consumeWithGenericClass", Collection.class);

Class<?> result = extractor.extractFrom(m);

assertEquals(Optional.class, result);
assertEquals(Collection.class, result);
}

@Test
Expand Down Expand Up @@ -118,9 +118,9 @@ public void consumeWithoutPayloadAnnotation(String value, Integer value2) {}

public void consumeWithString(String value) {}

public void consumeWithGenericClass(Optional<String> value) {}
public void consumeWithGenericClass(Collection<String> value) {}

public void consumeWithMessageOfGenericClasses(Message<Optional<String>> value) {}
public void consumeWithMessageOfGenericClasses(Message<Collection<String>> value) {}

public void consumeWithMessageOfStringExtends(Message<? extends String> value) {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void payloadTest() {
Map<String, Integer> actual = properties.getPayload().getExtractableClasses();

// default values
assertThat(actual).hasSize(5);
assertThat(actual).hasSize(6);
assertThat(actual).containsEntry("org.apache.kafka.streams.kstream.KStream", 1);
assertThat(actual).containsEntry("org.springframework.messaging.Message", 0);
assertThat(actual).containsEntry("java.util.function.Consumer", 0);
Expand Down Expand Up @@ -122,14 +122,15 @@ void payloadCustomizedTest() {
Map<String, Integer> actual = properties.getPayload().getExtractableClasses();

// default values
assertThat(actual).hasSize(6);
assertThat(actual).hasSize(7);
assertThat(actual).containsEntry("my.custom.class", 1);
// default values
assertThat(actual).containsEntry("org.apache.kafka.streams.kstream.KStream", 1);
assertThat(actual).containsEntry("org.springframework.messaging.Message", 0);
assertThat(actual).containsEntry("java.util.function.Consumer", 0);
assertThat(actual).containsEntry("java.util.function.Supplier", 0);
assertThat(actual).containsEntry("java.util.List", 0);
assertThat(actual).containsEntry("java.util.Optional", 0);
}
}

Expand All @@ -156,12 +157,13 @@ static class PayloadDisabledIntegrationTest {
void payloadDisabledTest() {
Map<String, Integer> actual = properties.getPayload().getExtractableClasses();

assertThat(actual).hasSize(4);
assertThat(actual).hasSize(5);
// default values
assertThat(actual).containsEntry("org.apache.kafka.streams.kstream.KStream", 1);
assertThat(actual).containsEntry("org.springframework.messaging.Message", 0);
assertThat(actual).containsEntry("java.util.function.Consumer", 0);
assertThat(actual).containsEntry("java.util.function.Supplier", 0);
assertThat(actual).containsEntry("java.util.Optional", 0);
}
}
}

0 comments on commit 3bdcd51

Please sign in to comment.