-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathHealthControllerTest.java
More file actions
52 lines (40 loc) · 1.7 KB
/
HealthControllerTest.java
File metadata and controls
52 lines (40 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/**
* Copyright (c) 2025, Samsung Electronics Co., Ltd. All rights reserved.
*
* Use of this source code is governed by a MIT license that can be
* found in the LICENSE file.
*/
package com.lpvs.controller;
import com.lpvs.repository.LPVSQueueRepository;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.when;
@ExtendWith(MockitoExtension.class)
public class HealthControllerTest {
@Mock private LPVSQueueRepository queueRepository;
@InjectMocks private HealthController healthController;
@Test
public void testGetHealthStatus_Success_EmptyQueue() {
when(queueRepository.count()).thenReturn(0L);
ResponseEntity<Map<String, Long>> response = healthController.getHealthStatus();
assertEquals(HttpStatus.OK, response.getStatusCode());
Map<String, Long> responseBody = response.getBody();
assertEquals(0L, responseBody.get("queueLength"));
}
@Test
public void testGetHealthStatus_Success_WithItems() {
long expectedQueueLength = 5L;
when(queueRepository.count()).thenReturn(expectedQueueLength);
ResponseEntity<Map<String, Long>> response = healthController.getHealthStatus();
assertEquals(HttpStatus.OK, response.getStatusCode());
Map<String, Long> responseBody = response.getBody();
assertEquals(expectedQueueLength, responseBody.get("queueLength"));
}
}