|
| 1 | +/* |
| 2 | + * Copyright 2002-2023 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.graphql.data.method.annotation.support; |
| 17 | + |
| 18 | +import java.util.Collections; |
| 19 | +import java.util.List; |
| 20 | + |
| 21 | +import org.junit.jupiter.api.Test; |
| 22 | + |
| 23 | +import org.springframework.context.support.StaticApplicationContext; |
| 24 | +import org.springframework.graphql.data.method.HandlerMethodArgumentResolver; |
| 25 | + |
| 26 | +import static org.assertj.core.api.Assertions.assertThat; |
| 27 | +import static org.mockito.Mockito.mock; |
| 28 | + |
| 29 | +/** |
| 30 | + * Unit tests for {@link AnnotatedControllerConfigurer}. |
| 31 | + * |
| 32 | + * @author Rossen Stoyanchev |
| 33 | + * @since 1.2 |
| 34 | + */ |
| 35 | +public class AnnotatedControllerConfigurerTests { |
| 36 | + |
| 37 | + |
| 38 | + @Test |
| 39 | + void customArgumentResolvers() { |
| 40 | + HandlerMethodArgumentResolver customResolver1 = mock(HandlerMethodArgumentResolver.class); |
| 41 | + HandlerMethodArgumentResolver customResolver2 = mock(HandlerMethodArgumentResolver.class); |
| 42 | + |
| 43 | + AnnotatedControllerConfigurer configurer = new AnnotatedControllerConfigurer(); |
| 44 | + configurer.setCustomArgumentResolver(Collections.singletonList(customResolver1)); |
| 45 | + configurer.setCustomArgumentResolver(Collections.singletonList(customResolver2)); |
| 46 | + configurer.setApplicationContext(new StaticApplicationContext()); |
| 47 | + configurer.afterPropertiesSet(); |
| 48 | + |
| 49 | + List<HandlerMethodArgumentResolver> resolvers = configurer.getArgumentResolvers().getResolvers(); |
| 50 | + int size = resolvers.size(); |
| 51 | + assertThat(resolvers).element(size -1).isInstanceOf(SourceMethodArgumentResolver.class); |
| 52 | + assertThat(resolvers).element(size -2).isSameAs(customResolver2); |
| 53 | + assertThat(resolvers).element(size -3).isSameAs(customResolver1); |
| 54 | + } |
| 55 | + |
| 56 | +} |
0 commit comments