暂存提交
This commit is contained in:
+16
-5
@@ -1,6 +1,7 @@
|
||||
package com.baiyue.warehouse.service;
|
||||
|
||||
import com.baiyue.common.core.exception.BizException;
|
||||
import com.baiyue.common.core.api.ResultCode;
|
||||
import com.baiyue.warehouse.entity.WarehouseEntity;
|
||||
import com.baiyue.warehouse.repository.WarehouseRepository;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
@@ -16,19 +17,29 @@ class WarehouseApplicationServiceTest {
|
||||
void shouldReturnOnlyActiveTenantOwnedWarehouseForMerchantDetail() {
|
||||
WarehouseRepository repository=mock(WarehouseRepository.class);
|
||||
WarehouseEntity warehouse=new WarehouseEntity(); warehouse.setId(1L); warehouse.setTenantId(10001L); warehouse.setStatus("ACTIVE");
|
||||
when(repository.findActiveOwned(10001,1)).thenReturn(warehouse);
|
||||
when(repository.findOwned(10001,1)).thenReturn(warehouse);
|
||||
when(repository.findAddresses(10001,1)).thenReturn(java.util.List.of());
|
||||
when(repository.findCapabilities(10001,1)).thenReturn(java.util.List.of());
|
||||
WarehouseApplicationService service=new WarehouseApplicationService(); ReflectionTestUtils.setField(service,"repository",repository);
|
||||
assertThat(service.activeDetail(10001,1).warehouse()).isSameAs(warehouse);
|
||||
verify(repository).findActiveOwned(10001,1);
|
||||
verify(repository).findOwned(10001,1);
|
||||
}
|
||||
@Test
|
||||
@DisplayName("停用或跨租户仓库按不存在处理")
|
||||
void shouldTreatInactiveOrCrossTenantWarehouseAsNotFound() {
|
||||
@DisplayName("跨租户或不存在仓库返回 404")
|
||||
void shouldTreatMissingOrCrossTenantWarehouseAsNotFound() {
|
||||
WarehouseRepository repository=mock(WarehouseRepository.class);
|
||||
WarehouseApplicationService service=new WarehouseApplicationService(); ReflectionTestUtils.setField(service,"repository",repository);
|
||||
assertThatThrownBy(() -> service.activeDetail(10002,1)).isInstanceOf(BizException.class)
|
||||
.hasMessageContaining("停用");
|
||||
.extracting(exception -> ((BizException) exception).getResultCode()).isEqualTo(ResultCode.NOT_FOUND);
|
||||
}
|
||||
@Test
|
||||
@DisplayName("停用仓库返回 409")
|
||||
void shouldTreatInactiveWarehouseAsConflict() {
|
||||
WarehouseRepository repository=mock(WarehouseRepository.class);
|
||||
WarehouseEntity warehouse=new WarehouseEntity(); warehouse.setId(1L); warehouse.setTenantId(10001L); warehouse.setStatus("INACTIVE");
|
||||
when(repository.findOwned(10001,1)).thenReturn(warehouse);
|
||||
WarehouseApplicationService service=new WarehouseApplicationService(); ReflectionTestUtils.setField(service,"repository",repository);
|
||||
assertThatThrownBy(() -> service.activeDetail(10001,1)).isInstanceOf(BizException.class)
|
||||
.extracting(exception -> ((BizException) exception).getResultCode()).isEqualTo(ResultCode.CONFLICT);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user