This commit is contained in:
2026-09-15 14:30:47 +08:00
parent a474ca4d93
commit d1a00b8e01
18 changed files with 141 additions and 30 deletions
@@ -8,6 +8,7 @@ import com.baiyue.warehouse.entity.WarehousePalletEntity;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.springframework.cloud.client.circuitbreaker.NoFallbackAvailableException;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.test.util.ReflectionTestUtils;
@@ -66,6 +67,19 @@ class PalletLabelPrintServiceTest {
verifyNoInteractions(print);
}
@Test
void mapsCircuitBreakerWrappedPrintFailureToServiceUnavailable() {
when(print.generateInboundMarks(anyString(), anyString(), any()))
.thenThrow(new NoFallbackAvailableException("No fallback available.",
new IllegalStateException("No instances available for print-service")));
assertThatThrownBy(() -> service.print(200L, 9L, "request-1"))
.isInstanceOfSatisfying(BizException.class, exception -> {
assertThat(exception.getResultCode()).isEqualTo(ResultCode.SERVICE_UNAVAILABLE);
assertThat(exception.getMessage()).contains("打印服务暂不可用");
});
}
@Test
void rejectsJsonErrorInsteadOfDownloadingItAsPdf() {
when(print.generateInboundMarks(anyString(), anyString(), any()))