|
26 | 26 | import org.springframework.data.aot.sample.ConfigWithQuerydslPredicateExecutor.Person;
|
27 | 27 | import org.springframework.data.aot.sample.QConfigWithQuerydslPredicateExecutor_Person;
|
28 | 28 | import org.springframework.data.classloadersupport.HidingClassLoader;
|
| 29 | +import org.springframework.data.querydsl.User; |
29 | 30 | import org.springframework.javapoet.ClassName;
|
30 | 31 |
|
31 | 32 | import com.querydsl.core.types.EntityPath;
|
32 | 33 |
|
| 34 | +/** |
| 35 | + * Unit tests for {@link QTypeContributor}. |
| 36 | + * |
| 37 | + * @author ckdgus08 |
| 38 | + */ |
33 | 39 | class QTypeContributorUnitTests {
|
34 | 40 |
|
35 | 41 | @Test // GH-2721
|
@@ -68,4 +74,59 @@ void doesNotAddQTypeHintIfQuerydslNotPresent() {
|
68 | 74 | assertThat(generationContext.getRuntimeHints()).matches(
|
69 | 75 | RuntimeHintsPredicates.reflection().onType(QConfigWithQuerydslPredicateExecutor_Person.class).negate());
|
70 | 76 | }
|
| 77 | + |
| 78 | + @Test // DATAMONGO-4958 |
| 79 | + void doesNotAddQTypeHintForArrayType() { |
| 80 | + |
| 81 | + GenerationContext generationContext = new DefaultGenerationContext( |
| 82 | + new ClassNameGenerator(ClassName.get(this.getClass())), new InMemoryGeneratedFiles()); |
| 83 | + |
| 84 | + QTypeContributor.contributeEntityPath(Person[].class, generationContext, HidingClassLoader.hideTypes()); |
| 85 | + |
| 86 | + assertThat(generationContext.getRuntimeHints()).matches( |
| 87 | + RuntimeHintsPredicates.reflection().onType(QConfigWithQuerydslPredicateExecutor_Person.class).negate()); |
| 88 | + assertThat(generationContext.getRuntimeHints()).matches( |
| 89 | + RuntimeHintsPredicates.reflection().onType(QConfigWithQuerydslPredicateExecutor_Person[].class).negate()); |
| 90 | + } |
| 91 | + |
| 92 | + @Test // DATAMONGO-4958 |
| 93 | + void addsQTypeHintForQUserType() { |
| 94 | + |
| 95 | + GenerationContext generationContext = new DefaultGenerationContext( |
| 96 | + new ClassNameGenerator(ClassName.get(this.getClass())), new InMemoryGeneratedFiles()); |
| 97 | + |
| 98 | + QTypeContributor.contributeEntityPath(User.class, generationContext, getClass().getClassLoader()); |
| 99 | + |
| 100 | + var qUserHintCount = generationContext.getRuntimeHints().reflection().typeHints() |
| 101 | + .filter(hint -> hint.getType().getName().equals("org.springframework.data.querydsl.QUser")) |
| 102 | + .count(); |
| 103 | + assertThat(qUserHintCount).isEqualTo(1); |
| 104 | + } |
| 105 | + |
| 106 | + @Test // DATAMONGO-4958 |
| 107 | + void doesNotAddQTypeHintForQUserArrayType() { |
| 108 | + |
| 109 | + GenerationContext generationContext = new DefaultGenerationContext( |
| 110 | + new ClassNameGenerator(ClassName.get(this.getClass())), new InMemoryGeneratedFiles()); |
| 111 | + var classLoader = getClass().getClassLoader(); |
| 112 | + |
| 113 | + QTypeContributor.contributeEntityPath(User[].class, generationContext, classLoader); |
| 114 | + |
| 115 | + assertThat(generationContext.getRuntimeHints().reflection().typeHints()).isEmpty(); |
| 116 | + var qUserHintCount = generationContext.getRuntimeHints().reflection().typeHints() |
| 117 | + .filter(hint -> hint.getType().getName().equals("org.springframework.data.querydsl.QUser")) |
| 118 | + .count(); |
| 119 | + assertThat(qUserHintCount).isEqualTo(0); |
| 120 | + } |
| 121 | + |
| 122 | + @Test // DATAMONGO-4958 |
| 123 | + void doesNotAddQTypeHintForPrimitiveType() { |
| 124 | + |
| 125 | + GenerationContext generationContext = new DefaultGenerationContext( |
| 126 | + new ClassNameGenerator(ClassName.get(this.getClass())), new InMemoryGeneratedFiles()); |
| 127 | + |
| 128 | + QTypeContributor.contributeEntityPath(int.class, generationContext, getClass().getClassLoader()); |
| 129 | + |
| 130 | + assertThat(generationContext.getRuntimeHints().reflection().typeHints()).isEmpty(); |
| 131 | + } |
71 | 132 | }
|
0 commit comments