Skip to content

Commit eac6c0d

Browse files
authored
test: Add tests for MistralAiRuntimeHints (#3987)
Signed-off-by: Alex Klimenko <[email protected]>
1 parent 5483c7f commit eac6c0d

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

models/spring-ai-mistral-ai/src/test/java/org/springframework/ai/mistralai/aot/MistralAiRuntimeHintsTests.java

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,66 @@ void registerHints() {
5656
assertThat(registeredTypes.contains(TypeReference.of(MistralAiEmbeddingOptions.class))).isTrue();
5757
}
5858

59+
@Test
60+
void registerHintsWithNullClassLoader() {
61+
RuntimeHints runtimeHints = new RuntimeHints();
62+
MistralAiRuntimeHints mistralAiRuntimeHints = new MistralAiRuntimeHints();
63+
64+
// Should not throw exception with null classLoader
65+
mistralAiRuntimeHints.registerHints(runtimeHints, null);
66+
67+
// Verify hints were registered
68+
assertThat(runtimeHints.reflection().typeHints().count()).isGreaterThan(0);
69+
}
70+
71+
@Test
72+
void registerHintsWithValidClassLoader() {
73+
RuntimeHints runtimeHints = new RuntimeHints();
74+
MistralAiRuntimeHints mistralAiRuntimeHints = new MistralAiRuntimeHints();
75+
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
76+
77+
mistralAiRuntimeHints.registerHints(runtimeHints, classLoader);
78+
79+
// Verify hints were registered
80+
assertThat(runtimeHints.reflection().typeHints().count()).isGreaterThan(0);
81+
}
82+
83+
@Test
84+
void registerHintsIsIdempotent() {
85+
RuntimeHints runtimeHints = new RuntimeHints();
86+
MistralAiRuntimeHints mistralAiRuntimeHints = new MistralAiRuntimeHints();
87+
88+
// Register hints twice
89+
mistralAiRuntimeHints.registerHints(runtimeHints, null);
90+
long firstCount = runtimeHints.reflection().typeHints().count();
91+
92+
mistralAiRuntimeHints.registerHints(runtimeHints, null);
93+
long secondCount = runtimeHints.reflection().typeHints().count();
94+
95+
// Should have same number of hints
96+
assertThat(firstCount).isEqualTo(secondCount);
97+
}
98+
99+
@Test
100+
void verifyExpectedTypesAreRegistered() {
101+
RuntimeHints runtimeHints = new RuntimeHints();
102+
MistralAiRuntimeHints mistralAiRuntimeHints = new MistralAiRuntimeHints();
103+
mistralAiRuntimeHints.registerHints(runtimeHints, null);
104+
105+
Set<TypeReference> registeredTypes = new HashSet<>();
106+
runtimeHints.reflection().typeHints().forEach(typeHint -> registeredTypes.add(typeHint.getType()));
107+
108+
// Verify some expected types are registered (adjust class names as needed)
109+
assertThat(registeredTypes.stream().anyMatch(tr -> tr.getName().contains("MistralAi"))).isTrue();
110+
assertThat(registeredTypes.stream().anyMatch(tr -> tr.getName().contains("ChatCompletion"))).isTrue();
111+
}
112+
113+
@Test
114+
void verifyPackageScanningWorks() {
115+
Set<TypeReference> jsonAnnotatedClasses = findJsonAnnotatedClassesInPackage("org.springframework.ai.mistralai");
116+
117+
// Verify package scanning found classes
118+
assertThat(jsonAnnotatedClasses.size()).isGreaterThan(0);
119+
}
120+
59121
}

0 commit comments

Comments
 (0)