test(order): align batch draft service mocks

This commit is contained in:
2026-08-28 16:53:28 +08:00
parent 0ea4aeecc9
commit 0afe75379e
@@ -16,6 +16,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
@@ -30,7 +31,7 @@ class MerchantBatchDraftServiceTest {
void createsEachRowAndReturnsOrderReferences() {
doAnswer(invocation -> order(101L, "FL101", "RK-101"))
.doAnswer(invocation -> order(102L, "FL102", "RK-102"))
.when(itemService).create(anyLong(), anyLong(), any(), anyString());
.when(itemService).create(anyLong(), anyLong(), isNull(), any(), anyString());
var response = service.create(10L, 20L, "batch-key", List.of(
item("row-1"), item("row-2")));
@@ -48,7 +49,7 @@ class MerchantBatchDraftServiceTest {
void keepsSuccessfulRowsWhenAnotherRowFails() {
doAnswer(invocation -> order(101L, "FL101", "RK-101"))
.doThrow(new BizException("SKU不能为空"))
.when(itemService).create(anyLong(), anyLong(), any(), anyString());
.when(itemService).create(anyLong(), anyLong(), isNull(), any(), anyString());
var response = service.create(10L, 20L, "batch-key", List.of(
item("row-1"), item("row-2")));
@@ -63,7 +64,7 @@ class MerchantBatchDraftServiceTest {
@Test
void rejectsDuplicateRowWithoutCreatingItTwice() {
doAnswer(invocation -> order(101L, "FL101", "RK-101"))
.when(itemService).create(anyLong(), anyLong(), any(), anyString());
.when(itemService).create(anyLong(), anyLong(), isNull(), any(), anyString());
var response = service.create(10L, 20L, "batch-key", List.of(
item("same-row"), item("same-row")));
@@ -71,7 +72,7 @@ class MerchantBatchDraftServiceTest {
assertThat(response.succeeded()).isEqualTo(1);
assertThat(response.failed()).isEqualTo(1);
assertThat(response.items().get(1).errorCode()).isEqualTo("A0409");
verify(itemService).create(anyLong(), anyLong(), any(), anyString());
verify(itemService).create(anyLong(), anyLong(), isNull(), any(), anyString());
}
@Test
@@ -92,7 +93,7 @@ class MerchantBatchDraftServiceTest {
.isInstanceOf(BizException.class);
assertThatThrownBy(() -> service.create(10L, 20L, "batch-key", List.of()))
.isInstanceOf(BizException.class);
verify(itemService, never()).create(anyLong(), anyLong(), any(), anyString());
verify(itemService, never()).create(anyLong(), anyLong(), isNull(), any(), anyString());
}
private MerchantBatchDraftDtos.Item item(String rowId) {