From b3e94b6d126b5c5168cf109342f3975fa1182a81 Mon Sep 17 00:00:00 2001 From: Havlli Date: Sun, 26 Apr 2026 21:10:27 +0200 Subject: [PATCH] refactor: use typed configuration properties --- .../github/havlli/EventPilot/Application.java | 2 ++ .../havlli/EventPilot/api/jwt/JWTService.java | 6 ++-- .../api/security/ApiSecurityProperties.java | 29 +++++++++++++++++++ .../EventPilot/api/security/CorsConfig.java | 25 ++++++---------- .../command/onreadyevent/ScheduledTask.java | 6 ++-- .../github/havlli/EventPilot/core/Client.java | 9 +++--- .../EventPilot/core/DiscordProperties.java | 23 +++++++++++++++ .../core/GlobalCommandRegistrar.java | 9 +++--- .../EventPilot/session/RedisConfig.java | 28 ------------------ src/main/resources/application.yml | 7 ++--- .../EventPilot/TestDatabaseContainer.java | 4 +-- .../EventPilot/api/jwt/JWTServiceTest.java | 28 +++++++++++++----- .../api/security/CorsConfigTest.java | 16 ++++++---- .../onreadyevent/ScheduledTaskTest.java | 9 ++++-- .../havlli/EventPilot/core/ClientIT.java | 6 +++- .../core/GlobalCommandRegistrarTest.java | 12 ++++++-- 16 files changed, 134 insertions(+), 85 deletions(-) create mode 100644 src/main/java/com/github/havlli/EventPilot/api/security/ApiSecurityProperties.java create mode 100644 src/main/java/com/github/havlli/EventPilot/core/DiscordProperties.java delete mode 100644 src/main/java/com/github/havlli/EventPilot/session/RedisConfig.java diff --git a/src/main/java/com/github/havlli/EventPilot/Application.java b/src/main/java/com/github/havlli/EventPilot/Application.java index ab015ff..c50bb42 100644 --- a/src/main/java/com/github/havlli/EventPilot/Application.java +++ b/src/main/java/com/github/havlli/EventPilot/Application.java @@ -2,8 +2,10 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.context.properties.ConfigurationPropertiesScan; @SpringBootApplication +@ConfigurationPropertiesScan public class Application { public static void main(String[] args) { diff --git a/src/main/java/com/github/havlli/EventPilot/api/jwt/JWTService.java b/src/main/java/com/github/havlli/EventPilot/api/jwt/JWTService.java index f944673..36569f5 100644 --- a/src/main/java/com/github/havlli/EventPilot/api/jwt/JWTService.java +++ b/src/main/java/com/github/havlli/EventPilot/api/jwt/JWTService.java @@ -1,5 +1,6 @@ package com.github.havlli.EventPilot.api.jwt; +import com.github.havlli.EventPilot.api.security.ApiSecurityProperties; import com.github.havlli.EventPilot.api.auth.UserDetailsImpl; import com.github.havlli.EventPilot.entity.user.User; import io.jsonwebtoken.*; @@ -7,7 +8,6 @@ import io.jsonwebtoken.security.Keys; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Value; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.stereotype.Component; @@ -23,8 +23,8 @@ public class JWTService { private static final Logger LOG = LoggerFactory.getLogger(JWTService.class); private final String jwtSecret; - public JWTService(@Value("${security.jwt.secret}") String jwtSecret) { - this.jwtSecret = jwtSecret; + public JWTService(ApiSecurityProperties securityProperties) { + this.jwtSecret = securityProperties.jwt().secret(); } public boolean hasClaim(String token, String claimName) { diff --git a/src/main/java/com/github/havlli/EventPilot/api/security/ApiSecurityProperties.java b/src/main/java/com/github/havlli/EventPilot/api/security/ApiSecurityProperties.java new file mode 100644 index 0000000..701aeb1 --- /dev/null +++ b/src/main/java/com/github/havlli/EventPilot/api/security/ApiSecurityProperties.java @@ -0,0 +1,29 @@ +package com.github.havlli.EventPilot.api.security; + +import jakarta.validation.Valid; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotEmpty; +import jakarta.validation.constraints.NotNull; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.validation.annotation.Validated; + +import java.util.List; + +@Validated +@ConfigurationProperties(prefix = "security") +public record ApiSecurityProperties( + @Valid @NotNull Jwt jwt, + @Valid @NotNull Cors cors +) { + + public record Jwt(@NotBlank String secret) { + } + + public record Cors( + @NotEmpty List allowedOrigins, + @NotEmpty List allowedMethods, + @NotEmpty List allowedHeaders, + List exposedHeaders + ) { + } +} diff --git a/src/main/java/com/github/havlli/EventPilot/api/security/CorsConfig.java b/src/main/java/com/github/havlli/EventPilot/api/security/CorsConfig.java index b4bcacd..d31b909 100644 --- a/src/main/java/com/github/havlli/EventPilot/api/security/CorsConfig.java +++ b/src/main/java/com/github/havlli/EventPilot/api/security/CorsConfig.java @@ -1,6 +1,5 @@ package com.github.havlli.EventPilot.api.security; -import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.cors.CorsConfiguration; @@ -8,29 +7,23 @@ import org.springframework.web.cors.UrlBasedCorsConfigurationSource; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; -import java.util.List; - @Configuration public class CorsConfig implements WebMvcConfigurer { - @Value("#{'${security.cors.allowed-origins}'.split(',')}") - private List allowedOrigins; - @Value("#{'${security.cors.allowed-methods}'.split(',')}") - private List allowedMethods; - - @Value("#{'${security.cors.allowed-headers}'.split(',')}") - private List allowedHeaders; + private final ApiSecurityProperties securityProperties; - @Value("#{'${security.cors.exposed-headers}'.split(',')}") - private List exposedHeaders; + public CorsConfig(ApiSecurityProperties securityProperties) { + this.securityProperties = securityProperties; + } @Bean public CorsConfigurationSource corsConfigurationSource() { + ApiSecurityProperties.Cors cors = securityProperties.cors(); CorsConfiguration configuration = new CorsConfiguration(); - configuration.setAllowedOrigins(allowedOrigins); - configuration.setAllowedMethods(allowedMethods); - configuration.setAllowedHeaders(allowedHeaders); - configuration.setExposedHeaders(exposedHeaders); + configuration.setAllowedOrigins(cors.allowedOrigins()); + configuration.setAllowedMethods(cors.allowedMethods()); + configuration.setAllowedHeaders(cors.allowedHeaders()); + configuration.setExposedHeaders(cors.exposedHeaders()); UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); source.registerCorsConfiguration("/api/**", configuration); return source; diff --git a/src/main/java/com/github/havlli/EventPilot/command/onreadyevent/ScheduledTask.java b/src/main/java/com/github/havlli/EventPilot/command/onreadyevent/ScheduledTask.java index 191c813..2d55fdb 100644 --- a/src/main/java/com/github/havlli/EventPilot/command/onreadyevent/ScheduledTask.java +++ b/src/main/java/com/github/havlli/EventPilot/command/onreadyevent/ScheduledTask.java @@ -1,11 +1,11 @@ package com.github.havlli.EventPilot.command.onreadyevent; import com.github.havlli.EventPilot.core.DiscordService; +import com.github.havlli.EventPilot.core.DiscordProperties; import com.github.havlli.EventPilot.entity.event.Event; import com.github.havlli.EventPilot.entity.event.EventService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import reactor.core.Disposable; import reactor.core.publisher.Flux; @@ -30,11 +30,11 @@ public class ScheduledTask { public ScheduledTask( EventService eventService, DiscordService discordService, - @Value("${discord.scheduler.interval-seconds}") Integer intervalSeconds + DiscordProperties discordProperties ) { this.eventService = eventService; this.discordService = discordService; - this.intervalSeconds = intervalSeconds; + this.intervalSeconds = discordProperties.scheduler().intervalSeconds(); } public Flux getSchedulersFlux() { diff --git a/src/main/java/com/github/havlli/EventPilot/core/Client.java b/src/main/java/com/github/havlli/EventPilot/core/Client.java index 0a4258d..8f031fd 100644 --- a/src/main/java/com/github/havlli/EventPilot/core/Client.java +++ b/src/main/java/com/github/havlli/EventPilot/core/Client.java @@ -5,7 +5,6 @@ import discord4j.core.object.presence.ClientActivity; import discord4j.core.object.presence.ClientPresence; import discord4j.rest.RestClient; -import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Profile; import org.springframework.stereotype.Component; @@ -13,15 +12,15 @@ @Component @Profile("!test") public class Client { - private final String token; + private final DiscordProperties discordProperties; - public Client(@Value("${discord.token}") String token) { - this.token = token; + public Client(DiscordProperties discordProperties) { + this.discordProperties = discordProperties; } @Bean public GatewayDiscordClient createDiscordClient() { - return DiscordClient.create(token) + return DiscordClient.create(discordProperties.token()) .gateway() .setInitialPresence(__ -> ClientPresence.online(ClientActivity.listening("to /commands"))) .login() diff --git a/src/main/java/com/github/havlli/EventPilot/core/DiscordProperties.java b/src/main/java/com/github/havlli/EventPilot/core/DiscordProperties.java new file mode 100644 index 0000000..9d6e981 --- /dev/null +++ b/src/main/java/com/github/havlli/EventPilot/core/DiscordProperties.java @@ -0,0 +1,23 @@ +package com.github.havlli.EventPilot.core; + +import jakarta.validation.Valid; +import jakarta.validation.constraints.Min; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.validation.annotation.Validated; + +@Validated +@ConfigurationProperties(prefix = "discord") +public record DiscordProperties( + @NotBlank String token, + @Valid @NotNull Commands commands, + @Valid @NotNull Scheduler scheduler +) { + + public record Commands(@NotBlank String folder) { + } + + public record Scheduler(@Min(1) int intervalSeconds) { + } +} diff --git a/src/main/java/com/github/havlli/EventPilot/core/GlobalCommandRegistrar.java b/src/main/java/com/github/havlli/EventPilot/core/GlobalCommandRegistrar.java index 71010f2..9dae6fb 100644 --- a/src/main/java/com/github/havlli/EventPilot/core/GlobalCommandRegistrar.java +++ b/src/main/java/com/github/havlli/EventPilot/core/GlobalCommandRegistrar.java @@ -6,7 +6,6 @@ import discord4j.rest.service.ApplicationService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationRunner; import org.springframework.context.annotation.DependsOn; @@ -32,16 +31,16 @@ public class GlobalCommandRegistrar implements ApplicationRunner { private static final Logger LOG = LoggerFactory.getLogger(GlobalCommandRegistrar.class); private final RestClient restClient; private final PathMatchingResourcePatternResolver pathMatcher; - private final String parentFolder; + private final DiscordProperties discordProperties; public GlobalCommandRegistrar( RestClient restClient, PathMatchingResourcePatternResolver pathMatcher, - @Value(value = "${discord.commands.folder}") String parentFolder + DiscordProperties discordProperties ) { this.restClient = restClient; this.pathMatcher = pathMatcher; - this.parentFolder = parentFolder; + this.discordProperties = discordProperties; } @Override @@ -104,7 +103,7 @@ protected ApplicationCommandRequest readJsonValueOrThrow(JacksonResources jackso } private String getLocationPattern() { - return parentFolder + "/*.json"; + return discordProperties.commands().folder() + "/*.json"; } protected ApplicationCommandRequest readJsonValue(JacksonResources jacksonResources, Resource resource) throws IOException { diff --git a/src/main/java/com/github/havlli/EventPilot/session/RedisConfig.java b/src/main/java/com/github/havlli/EventPilot/session/RedisConfig.java deleted file mode 100644 index 95f2c0c..0000000 --- a/src/main/java/com/github/havlli/EventPilot/session/RedisConfig.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.github.havlli.EventPilot.session; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.data.redis.connection.RedisStandaloneConfiguration; -import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; - -@Configuration -public class RedisConfig { - - @Value("${cache.redis.host}") - private String redisHost; - @Value("${cache.redis.port}") - private Integer redisPort; - @Bean - public LettuceConnectionFactory connectionFactory(RedisStandaloneConfiguration redisStandaloneConfiguration) { - redisStandaloneConfiguration.setHostName(redisHost); - redisStandaloneConfiguration.setPort(redisPort); - redisStandaloneConfiguration.setDatabase(0); - return new LettuceConnectionFactory(redisStandaloneConfiguration); - } - - @Bean - public RedisStandaloneConfiguration redisStandaloneConfiguration() { - return new RedisStandaloneConfiguration(); - } -} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index f3ec77e..141cd92 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -21,14 +21,11 @@ spring: show-sql: false data: redis: + host: localhost + port: 6379 repositories: enabled: false -cache: - redis: - host: localhost - port: 6379 - security: jwt: secret: ${JWT_SECRET} diff --git a/src/test/java/com/github/havlli/EventPilot/TestDatabaseContainer.java b/src/test/java/com/github/havlli/EventPilot/TestDatabaseContainer.java index 3d2b6e2..40f8d75 100644 --- a/src/test/java/com/github/havlli/EventPilot/TestDatabaseContainer.java +++ b/src/test/java/com/github/havlli/EventPilot/TestDatabaseContainer.java @@ -59,8 +59,8 @@ private static void registerContainerProperties(DynamicPropertyRegistry registry registry.add("spring.datasource.url", () -> postgresSQLContainer.getJdbcUrl()); registry.add("spring.datasource.username", () -> postgresSQLContainer.getUsername()); registry.add("spring.datasource.password", () -> postgresSQLContainer.getPassword()); - registry.add("cache.redis.host", () -> redisContainer.getHost()); - registry.add("cache.redis.port", () -> redisContainer.getFirstMappedPort()); + registry.add("spring.data.redis.host", () -> redisContainer.getHost()); + registry.add("spring.data.redis.port", () -> redisContainer.getFirstMappedPort()); registry.add("security.jwt.secret", () -> "MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDE="); registry.add("discord.token", () -> "test"); } diff --git a/src/test/java/com/github/havlli/EventPilot/api/jwt/JWTServiceTest.java b/src/test/java/com/github/havlli/EventPilot/api/jwt/JWTServiceTest.java index b547e96..8eee01d 100644 --- a/src/test/java/com/github/havlli/EventPilot/api/jwt/JWTServiceTest.java +++ b/src/test/java/com/github/havlli/EventPilot/api/jwt/JWTServiceTest.java @@ -1,5 +1,6 @@ package com.github.havlli.EventPilot.api.jwt; +import com.github.havlli.EventPilot.api.security.ApiSecurityProperties; import com.github.havlli.EventPilot.api.auth.UserDetailsImpl; import com.github.havlli.EventPilot.entity.user.User; import com.github.havlli.EventPilot.entity.user.UserRole; @@ -14,6 +15,7 @@ import org.mockito.MockitoAnnotations; import java.util.Date; +import java.util.List; import java.util.Map; import java.util.Optional; import java.util.Set; @@ -32,7 +34,7 @@ class JWTServiceTest { void setUp() { autoCloseable = MockitoAnnotations.openMocks(this); jwtSecret = generateKey(); - underTest = new JWTService(jwtSecret); + underTest = createJwtService(jwtSecret); } private String generateKey() { @@ -40,6 +42,18 @@ private String generateKey() { return Encoders.BASE64.encode(encodedSecret); } + private JWTService createJwtService(String jwtSecret) { + return new JWTService(new ApiSecurityProperties( + new ApiSecurityProperties.Jwt(jwtSecret), + new ApiSecurityProperties.Cors( + List.of("http://localhost:3000"), + List.of("GET"), + List.of("Authorization"), + List.of("Authorization") + ) + )); + } + @AfterEach void tearDown() throws Exception { autoCloseable.close(); @@ -83,7 +97,7 @@ void hasClaim_ThrowsSignatureException_WhenTokenSignatureIsInvalid() { User user = new User(null, "username", "email", "password", Set.of(userRole)); String jwtSecret = generateKey(); - JWTService underTestSpy = spy(new JWTService(jwtSecret)); + JWTService underTestSpy = spy(createJwtService(jwtSecret)); String jwtToken = underTestSpy.generateToken(user); String invalidSignatureToken = jwtToken.substring(0, jwtToken.length() - 5); @@ -99,7 +113,7 @@ void hasClaim_ThrowsMalformedException_WhenTokenHeaderIsInvalid() { User user = new User(null, "username", "email", "password", Set.of(userRole)); String jwtSecret = generateKey(); - JWTService underTestSpy = spy(new JWTService(jwtSecret)); + JWTService underTestSpy = spy(createJwtService(jwtSecret)); String jwtToken = underTestSpy.generateToken(user); String invalidHeaderToken = jwtToken.substring(5); @@ -115,7 +129,7 @@ void hasClaim_ThrowsJwtException_WhenTokenPayloadIsInvalid() { User user = new User(null, "username", "email", "password", Set.of(userRole)); String jwtSecret = generateKey(); - JWTService underTestSpy = spy(new JWTService(jwtSecret)); + JWTService underTestSpy = spy(createJwtService(jwtSecret)); String jwtToken = underTestSpy.generateToken(user); String[] splitToken = jwtToken.split("\\."); @@ -134,7 +148,7 @@ void isTokenValid_ReturnsTrue_WhenTokenIsValidAndMatchesUserDetails() { User user = new User(null, "username", "email", "password", Set.of(userRole)); String jwtSecret = generateKey(); - JWTService underTestSpy = spy(new JWTService(jwtSecret)); + JWTService underTestSpy = spy(createJwtService(jwtSecret)); String validToken = underTestSpy.generateToken(user); UserDetailsImpl userDetails = UserDetailsImpl.of(user); @@ -153,7 +167,7 @@ void isTokenValid_ReturnsFalse_WhenTokenIsValidAndNotMatchesUsername() { User user = new User(null, "username", "email", "password", Set.of(userRole)); String jwtSecret = generateKey(); - JWTService underTestSpy = spy(new JWTService(jwtSecret)); + JWTService underTestSpy = spy(createJwtService(jwtSecret)); String validToken = underTestSpy.generateToken(user); User differentUser = new User(null, "username1", "email", "password", Set.of(userRole)); @@ -173,7 +187,7 @@ void isTokenValid_ThrowsJWTException_WhenTokenIsInvalidAndMatchesUsername() { User user = new User(null, "username", "email", "password", Set.of(userRole)); String jwtSecret = generateKey(); - JWTService underTestSpy = spy(new JWTService(jwtSecret)); + JWTService underTestSpy = spy(createJwtService(jwtSecret)); String validToken = underTestSpy.generateToken(user); String[] splitToken = validToken.split("\\."); splitToken[1] = "eyJzdWIiOiJ1c2VybmFtZSIsImF1dGhvcml0aWVzIjpboiJhdXRob3JpdHkiOiJVU0VSIn1dLCJpYXQiOjE2OTczOTIxMzMsImV4cCI6MTY5NzQyODEzM30"; diff --git a/src/test/java/com/github/havlli/EventPilot/api/security/CorsConfigTest.java b/src/test/java/com/github/havlli/EventPilot/api/security/CorsConfigTest.java index bc06a68..16bd679 100644 --- a/src/test/java/com/github/havlli/EventPilot/api/security/CorsConfigTest.java +++ b/src/test/java/com/github/havlli/EventPilot/api/security/CorsConfigTest.java @@ -2,7 +2,6 @@ import org.junit.jupiter.api.Test; import org.springframework.mock.web.MockHttpServletRequest; -import org.springframework.test.util.ReflectionTestUtils; import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.cors.CorsConfigurationSource; @@ -14,11 +13,16 @@ class CorsConfigTest { @Test void corsConfigurationSource_UsesExplicitApiCorsPolicy() { - CorsConfig underTest = new CorsConfig(); - ReflectionTestUtils.setField(underTest, "allowedOrigins", List.of("http://localhost:3000", "http://localhost:5173")); - ReflectionTestUtils.setField(underTest, "allowedMethods", List.of("GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS")); - ReflectionTestUtils.setField(underTest, "allowedHeaders", List.of("Authorization", "Content-Type")); - ReflectionTestUtils.setField(underTest, "exposedHeaders", List.of("Authorization")); + ApiSecurityProperties securityProperties = new ApiSecurityProperties( + new ApiSecurityProperties.Jwt("secret"), + new ApiSecurityProperties.Cors( + List.of("http://localhost:3000", "http://localhost:5173"), + List.of("GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"), + List.of("Authorization", "Content-Type"), + List.of("Authorization") + ) + ); + CorsConfig underTest = new CorsConfig(securityProperties); CorsConfigurationSource source = underTest.corsConfigurationSource(); MockHttpServletRequest request = new MockHttpServletRequest("GET", "/api/users"); diff --git a/src/test/java/com/github/havlli/EventPilot/command/onreadyevent/ScheduledTaskTest.java b/src/test/java/com/github/havlli/EventPilot/command/onreadyevent/ScheduledTaskTest.java index 41b18e2..2531f2d 100644 --- a/src/test/java/com/github/havlli/EventPilot/command/onreadyevent/ScheduledTaskTest.java +++ b/src/test/java/com/github/havlli/EventPilot/command/onreadyevent/ScheduledTaskTest.java @@ -1,6 +1,7 @@ package com.github.havlli.EventPilot.command.onreadyevent; import com.github.havlli.EventPilot.core.DiscordService; +import com.github.havlli.EventPilot.core.DiscordProperties; import com.github.havlli.EventPilot.entity.event.Event; import com.github.havlli.EventPilot.entity.event.EventService; import org.junit.jupiter.api.AfterEach; @@ -30,7 +31,11 @@ class ScheduledTaskTest { @BeforeEach public void setUp() { autoCloseable = MockitoAnnotations.openMocks(this); - underTest = new ScheduledTask(eventServiceMock, discordServiceMock, intervalSeconds); + underTest = new ScheduledTask(eventServiceMock, discordServiceMock, new DiscordProperties( + "token", + new DiscordProperties.Commands("commands"), + new DiscordProperties.Scheduler(intervalSeconds) + )); } @AfterEach @@ -56,4 +61,4 @@ public void getFlux_InvokesServicesTwiceIn13Seconds_WhenIntervalIs5Seconds() { verify(discordServiceMock, times(2)).deactivateEvents(expiredEvents); } -} \ No newline at end of file +} diff --git a/src/test/java/com/github/havlli/EventPilot/core/ClientIT.java b/src/test/java/com/github/havlli/EventPilot/core/ClientIT.java index e1cf02f..89d246e 100644 --- a/src/test/java/com/github/havlli/EventPilot/core/ClientIT.java +++ b/src/test/java/com/github/havlli/EventPilot/core/ClientIT.java @@ -18,7 +18,11 @@ class ClientIT extends DiscordBotTestConfig { void setUp() { String token = getToken(); assumeTrue(isRealBotToken(token), "TEST_DISCORD_BOT_TOKEN is not configured with a real bot token"); - underTest = new Client(token); + underTest = new Client(new DiscordProperties( + token, + new DiscordProperties.Commands("commands"), + new DiscordProperties.Scheduler(60) + )); } private boolean isRealBotToken(String token) { diff --git a/src/test/java/com/github/havlli/EventPilot/core/GlobalCommandRegistrarTest.java b/src/test/java/com/github/havlli/EventPilot/core/GlobalCommandRegistrarTest.java index 25e5b17..3fdf422 100644 --- a/src/test/java/com/github/havlli/EventPilot/core/GlobalCommandRegistrarTest.java +++ b/src/test/java/com/github/havlli/EventPilot/core/GlobalCommandRegistrarTest.java @@ -44,7 +44,7 @@ void setUp() { underTest = new GlobalCommandRegistrar( mockClient, new PathMatchingResourcePatternResolver(), - "commands" + discordProperties("commands") ); } @@ -82,7 +82,7 @@ void run_ShouldThrow_WhenFileNotFound() { underTest = new GlobalCommandRegistrar( mockClient, new PathMatchingResourcePatternResolver(), - "impossible-folder" + discordProperties("impossible-folder") ); // Assert @@ -124,4 +124,12 @@ void run_ShouldThrow_WhenBulkOverwriteFails() { .isInstanceOf(RuntimeException.class) .hasMessageContaining("registration failed"); } + + private DiscordProperties discordProperties(String commandsFolder) { + return new DiscordProperties( + "token", + new DiscordProperties.Commands(commandsFolder), + new DiscordProperties.Scheduler(60) + ); + } }