package com.tourguide.modules.order.service; import com.alibaba.fastjson.JSONObject; import com.tourguide.common.huifu.properties.HuiFuProperties; import com.tourguide.modules.order.payment.HuifuPaymentNotice; import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; class HuifuPaymentCallbackServiceTest { @Test void successfulNoticeShouldDelegateVerifiedPaymentData() { HuiFuProperties properties = new HuiFuProperties(); properties.setHuifuId("merchant-1"); TourOrderPaymentService orderPaymentService = mock(TourOrderPaymentService.class); HuifuPaymentCallbackService service = new HuifuPaymentCallbackService(properties, orderPaymentService); JSONObject body = new JSONObject(); body.put("req_seq_id", "DG001"); body.put("huifu_id", "merchant-1"); body.put("trans_stat", "S"); body.put("trans_amt", "36.00"); body.put("hf_seq_id", "HF001"); body.put("end_time", "20260803160530"); service.handle(body); ArgumentCaptor captor = ArgumentCaptor.forClass(HuifuPaymentNotice.class); verify(orderPaymentService).confirm(captor.capture()); HuifuPaymentNotice notice = captor.getValue(); assertThat(notice.getReqSeqId()).isEqualTo("DG001"); assertThat(notice.getAmount()).isEqualByComparingTo("36.00"); assertThat(notice.getProviderTransactionId()).isEqualTo("HF001"); assertThat(notice.getPaidAt()).isEqualTo("2026-08-03T16:05:30"); } @Test void unsuccessfulNoticeShouldNotConfirmOrder() { HuiFuProperties properties = new HuiFuProperties(); properties.setHuifuId("merchant-1"); TourOrderPaymentService orderPaymentService = mock(TourOrderPaymentService.class); HuifuPaymentCallbackService service = new HuifuPaymentCallbackService(properties, orderPaymentService); JSONObject body = new JSONObject(); body.put("req_seq_id", "DG001"); body.put("huifu_id", "merchant-1"); body.put("trans_stat", "F"); service.handle(body); verify(orderPaymentService, never()).confirm(org.mockito.ArgumentMatchers.any()); } }