when(mockResultSet.getBlob(anyInt())).thenReturn(mockBlob);
OutputStream mockOutputStream = mock(OutputStream.class);
when(mockBlob.setBinaryStream(anyLong())).thenReturn(mockOutputStream);
//create object to test and inject required dependencies
ContentManagerBean objectUnderTest = new ContentManagerBean();
Field[] fields = ContentManagerBean.class.getDeclaredFields();
for (Field field : fields) {
if (field.getName().equals("entityManager")) {
field.setAccessible(true);
field.set(objectUnderTest, mockEntityManager);
field.setAccessible(false);
}
else if (field.getName().equals("contentManager")) {
field.setAccessible(true);
field.set(objectUnderTest, mockContentManager);
field.setAccessible(false);
}
else if (field.getName().equals("dataSource")) {
field.setAccessible(true);
field.set(objectUnderTest, mockDataSource);
field.setAccessible(false);
}
}
//run the code to be tested
PackageVersion result = objectUnderTest.createPackageVersionWithDisplayVersion(mockSubject, packageName,
packageTypeID, version, displayVersion, architectureId, packageBitStream);
//verify the results (Assert and Mock Verification)
verify(mockList, times(2)).size();
verify(mockList, never()).get(anyInt());