package com.tcm.training.admin.app.live.service;
|
|
import com.baomidou.mybatisplus.core.MybatisConfiguration;
|
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
|
import com.tcm.training.admin.app.live.vo.AppLiveExpertVO;
|
import com.tcm.training.admin.live.entity.Expert;
|
import com.tcm.training.admin.live.mapper.ExpertMapper;
|
import org.apache.ibatis.builder.MapperBuilderAssistant;
|
import org.junit.jupiter.api.BeforeAll;
|
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.mockito.Mock;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.Mockito.when;
|
|
/**
|
* APP 养生直播专家服务测试。
|
*/
|
@ExtendWith(MockitoExtension.class)
|
class AppLiveExpertServiceTest {
|
|
@BeforeAll
|
static void initLambdaCache() {
|
MapperBuilderAssistant assistant = new MapperBuilderAssistant(new MybatisConfiguration(), "");
|
TableInfoHelper.initTableInfo(assistant, Expert.class);
|
}
|
|
@Mock
|
private ExpertMapper expertMapper;
|
|
private AppLiveExpertService appLiveExpertService;
|
|
/**
|
* 每个用例前重建被测服务。
|
*/
|
@BeforeEach
|
void setUp() {
|
appLiveExpertService = new AppLiveExpertService(expertMapper);
|
}
|
|
/**
|
* 已启用专家应返回 APP 端详情。
|
*/
|
@Test
|
void detailShouldReturnEnabledExpert() {
|
Expert expert = new Expert();
|
expert.setId(1L);
|
expert.setName("张雨泽");
|
expert.setAvatar("https://cdn.example/avatar.png");
|
expert.setSpecialty("养生调理");
|
expert.setIntro("专家介绍");
|
expert.setStatus(1);
|
when(expertMapper.selectOne(any())).thenReturn(expert);
|
|
AppLiveExpertVO expertVO = appLiveExpertService.detail(1L);
|
|
assertEquals(Long.valueOf(1L), expertVO.getId());
|
assertEquals("张雨泽", expertVO.getName());
|
assertEquals("养生调理", expertVO.getSpecialty());
|
}
|
|
/**
|
* 禁用或不存在的专家应返回统一错误。
|
*/
|
@Test
|
void detailShouldFailWhenExpertMissing() {
|
when(expertMapper.selectOne(any())).thenReturn(null);
|
|
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class,
|
() -> appLiveExpertService.detail(99L));
|
|
assertEquals("授课专家不存在", exception.getMessage());
|
}
|
}
|