package com.zy.asrs.service.impl;
|
|
import com.zy.asrs.entity.BasCrnp;
|
import com.zy.asrs.mapper.BasCrnpMapper;
|
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 org.springframework.test.util.ReflectionTestUtils;
|
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.mockito.Mockito.when;
|
|
@ExtendWith(MockitoExtension.class)
|
class BasCrnpServiceImplTest {
|
|
@Mock
|
private BasCrnpMapper basCrnpMapper;
|
|
private BasCrnpServiceImpl service;
|
|
@BeforeEach
|
void setUp() {
|
service = new BasCrnpServiceImpl();
|
ReflectionTestUtils.setField(service, "baseMapper", basCrnpMapper);
|
}
|
|
@Test
|
void checkSiteError_shouldRejectNullInboundFlag() {
|
BasCrnp basCrnp = buildCrnp(null, "Y");
|
when(basCrnpMapper.selectById(22)).thenReturn(basCrnp);
|
|
assertFalse(service.checkSiteError(22, true));
|
}
|
|
@Test
|
void checkSiteError_shouldAllowExplicitInboundFlagY() {
|
BasCrnp basCrnp = buildCrnp("Y", "Y");
|
when(basCrnpMapper.selectById(22)).thenReturn(basCrnp);
|
|
assertTrue(service.checkSiteError(22, true));
|
}
|
|
@Test
|
void checkSiteStatus_shouldRejectNullInboundFlag() {
|
BasCrnp basCrnp = buildCrnp(null, "Y");
|
when(basCrnpMapper.selectById(22)).thenReturn(basCrnp);
|
|
assertThrows(RuntimeException.class, () -> service.checkSiteStatus(22));
|
}
|
|
private BasCrnp buildCrnp(String inEnable, String outEnable) {
|
BasCrnp basCrnp = new BasCrnp();
|
basCrnp.setCrnNo(22);
|
basCrnp.setCrnSts(3);
|
basCrnp.setCrnErr(0L);
|
basCrnp.setInEnable(inEnable);
|
basCrnp.setOutEnable(outEnable);
|
return basCrnp;
|
}
|
}
|