### Question:
JarContentDelegate extends FileContentDelegate { @Override public Set<ResourcePackageDetails> discoverDeployedPackages() { Set<ResourcePackageDetails> packages = new HashSet<ResourcePackageDetails>(); File[] files = this.getDirectory().listFiles(new FileFilter() { public boolean accept(File pathname) { return pathname.getName().endsWith(getFileEnding()) && pathname.isFile(); } }); for (File file : files) { String manifestVersion = null; JarFile jf = null; try { Configuration config = new Configuration(); jf = new JarFile(file); Manifest manifest = jf.getManifest(); if (manifest != null) { Attributes attributes = manifest.getMainAttributes(); manifestVersion = attributes.getValue(Attributes.Name.IMPLEMENTATION_VERSION); config.put(new PropertySimple("version", manifestVersion)); config.put(new PropertySimple("title", attributes.getValue(Attributes.Name.IMPLEMENTATION_TITLE))); config.put(new PropertySimple("url", attributes.getValue(Attributes.Name.IMPLEMENTATION_URL))); config .put(new PropertySimple("vendor", attributes.getValue(Attributes.Name.IMPLEMENTATION_VENDOR))); config.put(new PropertySimple("classpath", attributes.getValue(Attributes.Name.CLASS_PATH))); config.put(new PropertySimple("sealed", attributes.getValue(Attributes.Name.SEALED))); } String sha256 = null; try { sha256 = new MessageDigestGenerator(MessageDigestGenerator.SHA_256).calcDigestString(file); } catch (Exception e) { } ResourcePackageDetails details = new ResourcePackageDetails(new PackageDetailsKey(file.getName(), getVersion(sha256), getPackageTypeName(), "noarch")); packages.add(details); details.setFileCreatedDate(file.lastModified()); details.setFileName(file.getName()); details.setFileSize(file.length()); details.setClassification(MIME_TYPE_JAR); details.setSHA256(sha256); details.setDisplayVersion(getDisplayVersion(file)); details.setExtraProperties(config); } catch (IOException e) { } finally { try { if (jf != null) jf.close(); } catch (Exception e) { } } } return packages; } JarContentDelegate(File directory, String packageTypeName); String getPackageTypeName(); @Override Set<ResourcePackageDetails> discoverDeployedPackages();  }### Answer:
@Test public void testDiscoverDeployedPackages() throws Exception { File mockDirectory = mock(File.class); when(mockDirectory.exists()).thenReturn(true); when(mockDirectory.isDirectory()).thenReturn(true); File mockFile = mock(File.class); when(mockDirectory.listFiles(any(FileFilter.class))).thenReturn(new File[] { mockFile }); when(mockFile.getName()).thenReturn("testFile"); JarFile mockJarFile = mock(JarFile.class); PowerMockito.whenNew(JarFile.class).withParameterTypes(File.class).withArguments(any(File.class)) .thenReturn(mockJarFile); MessageDigestGenerator mockMessageDigestGenerator = mock(MessageDigestGenerator.class); PowerMockito.whenNew(MessageDigestGenerator.class).withParameterTypes(String.class).withArguments(anyString()) .thenReturn(mockMessageDigestGenerator); when(mockMessageDigestGenerator.calcDigestString(any(File.class))).thenReturn("abcd1234"); JarContentDelegate objectUnderTest = new JarContentDelegate(mockDirectory, "jar"); Set<ResourcePackageDetails> resultSet = objectUnderTest.discoverDeployedPackages(); Assert.assertEquals(resultSet.size(), 1); ResourcePackageDetails resultPackageDetails = (ResourcePackageDetails) resultSet.toArray()[0]; Assert.assertEquals(resultPackageDetails.getVersion(), "[sha256=abcd1234]"); Assert.assertEquals(resultPackageDetails.getSHA256(), "abcd1234"); }