parent
7ecda3d53a
commit
ba952bb1f8
@ -0,0 +1,5 @@
|
|||||||
|
spring.application.name=Recruit
|
||||||
|
# Development properties
|
||||||
|
server.port=8080
|
||||||
|
logging.level.root=DEBUG
|
||||||
|
|
@ -0,0 +1,4 @@
|
|||||||
|
spring.application.name=Recruit
|
||||||
|
# Production properties
|
||||||
|
server.port=80
|
||||||
|
logging.level.root=INFO
|
@ -0,0 +1,11 @@
|
|||||||
|
spring.application.name=Recruit
|
||||||
|
# Common properties
|
||||||
|
spring.datasource.url=jdbc:mysql://localhost:3306/ahbvcrefactor
|
||||||
|
spring.datasource.username=root
|
||||||
|
spring.datasource.password=root
|
||||||
|
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
||||||
|
|
||||||
|
mybatis.mapper-locations=classpath:mapper/*.xml
|
||||||
|
# Development specific properties
|
||||||
|
spring.profiles.active=dev
|
||||||
|
|
@ -0,0 +1,13 @@
|
|||||||
|
package edu.ahbvc.recruit;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
|
@SpringBootTest
|
||||||
|
class RecruitApplicationTests {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void contextLoads() {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,109 @@
|
|||||||
|
package edu.ahbvc.recruit.service;
|
||||||
|
|
||||||
|
import edu.ahbvc.recruit.mapper.AdminInter;
|
||||||
|
import edu.ahbvc.recruit.model.Admin;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.InjectMocks;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.junit.MockitoJUnitRunner;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
|
public class AdminServiceTest {
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private AdminInter mapper;
|
||||||
|
|
||||||
|
@InjectMocks
|
||||||
|
private AdminServiceImpl adminService;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
// 初始化操作可以放在这里
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetAdmins_WithAllParameters() {
|
||||||
|
// 准备测试数据
|
||||||
|
List<Admin> expectedAdmins = Arrays.asList(
|
||||||
|
new Admin(),
|
||||||
|
new Admin()
|
||||||
|
);
|
||||||
|
|
||||||
|
// 设置mock行为
|
||||||
|
when(mapper.getAdmins(0, 10, "admin", "13800138000"))
|
||||||
|
.thenReturn(expectedAdmins);
|
||||||
|
|
||||||
|
// 调用测试方法
|
||||||
|
List<Admin> result = adminService.getAdmins(0, 10, "admin", "13800138000");
|
||||||
|
|
||||||
|
// 验证结果
|
||||||
|
assertEquals(expectedAdmins, result);
|
||||||
|
verify(mapper).getAdmins(0, 10, "admin", "13800138000");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetAdmins_WithNameOnly() {
|
||||||
|
List<Admin> expectedAdmins = Arrays.asList(
|
||||||
|
new Admin( )
|
||||||
|
);
|
||||||
|
|
||||||
|
when(mapper.getAdmins(0, 10, "admin", null))
|
||||||
|
.thenReturn(expectedAdmins);
|
||||||
|
|
||||||
|
List<Admin> result = adminService.getAdmins(0, 10, "admin", null);
|
||||||
|
|
||||||
|
assertEquals(expectedAdmins, result);
|
||||||
|
verify(mapper).getAdmins(0, 10, "admin", null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetAdmins_WithPhoneOnly() {
|
||||||
|
List<Admin> expectedAdmins = Arrays.asList(
|
||||||
|
new Admin()
|
||||||
|
);
|
||||||
|
|
||||||
|
when(mapper.getAdmins(0, 10, null, "13800138001"))
|
||||||
|
.thenReturn(expectedAdmins);
|
||||||
|
|
||||||
|
List<Admin> result = adminService.getAdmins(0, 10, null, "13800138001");
|
||||||
|
|
||||||
|
assertEquals(expectedAdmins, result);
|
||||||
|
verify(mapper).getAdmins(0, 10, null, "13800138001");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetAdmins_WithNoFilters() {
|
||||||
|
List<Admin> expectedAdmins = Arrays.asList(
|
||||||
|
new Admin(),
|
||||||
|
new Admin()
|
||||||
|
);
|
||||||
|
|
||||||
|
when(mapper.getAdmins(0, 10, null, null))
|
||||||
|
.thenReturn(expectedAdmins);
|
||||||
|
|
||||||
|
List<Admin> result = adminService.getAdmins(0, 10, null, null);
|
||||||
|
|
||||||
|
assertEquals(expectedAdmins, result);
|
||||||
|
verify(mapper).getAdmins(0, 10, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetAdmins_EmptyResult() {
|
||||||
|
when(mapper.getAdmins(0, 10, "nonexistent", "00000000000"))
|
||||||
|
.thenReturn(Arrays.asList());
|
||||||
|
|
||||||
|
List<Admin> result = adminService.getAdmins(0, 10, "nonexistent", "00000000000");
|
||||||
|
|
||||||
|
assertTrue(result.isEmpty());
|
||||||
|
verify(mapper).getAdmins(0, 10, "nonexistent", "00000000000");
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue