VhdProcessor extends AdapterBase implements Processor { @Override public long getVirtualSize(File file) throws IOException { try { long size = getTemplateVirtualSize(file); return size; } catch (Exception e) { s_logger.info("[ignored]" + "failed to get template virtual size for VHD: " + e.getLocalizedMessage()); } return file.length(); }  @Override FormatInfo process(String templatePath, ImageFormat format, String templateName); @Override long getVirtualSize(File file); @Override boolean configure(String name, Map<String, Object> params);  }
@Test public void testGetVirtualSize() throws Exception{ long virtualSize = 2000; long actualSize = 1000; File mockFile = Mockito.mock(File.class); Mockito.when(mockFile.length()).thenReturn(actualSize); Mockito.doReturn(virtualSize).when(processor).getTemplateVirtualSize((File) Mockito.any()); Assert.assertEquals(virtualSize, processor.getVirtualSize(mockFile)); Mockito.verify(mockFile,Mockito.times(0)).length(); }