forked from springwolf/springwolf-core
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: GH-132: Add test for SpringPayloadAnnotationTypeExtractor
Add log message to indicate mismatch java versions Co-Authored-By: 93372330+sam0r040@users.noreply.github.com
- Loading branch information
Showing
2 changed files
with
99 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
...gwolf/asyncapi/scanners/channels/annotation/SpringPayloadAnnotationTypeExtractorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package io.github.stavshamir.springwolf.asyncapi.scanners.channels.annotation; | ||
|
||
|
||
import org.junit.Test; | ||
import org.springframework.messaging.handler.annotation.Payload; | ||
|
||
import java.lang.reflect.Method; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class SpringPayloadAnnotationTypeExtractorTest { | ||
|
||
@Test | ||
public void getPayloadType() throws NoSuchMethodException { | ||
Method m = TestClass.class.getDeclaredMethod("consumeWithString", String.class); | ||
|
||
Class<?> result = SpringPayloadAnnotationTypeExtractor.getPayloadType(m); | ||
|
||
assertEquals(String.class, result); | ||
} | ||
|
||
@Test | ||
public void getPayloadTypeWithPayloadAnnotation() throws NoSuchMethodException { | ||
Method m = TestClass.class.getDeclaredMethod("consumeWithStringAndPayloadAnnotation", String.class, Integer.class); | ||
|
||
Class<?> result = SpringPayloadAnnotationTypeExtractor.getPayloadType(m); | ||
|
||
assertEquals(String.class, result); | ||
} | ||
|
||
@Test | ||
public void getPayloadTypeWithListOfStrings() throws NoSuchMethodException { | ||
Method m = TestClass.class.getDeclaredMethod("consumeWithListOfStrings", List.class); | ||
|
||
Class<?> result = SpringPayloadAnnotationTypeExtractor.getPayloadType(m); | ||
|
||
assertEquals(String.class, result); | ||
} | ||
|
||
@Test | ||
public void getPayloadTypeWithListOfInterfaces() throws NoSuchMethodException { | ||
Method m = TestClass.class.getDeclaredMethod("consumeWithListOfGenericClasses", List.class); | ||
|
||
Class<?> result = SpringPayloadAnnotationTypeExtractor.getPayloadType(m); | ||
|
||
// Unable to resolve optional<String>, fallback to root type list | ||
assertEquals(List.class, result); | ||
} | ||
|
||
@Test | ||
public void getPayloadTypeWithInterface() throws NoSuchMethodException { | ||
Method m = TestClass.class.getDeclaredMethod("consumeWithGenericClass", Optional.class); | ||
|
||
Class<?> result = SpringPayloadAnnotationTypeExtractor.getPayloadType(m); | ||
|
||
assertEquals(Optional.class, result); | ||
} | ||
|
||
@Test | ||
public void getPayloadTypeWithListOfStringExtends() throws NoSuchMethodException { | ||
Method m = TestClass.class.getDeclaredMethod("consumeWithListOfStringExtends", List.class); | ||
|
||
Class<?> result = SpringPayloadAnnotationTypeExtractor.getPayloadType(m); | ||
|
||
// Unable to resolve optional<String>, fallback to root type list | ||
assertEquals(List.class, result); | ||
} | ||
|
||
@Test | ||
public void getPayloadTypeWithCustomType() throws NoSuchMethodException { | ||
Method m = TestClass.class.getDeclaredMethod("consumeWithCustomType", TestClass.MyType.class); | ||
|
||
Class<?> result = SpringPayloadAnnotationTypeExtractor.getPayloadType(m); | ||
|
||
assertEquals(TestClass.MyType.class, result); | ||
} | ||
|
||
public static class TestClass { | ||
public void consumeWithStringAndPayloadAnnotation(@Payload String value, Integer value2) {} | ||
public void consumeWithString(String value) {} | ||
public void consumeWithGenericClass(Optional<String> value) {} | ||
public void consumeWithListOfStrings(List<String> value) {} | ||
public void consumeWithListOfGenericClasses(List<Optional<String>> value) {} | ||
public void consumeWithListOfStringExtends(List<? extends String> value) {} | ||
public void consumeWithCustomType(MyType value) {} | ||
|
||
public static class MyType extends ArrayList<String> { } | ||
} | ||
} |