如何为以下代码编写junit

时间:2019-01-29 06:10:54

标签: spring-boot junit mockito

如何为if else编码编写测试用例。当将该对象设置为null时,我没有在else块中获得覆盖。 同样也没有在catch区域获得覆盖。

if (Object!= null) {
            if (Object.getId() != null) {
                responseModel = registrationService.updateVendor(Object);
            } else {
                responseModel = registrationService.save(Object);
            }
        } else {
            responseModel = new ResponseModel();
            responseModel.setCode(ERROR_1002);
            responseModel.setMessage(ERROR_MSG1002);
            logger.info("Vendor details not found");
        }

    } catch (NullPointerException  e) {
        //e.printStackTrace();

        responseModel = new ResponseModel();
        responseModel.setCode(ERROR_1000);
        responseModel.setMessage(ERROR_MSG1000);
        logger.error("Exception inside RegistrationController.Registration()" + e);

    }

0 个答案:

没有答案