|
| 1 | +/*- |
| 2 | + * -\-\- |
| 3 | + * github-api |
| 4 | + * -- |
| 5 | + * Copyright (C) 2016 - 2025 Spotify AB |
| 6 | + * -- |
| 7 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | + * you may not use this file except in compliance with the License. |
| 9 | + * You may obtain a copy of the License at |
| 10 | + * |
| 11 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | + * |
| 13 | + * Unless required by applicable law or agreed to in writing, software |
| 14 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | + * See the License for the specific language governing permissions and |
| 17 | + * limitations under the License. |
| 18 | + * -/-/- |
| 19 | + */ |
| 20 | + |
| 21 | +package com.spotify.github.v3.spring; |
| 22 | + |
| 23 | +import org.junit.Test; |
| 24 | +import org.springframework.boot.autoconfigure.AutoConfigurations; |
| 25 | +import org.springframework.boot.test.context.runner.ApplicationContextRunner; |
| 26 | +import org.springframework.context.annotation.Bean; |
| 27 | +import org.springframework.context.annotation.Configuration; |
| 28 | +import static org.assertj.core.api.Assertions.assertThat; |
| 29 | +import com.fasterxml.jackson.databind.ObjectMapper; |
| 30 | +import com.spotify.github.jackson.GithubApiModule; |
| 31 | + |
| 32 | +public class GithubClientAutoConfigurationTest { |
| 33 | + |
| 34 | + |
| 35 | + private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() |
| 36 | + .withConfiguration(AutoConfigurations.of(GithubClientAutoConfiguration.class)); |
| 37 | + |
| 38 | + @Test |
| 39 | + public void testModuleIsRegistered(){ |
| 40 | + |
| 41 | + this.contextRunner |
| 42 | + .withUserConfiguration(JacksonConfig.class) |
| 43 | + .run((context) -> { |
| 44 | + assertThat(context).hasSingleBean(GithubApiModule.class); |
| 45 | + }); |
| 46 | + } |
| 47 | + |
| 48 | + @Test |
| 49 | + public void testModuleIsNotRegisteredIfObjectMapperMissing(){ |
| 50 | + |
| 51 | + this.contextRunner |
| 52 | + .run((context) -> { |
| 53 | + assertThat(context).doesNotHaveBean(GithubApiModule.class); |
| 54 | + }); |
| 55 | + } |
| 56 | + |
| 57 | + @Configuration |
| 58 | + static class JacksonConfig { |
| 59 | + |
| 60 | + @Bean |
| 61 | + public ObjectMapper objectMapper() { |
| 62 | + return new ObjectMapper(); |
| 63 | + } |
| 64 | + } |
| 65 | +} |
0 commit comments