This commit is contained in:
2026-08-12 12:18:59 +08:00
parent 5a26a84f78
commit 0fceece378
8 changed files with 113 additions and 31 deletions
@@ -18,6 +18,7 @@ import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import java.util.List;
import java.math.BigDecimal;
import java.util.concurrent.Callable;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executors;
@@ -57,20 +58,20 @@ class MeasurementReviewServiceTest {
.isEqualTo(ResultCode.NOT_FOUND);
verify(repository).findOwned(10002L, 10L);
verify(repository, never()).transitionReview(anyLong(), anyLong(), anyLong(), anyInt(), anyBoolean());
verify(repository, never()).transitionReview(anyLong(), anyLong(), anyLong(), anyInt(), anyBoolean(), anyLong());
}
@Test
@DisplayName("审核通过是测量到计费的唯一正常推进关口")
void shouldApproveOnlyPendingSubmittedMeasurement() {
Fixture fixture = fixture(false);
when(fixture.repository.transitionReview(10001L, 10L, 9L, 3, true)).thenReturn(1);
when(fixture.repository.transitionReview(10001L, 10L, 9L, 3, true, 20L)).thenReturn(1);
when(fixture.repository.transitionMeasurement(10001L, 10L, 20L, "APPROVED")).thenReturn(1);
fixture.service.approve(10001L, 9L, "审核员", 10L, "approve-1",
new MeasurementReviewRequest(20L, 3, null));
verify(fixture.repository).transitionReview(10001L, 10L, 9L, 3, true);
verify(fixture.repository).transitionReview(10001L, 10L, 9L, 3, true, 20L);
verify(fixture.repository).transitionMeasurement(10001L, 10L, 20L, "APPROVED");
verify(fixture.repository).insertReview(any());
ArgumentCaptor<InboundStatusHistoryEntity> history =
@@ -94,7 +95,7 @@ class MeasurementReviewServiceTest {
.extracting(error -> ((BizException) error).getResultCode())
.isEqualTo(ResultCode.VALIDATION_FAILED);
verify(fixture.repository, never()).transitionReview(anyLong(), anyLong(), anyLong(), anyInt(), anyBoolean());
verify(fixture.repository, never()).transitionReview(anyLong(), anyLong(), anyLong(), anyInt(), anyBoolean(), anyLong());
}
@Test
@@ -106,7 +107,7 @@ class MeasurementReviewServiceTest {
.isInstanceOf(BizException.class)
.extracting(error -> ((BizException) error).getResultCode())
.isEqualTo(ResultCode.VALIDATION_FAILED);
verify(fixture.repository, never()).transitionReview(anyLong(), anyLong(), anyLong(), anyInt(), anyBoolean());
verify(fixture.repository, never()).transitionReview(anyLong(), anyLong(), anyLong(), anyInt(), anyBoolean(), anyLong());
}
@Test
@@ -120,7 +121,7 @@ class MeasurementReviewServiceTest {
new MeasurementReviewRequest(20L, 3, null));
verify(fixture.repository, never()).findOwned(anyLong(), anyLong());
verify(fixture.repository, never()).transitionReview(anyLong(), anyLong(), anyLong(), anyInt(), anyBoolean());
verify(fixture.repository, never()).transitionReview(anyLong(), anyLong(), anyLong(), anyInt(), anyBoolean(), anyLong());
}
@Test
@@ -158,7 +159,7 @@ class MeasurementReviewServiceTest {
Fixture fixture = fixture(false);
AtomicInteger attempts = new AtomicInteger();
CountDownLatch bothArrived = new CountDownLatch(2);
when(fixture.repository.transitionReview(anyLong(), anyLong(), anyLong(), anyInt(), anyBoolean()))
when(fixture.repository.transitionReview(anyLong(), anyLong(), anyLong(), anyInt(), anyBoolean(), anyLong()))
.thenAnswer(invocation -> {
bothArrived.countDown();
bothArrived.await();
@@ -199,6 +200,9 @@ class MeasurementReviewServiceTest {
measurement.setStatus("SUBMITTED");
InboundMeasurementItemEntity item = new InboundMeasurementItemEntity();
item.setPackageCount(5);
item.setTotalWeightKg(new BigDecimal("54.400"));
item.setTotalVolumeCbm(new BigDecimal("0.7480"));
item.setVolumeWeightKg(new BigDecimal("124.916"));
when(repository.findOwned(10001L, 10L)).thenReturn(order);
when(repository.findMeasurement(10001L, 10L, 20L)).thenReturn(measurement);
when(repository.listMeasurementItems(10001L, 20L)).thenReturn(List.of(item));