mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-10-04 22:13:44 +00:00
fix: spotless formatting fixes
This commit is contained in:
1 parent
c317ce012a
commit
2dfb27c859
17 files changed
+141
-79
No files matched your search
@@ -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>
|
||||
|
||||
|
||||
+3
-4
@@ -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);
|
||||
}
|
||||
}
|
||||
+3
-2
@@ -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();
|
||||
|
||||
+3
-2
@@ -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;
|
||||
}
|
||||
}
|
||||
+12
-11
@@ -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\"")));
|
||||
}
|
||||
}
|
||||
+7
-6
@@ -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.
|
||||
}
|
||||
}
|
||||
+6
-5
@@ -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>
|
||||
|
||||
|
||||
+3
-4
@@ -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);
|
||||
}
|
||||
}
|
||||
+7
-6
@@ -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>
|
||||
|
||||
|
||||
+3
-4
@@ -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);
|
||||
}
|
||||
}
|
||||
+3
-1
@@ -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();
|
||||
|
||||
+7
-6
@@ -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.
|
||||
}
|
||||
}
|
||||
+6
-5
@@ -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"));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+10
-8
@@ -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\"")));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user