【发布时间】:2021-01-08 12:43:57
【问题描述】:
我有一个 Component 类,如下所示:
@Component
@AllArgsConstructor
@NoArgsConstructor
@Slf4j
public class OutboundSystemTriggeredDirectAnalyzer implements BufferAccountAnalyzer {
private FeignCustomerClient customerClient;
@Override
public void analyze(BankStatementTransaction bankStatementTransaction) {
CustomerSummaryResponseDto customerSummary = new CustomerSummaryResponseDto();
CustomerSummaryBankAccountRequestDto parsedAccountNumber = CustomerUtils
.parseAccountNumber(bankStatementTransaction.getAccountNumber());
try {
customerSummary = customerClient
.getCustomerSummaryByBankAccount(parsedAccountNumber).getBody();
} catch (Exception e) {
log.error("Error on getting customer summary for bank account: {}", parsedAccountNumber);
}
CustomerIdentity customerIdentity = null;
if (customerSummary != null && customerSummary.getProducts() != null) {
customerIdentity = CustomerUtils.identifyCustomer(customerSummary);
}
}
假客户是
@FeignClient(CUSTOMER_MANAGEMENT)
public interface FeignCustomerClient {
@PostMapping(CUSTOMERS_PATH + SUMMARY + READ + BY_BANK_ACCOUNT)
ResponseEntity<CustomerSummaryResponseDto> getCustomerSummaryByBankAccount(CustomerSummaryBankAccountRequestDto request);
}
我创建了一个测试
@RunWith(MockitoJUnitRunner.class)
public class OutboundSystemTriggeredDirectAnalyzerTest {
@Mock
private FeignCustomerClient customerClient;
@Mock
private FeignOldtransactionClient transactionClient;
@InjectMocks
private OutboundSystemTriggeredDirectAnalyzer analyzer;
@Test
public void matchCustomer() {
BankStatementTransaction bankStatementTransaction = new BankStatementTransaction();
bankStatementTransaction.setAccountNumber("31-046-006770124");
CustomerSummaryBankAccountRequestDto parsedAccountNumber = new CustomerSummaryBankAccountRequestDto(31, 46, "6770124");
CustomerSummaryResponseDto customerSummary = new CustomerSummaryResponseDto();
BaseProductDto baseProductDto = new BaseProductDto(ProductType.LENDER, ProductSubType.PRIVATE, 32L);
List<BaseProductDto> baseProducts = new ArrayList<>();
baseProducts.add(baseProductDto);
customerSummary.setProducts(baseProducts);
WithdrawSearchRequestDto withdrawSearchRequestDto = new WithdrawSearchRequestDto();
withdrawSearchRequestDto.setIsApproved(TRUE);
withdrawSearchRequestDto.setLenderId(32L);
TransactionResponseDto transactionDto = new TransactionResponseDto();
transactionDto.setAmount(new BigDecimal("2000.00"));
List<TransactionResponseDto> transactions = new ArrayList<>();
transactions.add(transactionDto);
Mockito.when(customerClient.getCustomerSummaryByBankAccount(parsedAccountNumber)).thenReturn(ResponseEntity.ok(customerSummary));
Mockito.when(transactionClient.searchLenderWithdrawTransactions(1L, withdrawSearchRequestDto)).thenReturn(ResponseEntity.ok(transactions));
analyzer.analyze(bankStatementTransaction);
assertThat(bankStatementTransaction.getBankTransactionType().getId(), is(9L));
}
}
我希望在调用 customerClient.getCustomerSummaryByBankAccount 时返回我在测试中创建的 customerSummary 对象,但是当我调试时 - 它不返回 customerSummary,但它是 Null。
【问题讨论】: