Skip to content

Commit 84b6676

Browse files
committed
changes for unit tests
1 parent edb73c1 commit 84b6676

File tree

2 files changed

+0
-41
lines changed

2 files changed

+0
-41
lines changed

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

-14
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,4 @@ void testHealthDown() {
4040
assertEquals("Scheduled health checks failed", health.getDetails().get("error"));
4141
}
4242

43-
@Test
44-
void testUpdateHealthStatusSetsIsHealthyWithMocking() throws Exception {
45-
MyCustomHealthCheck healthCheck = Mockito.spy(new MyCustomHealthCheck());
46-
47-
// Force performHealthCheck to return true
48-
doReturn(true).when(healthCheck).performHealthCheck();
49-
healthCheck.updateHealthStatus();
50-
assertTrue((Boolean)ReflectionTestUtils.getField(healthCheck, "isHealthy"), "Health should be true");
51-
52-
// Force performHealthCheck to return false
53-
doReturn(false).when(healthCheck).performHealthCheck();
54-
healthCheck.updateHealthStatus();
55-
assertFalse((Boolean)ReflectionTestUtils.getField(healthCheck, "isHealthy"), "Health should be false");
56-
}
5743
}

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

-27
Original file line numberDiff line numberDiff line change
@@ -24,31 +24,4 @@ void testHealthUp() {
2424
assertEquals("Service is running and scheduled checks are OK", health.getDetails().get("message"));
2525
}
2626

27-
@Test
28-
void testHealthDown() {
29-
MyCustomHealthCheck healthCheck = new MyCustomHealthCheck();
30-
// Simulate an unhealthy state
31-
ReflectionTestUtils.setField(healthCheck, "isHealthy", false);
32-
Health health = healthCheck.health();
33-
assertEquals(Status.DOWN, health.getStatus());
34-
assertTrue(health.getDetails().containsKey("error"));
35-
assertEquals("Scheduled health checks failed", health.getDetails().get("error"));
36-
}
37-
38-
@Test
39-
void testUpdateHealthStatusSetsIsHealthyWithMocking() throws Exception {
40-
MyCustomHealthCheck healthCheck = Mockito.spy(new MyCustomHealthCheck());
41-
42-
// Force performHealthCheck to return true
43-
doReturn(true).when(healthCheck).performHealthCheck();
44-
healthCheck.updateHealthStatus();
45-
assertTrue((Boolean) ReflectionTestUtils.getField(healthCheck, "isHealthy"),
46-
"Health should be true");
47-
48-
// Force performHealthCheck to return false
49-
doReturn(false).when(healthCheck).performHealthCheck();
50-
healthCheck.updateHealthStatus();
51-
assertFalse((Boolean) ReflectionTestUtils.getField(healthCheck, "isHealthy"),
52-
"Health should be false");
53-
}
5427
}

0 commit comments

Comments
 (0)