优化布局
This commit is contained in:
+50
@@ -0,0 +1,50 @@
|
||||
package com.nanri.aiimage.modules.shopkey.service;
|
||||
|
||||
import com.nanri.aiimage.common.exception.BusinessException;
|
||||
import com.nanri.aiimage.common.security.ShopCredentialCryptoService;
|
||||
import com.nanri.aiimage.modules.shopkey.mapper.ShopManageMapper;
|
||||
import com.nanri.aiimage.modules.shopkey.model.entity.ShopManageEntity;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
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.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class ShopManageServiceTest {
|
||||
|
||||
@Mock
|
||||
private ShopManageMapper shopManageMapper;
|
||||
@Mock
|
||||
private ShopManageGroupService shopManageGroupService;
|
||||
@Mock
|
||||
private ShopCredentialCryptoService shopCredentialCryptoService;
|
||||
|
||||
@InjectMocks
|
||||
private ShopManageService service;
|
||||
|
||||
@Test
|
||||
void requireShopByNameReturnsManagedShop() {
|
||||
ShopManageEntity entity = new ShopManageEntity();
|
||||
entity.setShopName("测试店铺");
|
||||
when(shopManageMapper.selectOne(any())).thenReturn(entity);
|
||||
|
||||
assertSame(entity, service.requireShopByName(" 测试店铺 "));
|
||||
}
|
||||
|
||||
@Test
|
||||
void requireShopByNameReturnsChineseErrorWhenMissing() {
|
||||
when(shopManageMapper.selectOne(any())).thenReturn(null);
|
||||
|
||||
BusinessException exception = assertThrows(BusinessException.class,
|
||||
() -> service.requireShopByName("缺失店铺"));
|
||||
|
||||
assertEquals("后台店铺管理中未找到店铺:缺失店铺,请先添加店铺信息", exception.getMessage());
|
||||
}
|
||||
}
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
package com.nanri.aiimage.modules.ziniao.service;
|
||||
|
||||
import com.nanri.aiimage.common.exception.BusinessException;
|
||||
import com.nanri.aiimage.modules.shopkey.service.ShopManageService;
|
||||
import com.nanri.aiimage.modules.ziniao.model.vo.ZiniaoShopMatchResultVo;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InOrder;
|
||||
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.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.Mockito.inOrder;
|
||||
import static org.mockito.Mockito.verifyNoInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class ZiniaoShopSwitchServiceTest {
|
||||
|
||||
@Mock
|
||||
private ZiniaoAuthService ziniaoAuthService;
|
||||
@Mock
|
||||
private ZiniaoShopIndexService ziniaoShopIndexService;
|
||||
@Mock
|
||||
private ShopManageService shopManageService;
|
||||
|
||||
@Test
|
||||
void missingManagedShopStopsIndexedLookup() {
|
||||
String message = "后台店铺管理中未找到店铺:缺失店铺,请先添加店铺信息";
|
||||
when(shopManageService.requireShopByName("缺失店铺"))
|
||||
.thenThrow(new BusinessException(message));
|
||||
ZiniaoShopSwitchService service = new ZiniaoShopSwitchService(
|
||||
ziniaoAuthService, ziniaoShopIndexService, shopManageService);
|
||||
|
||||
BusinessException exception = assertThrows(BusinessException.class,
|
||||
() -> service.findIndexedStoreByName("缺失店铺", false));
|
||||
|
||||
assertEquals(message, exception.getMessage());
|
||||
verifyNoInteractions(ziniaoShopIndexService);
|
||||
}
|
||||
|
||||
@Test
|
||||
void managedShopIsCheckedBeforeIndexedLookup() {
|
||||
ZiniaoShopMatchResultVo expected = new ZiniaoShopMatchResultVo();
|
||||
expected.setMatched(true);
|
||||
when(ziniaoShopIndexService.findIndexedStoreByName("测试店铺", false)).thenReturn(expected);
|
||||
ZiniaoShopSwitchService service = new ZiniaoShopSwitchService(
|
||||
ziniaoAuthService, ziniaoShopIndexService, shopManageService);
|
||||
|
||||
ZiniaoShopMatchResultVo actual = service.findIndexedStoreByName(" 测试店铺 ", false);
|
||||
|
||||
assertSame(expected, actual);
|
||||
InOrder order = inOrder(shopManageService, ziniaoShopIndexService);
|
||||
order.verify(shopManageService).requireShopByName("测试店铺");
|
||||
order.verify(ziniaoShopIndexService).findIndexedStoreByName("测试店铺", false);
|
||||
}
|
||||
|
||||
@Test
|
||||
void missingManagedShopStopsDirectStaffMatch() {
|
||||
when(shopManageService.requireShopByName("缺失店铺"))
|
||||
.thenThrow(new BusinessException("后台店铺管理中未找到店铺:缺失店铺,请先添加店铺信息"));
|
||||
ZiniaoShopSwitchService service = new ZiniaoShopSwitchService(
|
||||
ziniaoAuthService, ziniaoShopIndexService, shopManageService);
|
||||
|
||||
assertThrows(BusinessException.class,
|
||||
() -> service.matchStoreByNameAcrossStaff("缺失店铺", 12L));
|
||||
verifyNoInteractions(ziniaoAuthService);
|
||||
}
|
||||
|
||||
@Test
|
||||
void blankShopNameDoesNotQueryManagedShopOrZiniao() {
|
||||
ZiniaoShopSwitchService service = new ZiniaoShopSwitchService(
|
||||
ziniaoAuthService, ziniaoShopIndexService, shopManageService);
|
||||
|
||||
ZiniaoShopMatchResultVo result = service.findIndexedStoreByName(" ", false);
|
||||
|
||||
assertEquals(ZiniaoShopIndexService.MATCH_STATUS_PENDING, result.getMatchStatus());
|
||||
assertEquals("店铺名为空,无法匹配索引", result.getMatchMessage());
|
||||
verifyNoInteractions(shopManageService, ziniaoShopIndexService, ziniaoAuthService);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user