提交
This commit is contained in:
+74
@@ -0,0 +1,74 @@
|
||||
package com.baiyue.lastleg.exceptionorder.service;
|
||||
|
||||
import com.baiyue.lastleg.entity.LastlegInboundOrder;
|
||||
import com.baiyue.lastleg.entity.LastlegOrder;
|
||||
import com.baiyue.lastleg.exceptionorder.mapper.ExceptionOrderMapper;
|
||||
import com.baiyue.lastleg.mapper.LastlegInboundOrderMapper;
|
||||
import com.baiyue.lastleg.mapper.LastlegOrderMapper;
|
||||
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 org.springframework.web.server.ResponseStatusException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class ExceptionOrderServiceTest {
|
||||
@Mock private ExceptionOrderMapper exceptionOrders;
|
||||
@Mock private LastlegOrderMapper lastMileOrders;
|
||||
@Mock private LastlegInboundOrderMapper inboundOrders;
|
||||
private ExceptionOrderService service;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
service = new ExceptionOrderService();
|
||||
ReflectionTestUtils.setField(service, "exceptionOrders", exceptionOrders);
|
||||
ReflectionTestUtils.setField(service, "lastMileOrders", lastMileOrders);
|
||||
ReflectionTestUtils.setField(service, "inboundOrders", inboundOrders);
|
||||
}
|
||||
|
||||
@Test
|
||||
void resolvesTheOneToOneInboundAndLastMileRelation() {
|
||||
LastlegOrder tail = tail("LM-1", "IN-1");
|
||||
LastlegInboundOrder inbound = inbound("IN-1");
|
||||
when(lastMileOrders.selectList(any())).thenReturn(List.of(tail));
|
||||
when(inboundOrders.selectList(any())).thenReturn(List.of(inbound));
|
||||
|
||||
var relation = service.resolve(null, null, "IN-1", "LM-1");
|
||||
|
||||
assertThat(relation.lastMileOrderNo()).isEqualTo("LM-1");
|
||||
assertThat(relation.inboundCode()).isEqualTo("IN-1");
|
||||
assertThat(relation.customerId()).isEqualTo("1001");
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectsInputsThatExistButDoNotBelongTogether() {
|
||||
when(lastMileOrders.selectList(any())).thenReturn(List.of(tail("LM-1", "IN-1")));
|
||||
when(inboundOrders.selectList(any())).thenReturn(List.of(inbound("IN-2")));
|
||||
|
||||
assertThatThrownBy(() -> service.resolve(null, null, "IN-2", "LM-1"))
|
||||
.isInstanceOf(ResponseStatusException.class)
|
||||
.hasMessageContaining("不是同一关联关系");
|
||||
}
|
||||
|
||||
private LastlegOrder tail(String orderNo, String inboundCode) {
|
||||
LastlegOrder value = new LastlegOrder();
|
||||
value.setId(12L); value.setCustomerId("1001"); value.setOrderNo(orderNo); value.setInboundCode(inboundCode);
|
||||
value.setCustomerName("测试客户"); value.setPackageCount(10);
|
||||
return value;
|
||||
}
|
||||
|
||||
private LastlegInboundOrder inbound(String inboundCode) {
|
||||
LastlegInboundOrder value = new LastlegInboundOrder();
|
||||
value.setId(11L); value.setCustomerId("1001"); value.setInboundCode(inboundCode); value.setPackageCount(10);
|
||||
return value;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user