fix: spotless formatting fixes

This commit is contained in:
Ilkka Seppälä
2026-06-07 12:40:02 +03:00
parent c317ce012a
commit 2dfb27c859
17 changed files with 141 additions and 79 deletions
@@ -67,6 +67,26 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>2.44.4</version>
<executions>
<execution>
<goals>
<goal>check</goal>
<goal>apply</goal>
</goals>
</execution>
</executions>
<configuration>
<java>
<googleJavaFormat>
<version>1.17.0</version>
</googleJavaFormat>
</java>
</configuration>
</plugin>
</plugins>
</build>
@@ -10,8 +10,7 @@ import org.springframework.cloud.openfeign.EnableFeignClients;
@EnableFeignClients
public class ContextserviceApplication {
public static void main(String[] args) {
SpringApplication.run(ContextserviceApplication.class, args);
}
public static void main(String[] args) {
SpringApplication.run(ContextserviceApplication.class, args);
}
}
@@ -7,7 +7,6 @@ import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Component("myCustomHealthCheck")
public class MyCustomHealthCheck implements HealthIndicator {
@@ -33,7 +32,9 @@ public class MyCustomHealthCheck implements HealthIndicator {
public Health health() {
if (isHealthy) {
log.info("Health check successful, service is UP");
return Health.up().withDetail("message", "Service is running and scheduled checks are OK").build();
return Health.up()
.withDetail("message", "Service is running and scheduled checks are OK")
.build();
} else {
log.warn("Health check failed, service is DOWN");
return Health.down().withDetail("error", "Scheduled health checks failed").build();
@@ -13,7 +13,8 @@ public class ContextController {
private final String userRegion;
@Autowired
public ContextController(GreetingServiceClient greetingServiceClient, @Value("${user.region}") String userRegion) {
public ContextController(
GreetingServiceClient greetingServiceClient, @Value("${user.region}") String userRegion) {
this.greetingServiceClient = greetingServiceClient;
this.userRegion = userRegion;
}
@@ -21,6 +22,6 @@ public class ContextController {
@GetMapping("/context")
public String getContext() {
String greeting = greetingServiceClient.getGreeting();
return "The Greeting Service says: "+greeting+" from "+userRegion;
return "The Greeting Service says: " + greeting + " from " + userRegion;
}
}
@@ -7,7 +7,6 @@ import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Import;
import org.springframework.http.MediaType;
@@ -21,29 +20,31 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
@Import(TestConfig.class)
class ContextControllerTest {
@Autowired
private MockMvc mockMvc;
@Autowired private MockMvc mockMvc;
@MockitoBean
private GreetingServiceClient greetingServiceClient;
@MockitoBean private GreetingServiceClient greetingServiceClient;
@Value("${user.region}")
private String userRegion;
@Test
void shouldReturnContextGreeting() throws Exception{
void shouldReturnContextGreeting() throws Exception {
Mockito.when(greetingServiceClient.getGreeting()).thenReturn("Mocked Hello");
mockMvc.perform(MockMvcRequestBuilders.get("/context")
.accept(MediaType.TEXT_PLAIN))
mockMvc
.perform(MockMvcRequestBuilders.get("/context").accept(MediaType.TEXT_PLAIN))
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.content().string("The Greeting Service says: Mocked Hello from Chennai, Tamil Nadu, India"));
.andExpect(
MockMvcResultMatchers.content()
.string("The Greeting Service says: Mocked Hello from Chennai, Tamil Nadu, India"));
}
@Test
void shouldReturnContextServiceHealthStatusUp() throws Exception {
mockMvc.perform(MockMvcRequestBuilders.get("/actuator/health"))
mockMvc
.perform(MockMvcRequestBuilders.get("/actuator/health"))
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.content().string(Matchers.containsString("\"status\":\"UP\"")));
.andExpect(
MockMvcResultMatchers.content().string(Matchers.containsString("\"status\":\"UP\"")));
}
}
@@ -6,12 +6,13 @@ import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class ContextserviceApplicationTests {
@Test
void contextLoads() {
// This is a basic integration test that checks if the Spring Application Context loads successfully.
@Test
void contextLoads() {
// This is a basic integration test that checks if the Spring Application Context loads
// successfully.
// If the context loads without any exceptions, the test is considered passing.
// It is often left empty as the act of loading the context is the primary verification.
// You can add specific assertions here if you want to verify the presence or state of certain beans.
}
// You can add specific assertions here if you want to verify the presence or state of certain
// beans.
}
}
@@ -1,10 +1,11 @@
package com.learning.contextservice;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import org.springframework.boot.actuate.health.Health;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.boot.actuate.health.Status;
import static org.junit.jupiter.api.Assertions.*;
import org.springframework.test.util.ReflectionTestUtils;
class MyCustomHealthCheckTest {
@@ -16,7 +17,8 @@ class MyCustomHealthCheckTest {
Health health = healthCheck.health();
assertEquals(Status.UP, health.getStatus());
assertTrue(health.getDetails().containsKey("message"));
assertEquals("Service is running and scheduled checks are OK", health.getDetails().get("message"));
assertEquals(
"Service is running and scheduled checks are OK", health.getDetails().get("message"));
}
@Test
@@ -29,5 +31,4 @@ class MyCustomHealthCheckTest {
assertTrue(health.getDetails().containsKey("error"));
assertEquals("Scheduled health checks failed", health.getDetails().get("error"));
}
}
}
@@ -49,6 +49,26 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>2.44.4</version>
<executions>
<execution>
<goals>
<goal>check</goal>
<goal>apply</goal>
</goals>
</execution>
</executions>
<configuration>
<java>
<googleJavaFormat>
<version>1.17.0</version>
</googleJavaFormat>
</java>
</configuration>
</plugin>
</plugins>
</build>
@@ -8,8 +8,7 @@ import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@EnableEurekaServer
public class EurekaserverApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaserverApplication.class, args);
}
public static void main(String[] args) {
SpringApplication.run(EurekaserverApplication.class, args);
}
}
@@ -6,12 +6,13 @@ import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class EurekaserverApplicationTests {
@Test
void contextLoads() {
// This is a basic integration test that checks if the Spring Application Context loads successfully.
@Test
void contextLoads() {
// This is a basic integration test that checks if the Spring Application Context loads
// successfully.
// If the context loads without any exceptions, the test is considered passing.
// It is often left empty as the act of loading the context is the primary verification.
// You can add specific assertions here if you want to verify the presence or state of certain beans.
}
// You can add specific assertions here if you want to verify the presence or state of certain
// beans.
}
}
@@ -63,6 +63,26 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>2.44.4</version>
<executions>
<execution>
<goals>
<goal>check</goal>
<goal>apply</goal>
</goals>
</execution>
</executions>
<configuration>
<java>
<googleJavaFormat>
<version>1.17.0</version>
</googleJavaFormat>
</java>
</configuration>
</plugin>
</plugins>
</build>
@@ -10,8 +10,7 @@ import org.springframework.context.annotation.ComponentScan;
@ComponentScan("com.learning.greetingservice.controller")
public class GreetingserviceApplication {
public static void main(String[] args) {
SpringApplication.run(GreetingserviceApplication.class, args);
}
public static void main(String[] args) {
SpringApplication.run(GreetingserviceApplication.class, args);
}
}
@@ -32,7 +32,9 @@ public class MyCustomHealthCheck implements HealthIndicator {
public Health health() {
if (isHealthy) {
log.info("Health check successful, service is UP");
return Health.up().withDetail("message", "Service is running and scheduled checks are OK").build();
return Health.up()
.withDetail("message", "Service is running and scheduled checks are OK")
.build();
} else {
log.warn("Health check failed, service is DOWN");
return Health.down().withDetail("error", "Scheduled health checks failed").build();
@@ -6,12 +6,13 @@ import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class GreetingserviceApplicationTests {
@Test
void contextLoads() {
// This is a basic integration test that checks if the Spring Application Context loads successfully.
@Test
void contextLoads() {
// This is a basic integration test that checks if the Spring Application Context loads
// successfully.
// If the context loads without any exceptions, the test is considered passing.
// It is often left empty as the act of loading the context is the primary verification.
// You can add specific assertions here if you want to verify the presence or state of certain beans.
}
// You can add specific assertions here if you want to verify the presence or state of certain
// beans.
}
}
@@ -1,10 +1,11 @@
package com.learning.greetingservice;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import org.springframework.boot.actuate.health.Health;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.boot.actuate.health.Status;
import static org.junit.jupiter.api.Assertions.*;
import org.springframework.test.util.ReflectionTestUtils;
class MyCustomHealthCheckTest {
@@ -16,7 +17,7 @@ class MyCustomHealthCheckTest {
Health health = healthCheck.health();
assertEquals(Status.UP, health.getStatus());
assertTrue(health.getDetails().containsKey("message"));
assertEquals("Service is running and scheduled checks are OK", health.getDetails().get("message"));
assertEquals(
"Service is running and scheduled checks are OK", health.getDetails().get("message"));
}
}
}
@@ -16,21 +16,23 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
@ActiveProfiles("test")
class GreetingControllerTest {
@Autowired
private MockMvc mockMvc;
@Autowired private MockMvc mockMvc;
@Test
void shouldReturnGreeting() throws Exception{
mockMvc.perform(MockMvcRequestBuilders.get("/greeting")
.accept(MediaType.TEXT_PLAIN))
void shouldReturnGreeting() throws Exception {
mockMvc
.perform(MockMvcRequestBuilders.get("/greeting").accept(MediaType.TEXT_PLAIN))
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.content().string("Hello"));
}
@Test
void shouldReturnHealthStatusUp() throws Exception{
mockMvc.perform(MockMvcRequestBuilders.get("/actuator/health"))
void shouldReturnHealthStatusUp() throws Exception {
mockMvc
.perform(MockMvcRequestBuilders.get("/actuator/health"))
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.content().string(org.hamcrest.Matchers.containsString("\"status\":\"UP\"")));
.andExpect(
MockMvcResultMatchers.content()
.string(org.hamcrest.Matchers.containsString("\"status\":\"UP\"")));
}
}
@@ -4,10 +4,8 @@ import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;
/**
* Token Bucket rate limiter implementation. Allows requests to proceed as long
* as there are tokens
* available in the bucket. Tokens are added at a fixed interval up to a defined
* capacity.
* Token Bucket rate limiter implementation. Allows requests to proceed as long as there are tokens
* available in the bucket. Tokens are added at a fixed interval up to a defined capacity.
*/
public class TokenBucketRateLimiter implements RateLimiter {
private final int capacity;
@@ -22,10 +20,10 @@ public class TokenBucketRateLimiter implements RateLimiter {
/**
* Constructor with custom refill interval.
*
* @param capacity token bucket capacity
* @param refillRate token refill rate
* @param capacity token bucket capacity
* @param refillRate token refill rate
* @param refillInterval refill interval value
* @param timeUnit refill interval time unit
* @param timeUnit refill interval time unit
*/
public TokenBucketRateLimiter(
int capacity, int refillRate, long refillInterval, TimeUnit timeUnit) {
@@ -53,10 +51,7 @@ public class TokenBucketRateLimiter implements RateLimiter {
buckets.forEach((k, b) -> b.refill(refillRate));
}
/**
* Inner class that represents the bucket holding tokens for each
* service-operation.
*/
/** Inner class that represents the bucket holding tokens for each service-operation. */
private static class TokenBucket {
private final int capacity;
private final AtomicInteger tokens;
@@ -69,10 +64,8 @@ public class TokenBucketRateLimiter implements RateLimiter {
boolean tryConsume() {
while (true) {
int current = tokens.get();
if (current <= 0)
return false;
if (tokens.compareAndSet(current, current - 1))
return true;
if (current <= 0) return false;
if (tokens.compareAndSet(current, current - 1)) return true;
}
}