diff --git a/src/main/resources/application-dev.properties b/src/main/resources/application-dev.properties new file mode 100644 index 0000000..9e337f3 --- /dev/null +++ b/src/main/resources/application-dev.properties @@ -0,0 +1,5 @@ +spring.application.name=Recruit +# Development properties +server.port=8080 +logging.level.root=DEBUG + diff --git a/src/main/resources/application-prod.properties b/src/main/resources/application-prod.properties new file mode 100644 index 0000000..8b4edf1 --- /dev/null +++ b/src/main/resources/application-prod.properties @@ -0,0 +1,4 @@ +spring.application.name=Recruit +# Production properties +server.port=80 +logging.level.root=INFO \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties new file mode 100644 index 0000000..fc7a5ae --- /dev/null +++ b/src/main/resources/application.properties @@ -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 + diff --git a/src/test/java/edu/hfnu/recruit/RecruitApplicationTests.java b/src/test/java/edu/hfnu/recruit/RecruitApplicationTests.java new file mode 100644 index 0000000..f7937e0 --- /dev/null +++ b/src/test/java/edu/hfnu/recruit/RecruitApplicationTests.java @@ -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() { + } + +} diff --git a/src/test/java/edu/hfnu/recruit/service/AdminServiceTest.java b/src/test/java/edu/hfnu/recruit/service/AdminServiceTest.java new file mode 100644 index 0000000..500cccd --- /dev/null +++ b/src/test/java/edu/hfnu/recruit/service/AdminServiceTest.java @@ -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 expectedAdmins = Arrays.asList( + new Admin(), + new Admin() + ); + + // 设置mock行为 + when(mapper.getAdmins(0, 10, "admin", "13800138000")) + .thenReturn(expectedAdmins); + + // 调用测试方法 + List result = adminService.getAdmins(0, 10, "admin", "13800138000"); + + // 验证结果 + assertEquals(expectedAdmins, result); + verify(mapper).getAdmins(0, 10, "admin", "13800138000"); + } + + @Test + public void testGetAdmins_WithNameOnly() { + List expectedAdmins = Arrays.asList( + new Admin( ) + ); + + when(mapper.getAdmins(0, 10, "admin", null)) + .thenReturn(expectedAdmins); + + List result = adminService.getAdmins(0, 10, "admin", null); + + assertEquals(expectedAdmins, result); + verify(mapper).getAdmins(0, 10, "admin", null); + } + + @Test + public void testGetAdmins_WithPhoneOnly() { + List expectedAdmins = Arrays.asList( + new Admin() + ); + + when(mapper.getAdmins(0, 10, null, "13800138001")) + .thenReturn(expectedAdmins); + + List result = adminService.getAdmins(0, 10, null, "13800138001"); + + assertEquals(expectedAdmins, result); + verify(mapper).getAdmins(0, 10, null, "13800138001"); + } + + @Test + public void testGetAdmins_WithNoFilters() { + List expectedAdmins = Arrays.asList( + new Admin(), + new Admin() + ); + + when(mapper.getAdmins(0, 10, null, null)) + .thenReturn(expectedAdmins); + + List 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 result = adminService.getAdmins(0, 10, "nonexistent", "00000000000"); + + assertTrue(result.isEmpty()); + verify(mapper).getAdmins(0, 10, "nonexistent", "00000000000"); + } +}