Home > OS >  How to write test case for this void method for if condition
How to write test case for this void method for if condition

Time:07-08

public void setRefundIdForPrepaid(RefundReturnRequest refundReturnRequest) { 
    if(StringUtils.isBlank (refundReturnRequest.getRefundRequest().getRefundId())) {
        refundReturnRequest.getRefundRequest().setRefundId (Integer.toString(ThreadLocalRandom.current().nextInt(999999999)));
    }
}

CodePudding user response:

you can test the RefundReturnRequest refundReturnRequest after the method executed.

@Test
void testSetRefundIdForPrepaid(){
   //build param
   RefundReturnRequest refundReturnRequest = new RefundReturnRequest();
   //executetd
   service.setRefundIdForPrepaid(refundReturnRequest);
   //test result
   assertThat(refundReturnRequest.getRefundRequest().getRefundId()).isEqualTo(xxx);
}

CodePudding user response:

@Test
TestsetRefundIdForPrepaid(){
//test case
}
  • Related