Skip to content

Commit d114269

Browse files
committed
Polishing.
Add unit tests. See #3304
1 parent 115beba commit d114269

File tree

2 files changed

+93
-0
lines changed

2 files changed

+93
-0
lines changed

src/test/java/org/springframework/data/convert/CustomConversionsUnitTests.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,16 @@ void registersVavrConverters() {
273273
assertThat(conversionService.canConvert(List.class, io.vavr.collection.List.class)).isTrue();
274274
}
275275

276+
@Test // GH-3304
277+
void registersMultipleConvertersCorrectly() {
278+
279+
CustomConversions customConversions = new CustomConversions(new ConverterConfiguration(StoreConversions.NONE,
280+
List.of(PointToMapConverter.INSTANCE, new FormatConverterFactory()), (it) -> true, null));
281+
282+
assertThat(customConversions.hasCustomWriteTarget(Point.class, Map.class)).isTrue();
283+
assertThat(customConversions.hasCustomWriteTarget(String.class, Format.class)).isTrue();
284+
}
285+
276286
@Test // GH-1484
277287
void doesNotFailIfPropertiesConversionIsNull() {
278288

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* Copyright 2025 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.spel;
17+
18+
import static org.assertj.core.api.Assertions.*;
19+
20+
import java.util.List;
21+
22+
import org.junit.jupiter.api.Test;
23+
24+
import org.springframework.data.spel.spi.EvaluationContextExtension;
25+
import org.springframework.expression.spel.support.StandardEvaluationContext;
26+
27+
/**
28+
* Unit tests for {@link ExtensionAwareEvaluationContextProvider}.
29+
*
30+
* @author Mark Paluch
31+
*/
32+
class ExtensionAwareEvaluationContextProviderUnitTests {
33+
34+
@Test // GH-3304
35+
void shouldRegisterMultipleProvidersCorrectly() {
36+
37+
ExtensionAwareEvaluationContextProvider provider = new ExtensionAwareEvaluationContextProvider(
38+
List.of(FirstExtension.INSTANCE, SecondExtension.INSTANCE));
39+
StandardEvaluationContext evaluationContext = provider.getEvaluationContext(new GenericModelRoot());
40+
41+
assertThat(evaluationContext).isNotNull();
42+
}
43+
44+
/**
45+
* Extension without exposing a concrete extension type.
46+
*/
47+
enum FirstExtension implements EvaluationContextExtension {
48+
49+
INSTANCE;
50+
51+
@Override
52+
public String getExtensionId() {
53+
return "generic1";
54+
}
55+
56+
@Override
57+
public Object getRootObject() {
58+
return new GenericModelRoot();
59+
}
60+
}
61+
62+
/**
63+
* Extension without exposing a concrete extension type.
64+
*/
65+
enum SecondExtension implements EvaluationContextExtension {
66+
67+
INSTANCE;
68+
69+
@Override
70+
public String getExtensionId() {
71+
return "generic2";
72+
}
73+
74+
@Override
75+
public Object getRootObject() {
76+
return new GenericModelRoot();
77+
}
78+
}
79+
80+
record GenericModelRoot() {
81+
}
82+
83+
}

0 commit comments

Comments
 (0)