|
| 1 | +/* |
| 2 | + * Copyright 2022 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.shell.boot; |
| 17 | + |
| 18 | +import org.junit.jupiter.api.Test; |
| 19 | + |
| 20 | +import org.springframework.boot.autoconfigure.AutoConfigurations; |
| 21 | +import org.springframework.boot.test.context.runner.ApplicationContextRunner; |
| 22 | +import org.springframework.context.annotation.Bean; |
| 23 | +import org.springframework.context.annotation.Configuration; |
| 24 | +import org.springframework.core.convert.ConversionService; |
| 25 | +import org.springframework.core.convert.support.DefaultConversionService; |
| 26 | +import org.springframework.shell.command.CommandExecution.CommandExecutionHandlerMethodArgumentResolvers; |
| 27 | +import org.springframework.shell.completion.CompletionResolver; |
| 28 | + |
| 29 | +import static org.assertj.core.api.Assertions.assertThat; |
| 30 | + |
| 31 | +public class ParameterResolverAutoConfigurationTests { |
| 32 | + |
| 33 | + private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() |
| 34 | + .withConfiguration(AutoConfigurations.of(ParameterResolverAutoConfiguration.class)); |
| 35 | + |
| 36 | + @Test |
| 37 | + void defaultCompletionResolverExists() { |
| 38 | + this.contextRunner.withUserConfiguration(CustomShellConversionServiceConfiguration.class) |
| 39 | + .run((context) -> { |
| 40 | + assertThat(context).hasSingleBean(CompletionResolver.class); |
| 41 | + }); |
| 42 | + } |
| 43 | + |
| 44 | + @Test |
| 45 | + void defaultCommandExecutionHandlerMethodArgumentResolversExists() { |
| 46 | + this.contextRunner.withUserConfiguration(CustomShellConversionServiceConfiguration.class) |
| 47 | + .run((context) -> { |
| 48 | + assertThat(context).hasSingleBean(CommandExecutionHandlerMethodArgumentResolvers.class); |
| 49 | + }); |
| 50 | + } |
| 51 | + |
| 52 | + @Test |
| 53 | + void multipleConversionServiceBeans() { |
| 54 | + this.contextRunner |
| 55 | + .withUserConfiguration(CustomShellConversionServiceConfiguration.class, |
| 56 | + ExtraConversionServiceConfiguration.class) |
| 57 | + .run((context) -> { |
| 58 | + assertThat(context).hasSingleBean(CommandExecutionHandlerMethodArgumentResolvers.class); |
| 59 | + }); |
| 60 | + } |
| 61 | + |
| 62 | + @Configuration |
| 63 | + static class CustomShellConversionServiceConfiguration { |
| 64 | + |
| 65 | + @Bean |
| 66 | + ConversionService shellConversionService() { |
| 67 | + return new DefaultConversionService(); |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 71 | + @Configuration |
| 72 | + static class ExtraConversionServiceConfiguration { |
| 73 | + |
| 74 | + @Bean |
| 75 | + ConversionService conversionService() { |
| 76 | + return new DefaultConversionService(); |
| 77 | + } |
| 78 | + } |
| 79 | +} |
0 commit comments