| package com.g9.g9backend.controller; |
| |
| import com.g9.g9backend.service.ResourceService; |
| import com.g9.g9backend.service.ThreadService; |
| import com.g9.g9backend.service.UserPurchaseService; |
| import com.g9.g9backend.service.UserUploadService; |
| import org.junit.jupiter.api.Test; |
| import org.mockito.InjectMocks; |
| import org.mockito.Mock; |
| |
| import static org.junit.jupiter.api.Assertions.*; |
| import static org.mockito.Mockito.*; |
| |
| import org.junit.jupiter.api.extension.ExtendWith; |
| import org.mockito.junit.jupiter.MockitoExtension; |
| import org.springframework.http.ResponseEntity; |
| |
| @ExtendWith(MockitoExtension.class) |
| public class TotalControllerTest { |
| |
| @Mock |
| private ThreadService threadService; |
| |
| @Mock |
| private UserPurchaseService userPurchaseService; |
| |
| @Mock |
| private UserUploadService userUploadService; |
| |
| @Mock |
| private ResourceService resourceService; |
| |
| @InjectMocks |
| private TotalController totalController; |
| |
| @Test |
| void testGetTotalInfo() { |
| when(threadService.count()).thenReturn(10L); |
| when(userPurchaseService.count()).thenReturn(20L); |
| when(userUploadService.count()).thenReturn(5L); |
| when(resourceService.count()).thenReturn(50L); |
| |
| ResponseEntity<TotalController.Info> response = totalController.getTotalInfo(); |
| |
| assertEquals(200, response.getStatusCode().value()); |
| TotalController.Info info = response.getBody(); |
| assertNotNull(info); |
| assertEquals(10L, info.getThreadCount()); |
| assertEquals(20L, info.getDownloadCount()); |
| assertEquals(5L, info.getAuthorCount()); |
| assertEquals(50L, info.getResourceCount()); |
| } |
| } |