Friday, September 26, 2014

How to write a junit test case for a void return type?

Example code:

public void initiateArchiverBuilder(WcBrand wcBrand,
VaReportEntry vaReportEntry) {
VaBuildRequest vaBuildRequest = new VaBuildRequest();
vaBuildRequest.setObjectId(vaReportEntry.getId());
vaBuildRequest.setPriority(1);
vaBuildRequest.setBuilder("BUILDER_ARCHIVER");
vaBuildRequest.setAction("ARCHIVER_ACTION_ARCHIVE)";
vaBuildRequestDao.create(vaBuildRequest);
}

Junit :

You can verify the create method is called or not in junit.
Mockito.verify(vaReportEntryDao).create(Mockito.any(VaReportEntry.class));

No comments: