Skip to content

Commit 8caffe8

Browse files
authored
test: Enhance test coverage for MistralAiBindingsPropertiesProcessor (#4165)
Signed-off-by: Oleksandr Klymenko <[email protected]>
1 parent 90f636e commit 8caffe8

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

spring-ai-spring-cloud-bindings/src/test/java/org/springframework/ai/bindings/MistralAiBindingsPropertiesProcessorTests.java

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.springframework.mock.env.MockEnvironment;
2828

2929
import static org.assertj.core.api.Assertions.assertThat;
30+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
3031

3132
/**
3233
* Unit tests for {@link MistralAiBindingsPropertiesProcessor}.
@@ -65,4 +66,58 @@ void whenDisabledThenPropertiesAreNotContributed() {
6566
assertThat(this.properties).isEmpty();
6667
}
6768

69+
@Test
70+
void nullBindingsShouldThrowException() {
71+
assertThatThrownBy(
72+
() -> new MistralAiBindingsPropertiesProcessor().process(this.environment, null, this.properties))
73+
.isInstanceOf(NullPointerException.class);
74+
}
75+
76+
@Test
77+
void nullEnvironmentShouldThrowException() {
78+
assertThatThrownBy(
79+
() -> new MistralAiBindingsPropertiesProcessor().process(null, this.bindings, this.properties))
80+
.isInstanceOf(NullPointerException.class);
81+
}
82+
83+
@Test
84+
void nullPropertiesShouldThrowException() {
85+
assertThatThrownBy(
86+
() -> new MistralAiBindingsPropertiesProcessor().process(this.environment, this.bindings, null))
87+
.isInstanceOf(NullPointerException.class);
88+
}
89+
90+
@Test
91+
void missingApiKeyShouldStillSetNullValue() {
92+
Bindings bindingsWithoutApiKey = new Bindings(new Binding("test-name", Paths.get("test-path"), Map
93+
.of(Binding.TYPE, MistralAiBindingsPropertiesProcessor.TYPE, "uri", "https://my.mistralai.example.net")));
94+
95+
new MistralAiBindingsPropertiesProcessor().process(this.environment, bindingsWithoutApiKey, this.properties);
96+
97+
assertThat(this.properties).containsEntry("spring.ai.mistralai.base-url", "https://my.mistralai.example.net");
98+
assertThat(this.properties).containsEntry("spring.ai.mistralai.api-key", null);
99+
}
100+
101+
@Test
102+
void emptyApiKeyIsStillSet() {
103+
Bindings bindingsWithEmptyApiKey = new Bindings(new Binding("test-name", Paths.get("test-path"),
104+
Map.of(Binding.TYPE, MistralAiBindingsPropertiesProcessor.TYPE, "api-key", "", "uri",
105+
"https://my.mistralai.example.net")));
106+
107+
new MistralAiBindingsPropertiesProcessor().process(this.environment, bindingsWithEmptyApiKey, this.properties);
108+
109+
assertThat(this.properties).containsEntry("spring.ai.mistralai.api-key", "");
110+
assertThat(this.properties).containsEntry("spring.ai.mistralai.base-url", "https://my.mistralai.example.net");
111+
}
112+
113+
@Test
114+
void wrongBindingTypeShouldBeIgnored() {
115+
Bindings wrongTypeBindings = new Bindings(new Binding("test-name", Paths.get("test-path"),
116+
Map.of(Binding.TYPE, "different-type", "api-key", "demo", "uri", "https://my.mistralai.example.net")));
117+
118+
new MistralAiBindingsPropertiesProcessor().process(this.environment, wrongTypeBindings, this.properties);
119+
120+
assertThat(this.properties).isEmpty();
121+
}
122+
68123
}

0 commit comments

Comments
 (0)