|  | 
|  | 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