Skip to content

Commit fcf605d

Browse files
committed
changes to for code coverage improvement
1 parent 84b6676 commit fcf605d

File tree

9 files changed

+11
-23
lines changed

9 files changed

+11
-23
lines changed

microservices-self-registration/contextservice/src/main/java/com/learning/contextservice/MyCustomHealthCheck.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import org.springframework.boot.actuate.health.HealthIndicator;
77
import org.springframework.scheduling.annotation.Scheduled;
88
import org.springframework.stereotype.Component;
9-
import java.time.Clock;
9+
1010

1111
@Component("myCustomHealthCheck")
1212
public class MyCustomHealthCheck implements HealthIndicator {

microservices-self-registration/contextservice/src/main/java/com/learning/contextservice/client/GreetingServiceClient.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import org.springframework.cloud.openfeign.FeignClient;
44
import org.springframework.web.bind.annotation.GetMapping;
55

6-
@FeignClient(name="greetingservice")
6+
@FeignClient(name = "greetingservice")
77
public interface GreetingServiceClient {
88

99
@GetMapping("/greeting")

microservices-self-registration/contextservice/src/test/java/com/learning/contextservice/ContextControllerTest.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
package com.learning.contextservice;
22

33
import com.learning.contextservice.client.GreetingServiceClient;
4-
import com.learning.contextservice.controller.ContextController;
54
import org.hamcrest.Matchers;
65
import org.junit.jupiter.api.Test;
76
import org.mockito.Mockito;
87
import org.springframework.beans.factory.annotation.Autowired;
98
import org.springframework.beans.factory.annotation.Value;
109
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
11-
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
10+
1211
import org.springframework.boot.test.context.SpringBootTest;
1312
import org.springframework.context.annotation.Import;
1413
import org.springframework.http.MediaType;

microservices-self-registration/contextservice/src/test/java/com/learning/contextservice/myCustomHealthCheckTest.java

-10
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,13 @@
11
package com.learning.contextservice;
22

33
import org.junit.jupiter.api.Test;
4-
import org.mockito.Mockito;
54
import org.springframework.boot.actuate.health.Health;
65
import org.springframework.test.util.ReflectionTestUtils;
76
import org.springframework.boot.actuate.health.Status;
8-
9-
import java.time.Clock;
10-
import java.time.Instant;
11-
import java.time.ZoneId;
12-
import java.util.function.BooleanSupplier;
13-
147
import static org.junit.jupiter.api.Assertions.*;
15-
import static org.mockito.Mockito.doReturn;
168

179
class MyCustomHealthCheckTest {
1810

19-
MyCustomHealthCheck healthCheck = new MyCustomHealthCheck();
20-
2111
@Test
2212
void testHealthUp() {
2313
MyCustomHealthCheck healthCheck = new MyCustomHealthCheck();
Binary file not shown.

microservices-self-registration/greetingservice/src/main/java/com/learning/greetingservice/GreetingserviceApplication.java

+2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
import org.springframework.boot.SpringApplication;
44
import org.springframework.boot.autoconfigure.SpringBootApplication;
55
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
6+
import org.springframework.context.annotation.ComponentScan;
67

78
@SpringBootApplication
89
@EnableDiscoveryClient
10+
@ComponentScan("com.learning.greetingservice.controller")
911
public class GreetingserviceApplication {
1012

1113
public static void main(String[] args) {
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.learning.greetingservice;
1+
package com.learning.greetingservice.controller;
22

33
import org.springframework.web.bind.annotation.GetMapping;
44
import org.springframework.web.bind.annotation.RestController;
@@ -7,7 +7,7 @@
77
public class GreetingsController {
88

99
@GetMapping("/greeting")
10-
public String getGreeting(){
10+
public String getGreeting() {
1111
return "Hello";
1212
}
1313
}

microservices-self-registration/greetingservice/src/test/java/com/learning/greetingservice/MyCustomHealthCheckTest.java

-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
package com.learning.greetingservice;
22

33
import org.junit.jupiter.api.Test;
4-
import org.mockito.Mockito;
54
import org.springframework.boot.actuate.health.Health;
65
import org.springframework.test.util.ReflectionTestUtils;
76
import org.springframework.boot.actuate.health.Status;
8-
9-
import java.util.function.BooleanSupplier;
10-
117
import static org.junit.jupiter.api.Assertions.*;
12-
import static org.mockito.Mockito.doReturn;
138

149
class MyCustomHealthCheckTest {
1510

microservices-self-registration/greetingservice/src/test/java/com/learning/greetingservice/GreetingControllerTest.java microservices-self-registration/greetingservice/src/test/java/com/learning/greetingservice/controller/GreetingControllerTest.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
package com.learning.greetingservice;
1+
package com.learning.greetingservice.controller;
22

3+
import com.learning.greetingservice.GreetingserviceApplication;
34
import org.junit.jupiter.api.Test;
45
import org.springframework.beans.factory.annotation.Autowired;
56
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
6-
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
77
import org.springframework.boot.test.context.SpringBootTest;
88
import org.springframework.http.MediaType;
9+
import org.springframework.test.context.ActiveProfiles;
910
import org.springframework.test.web.servlet.MockMvc;
1011
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
1112
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
1213

1314
@SpringBootTest(classes = GreetingserviceApplication.class)
1415
@AutoConfigureMockMvc
16+
@ActiveProfiles("test")
1517
class GreetingControllerTest {
1618

1719
@Autowired

0 commit comments

Comments
 (0)