java junit 私有方法_有没有办法在Junit5中的另一个方法中模拟私有方法调用

下面是我想测试的方法,但据我所知Junit5不支持PowerMockito。那么有什么方法可以在另一个方法内部模拟私有方法调用吗?

public Class MyClass {

private void sendEmailNotification(Checklist Checklist){

EmailService emailService = new EmailService();

BaseDTO esDO = newFolderService.getFolderByUri(ServicesUtils.getDecodedCaseNodeUriFromSelfLink(Checklist.getEs_uri()));

String esName = esDO.getName();

SharedInfo sharedInfo = Checklist.getShared_info();

sharedInfo.setEng_space_name(esName);

String reviewer = Checklist.getReviewer();

String ChecklistUri = Checklist.getUri();

String ChecklistName = Checklist.getName();

String targetPhase = Checklist.getTarget_phase();

String comment = Checklist.getComment();

String submitter = Checklist.getSubmitter();

String appURL = Checklist.getShared_info().getApp_url();

String ChecklistLink = buildChecklistURL(appURL, ChecklistUri);

String emailBodyTemplate;

String emailSubject;

emailBodyTemplate = EmailTemplates.getEmailTemplateByName(EmailConstants.TEMPLATE_DELIVERABLE_ACCEPTED_REJECTED_WITH_COMMENTS);

emailSubject = String.format(EmailConstants.ACCEPT_REJECT_WITH_COMMENTS_SUBJECT, ChecklistName, targetPhase);

emailBodyTemplate = EmailTemplates.replaceSharedVariable(emailBodyTemplate, sharedInfo);

emailBodyTemplate = EmailTemplates.replaceVariable(emailBodyTemplate, EmailConstants.VAR_TARGET_PHASE, targetPhase);

emailBodyTemplate = EmailTemplates.replaceVariable(emailBodyTemplate, EmailConstants.VAR_REVIEWER, reviewer);

emailBodyTemplate = EmailTemplates.replaceVariable(emailBodyTemplate, EmailConstants.VAR_CHECKLIST_ITEM_NAME, ChecklistName);

emailBodyTemplate = EmailTemplates.replaceVariable(emailBodyTemplate, EmailConstants.VAR_COMMENT, comment);

emailBodyTemplate = EmailTemplates.replaceVariable(emailBodyTemplate, EmailConstants.VAR_CHECKLIST_ITEM_URL, ChecklistLink);

try {

emailService.sendEmail(submitter, EmailConstants.EMAIL_SENDER, emailSubject, emailBodyTemplate);

} catch (RuntimeException e) {

Checklist.addError(messages.get(E_ACCEPT_REJECT_SEND_EMAIL));

}

}

//Method to be tested

public void method(Checklist checklist){

/*Some Code*/

sendEmail(checklist); /* want to ignore this, as throwing NullPointerException*/

/*Some Code*/

}}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值