### Question:
ImportedPackages implements ProgressCheckFactory { @Override public ProgressCheck newInstance(JsonObject config) throws Exception { final List<String> versions; JsonArray versionsFromConfig = config.getJsonArray(CONFIG_VERSION); if (versionsFromConfig != null) { versions = versionsFromConfig.stream().map(v -> (JsonString) v).map(JsonString::getString).collect(Collectors.toList()); } else { versions = DEFAULT_VERSIONS; } Map<String, Map<String, Set<Version>>> exportedPackagesByVersion = versions.stream() .map(version -> { InputStream inputStream = getClass().getResourceAsStream(String.format("/bundleinfo/%s.json", version)); if (inputStream == null) { throw new IllegalArgumentException(String.format("Unknown version %s", version)); } try (JsonReader reader = Json.createReader(inputStream)) { JsonObject packageDefinitions = reader.readObject(); ImmutableMap.Builder<String, Set<Version>> builder = ImmutableMap.builder(); packageDefinitions.keySet().forEach(key -> { builder.put(key, packageDefinitions.getJsonArray(key).stream().map(v -> { String str = ((JsonString) v).getString(); return new Version(str); }).collect(Collectors.toSet())); }); return new AbstractMap.SimpleEntry<>(version, builder.build()); } }).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); return new Check(exportedPackagesByVersion); }  @Override ProgressCheck newInstance(JsonObject config);  }### Answer:
@Test public void testMismatchedVersions() throws Exception { final File jarFile = new File(pack.getParentFile(), "package-imports-version-mismatch.jar"); if (jarFile.exists()) { jarFile.delete(); } TestPackageUtil.buildJarFromDir(new File("src/test/resources/package-imports-version-mismatch-jar"), jarFile, Collections.emptyMap()); final ProgressCheck check = new ImportedPackages().newInstance(key("aemVersion", arr("6.4")).get()); final PackageId packageId = PackageId.fromString("my_packages:test"); check.startedScan(); check.beforeExtract(packageId, null, null, null, Collections.emptyList()); final String path = "/apps/test/install/test.jar"; final Node ntFileNode = mock(Node.class); when(ntFileNode.isNodeType(JcrConstants.NT_FILE)).thenReturn(true); when(ntFileNode.hasProperty(Property.JCR_DATA)).thenReturn(true); final Property data = mock(Property.class); when(ntFileNode.getProperty(Property.JCR_DATA)).thenReturn(data); final Binary binary = mock(Binary.class); when(data.getBinary()).thenReturn(binary); doAnswer(call -> new FileInputStream(jarFile)).when(binary).getStream(); check.importedPath(packageId, path, ntFileNode); check.finishedScan(); assertEquals("reported violations", 1, check.getReportedViolations().size()); }
@Test public void testDefaultConfig() throws Exception { ProgressCheck check = new ImportedPackages().newInstance(Json.createObjectBuilder().build()); CheckReport report = scanWithCheck(check, pack); assertEquals(0, report.getViolations().size()); }
@Test(expected = IllegalArgumentException.class) public void testNewInstance_missingBundleInfo() throws Exception { new ImportedPackages().newInstance(key("aemVersion", arr("5.4")).get()); }