Skip to content

Commit d7a4c5f

Browse files
authored
Feat: Add Spring Boot AutoConfiguration with tests
1 parent 457a590 commit d7a4c5f

File tree

4 files changed

+123
-1
lines changed

4 files changed

+123
-1
lines changed

pom.xml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,24 @@
113113
</dependencyManagement>
114114

115115
<dependencies>
116+
<dependency>
117+
<groupId>org.springframework.boot</groupId>
118+
<artifactId>spring-boot-autoconfigure</artifactId>
119+
<version>2.7.18</version>
120+
<optional>true</optional>
121+
</dependency>
122+
<dependency>
123+
<groupId>org.springframework.boot</groupId>
124+
<artifactId>spring-boot-autoconfigure-processor</artifactId>
125+
<version>2.7.18</version>
126+
<optional>true</optional>
127+
</dependency>
128+
<dependency>
129+
<groupId>org.springframework.boot</groupId>
130+
<artifactId>spring-boot-starter-test</artifactId>
131+
<version>2.7.18</version>
132+
<scope>test</scope>
133+
</dependency>
116134
<dependency>
117135
<groupId>com.google.guava</groupId>
118136
<artifactId>guava</artifactId>
@@ -173,7 +191,6 @@
173191
<artifactId>opencensus-api</artifactId>
174192
<version>${opencensus.version}</version>
175193
</dependency>
176-
177194
<dependency>
178195
<groupId>io.opentelemetry</groupId>
179196
<artifactId>opentelemetry-api</artifactId>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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.springframework.boot.autoconfigure.AutoConfiguration;
24+
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
25+
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
26+
import org.springframework.context.annotation.Bean;
27+
28+
import com.spotify.github.v3.clients.GitHubClient;
29+
30+
@AutoConfiguration
31+
@ConditionalOnClass(GitHubClient.class)
32+
public class GithubClientAutoConfiguration {
33+
34+
@Bean
35+
@ConditionalOnBean
36+
public GitHubClient gitHubClient() {
37+
return GitHubClient.create(null, null);
38+
}
39+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
com.spotify.github.v3.spring.GithubClientAutoConfiguration

0 commit comments

Comments
 (0)