Code review comment: Did as you suggested and can verify that the fix works. Removing the fix causes the test to fail. 

Code before review:
public void testClearingEnvironmentCache() throws IOException {
Path projectBCachePath = testBuildDirectory.resolve("repo").resolve("cache").resolve("samjs").resolve(
"projectB");
FileUtils.deleteDirectory(projectBCachePath.toFile());
CompileResult depCompileResult = BCompileUtil.compileAndCacheBala("projects_for_resolution_tests/projectB1");
if (depCompileResult.getErrorCount() > 0) {
Assert.fail("Package B contains compilations error");
}
Path projectA = RESOURCE_DIRECTORY.resolve("projectA");
Project loadProjectA = TestUtils.loadBuildProject(projectA);
PackageCompilation compilation = loadProjectA.currentPackage().getCompilation();
DependencyGraph<ResolvedPackageDependency> dependencyGraph = compilation.getResolution().dependencyGraph();
for (ResolvedPackageDependency graphNode : dependencyGraph.getNodes()) {
PackageManifest manifest = graphNode.packageInstance().manifest();
if (manifest.name().value().equals("projectB")) {
Assert.assertEquals(manifest.version().toString(), "1.0.0");
}
}
String newMainProjectAContent = "";
Module defaultModuleProjectA = loadProjectA.currentPackage().getDefaultModule();
Optional<DocumentId> mainDocumentId =
defaultModuleProjectA.documentIds()
.stream()
.filter(documentId -> defaultModuleProjectA.document(documentId).name().equals("main.bal"))
.findFirst();
if (mainDocumentId.isEmpty()) {
Assert.fail("Failed to retrieve the document ID");
}
Document document = defaultModuleProjectA.document(mainDocumentId.get());
document.modify().withContent(newMainProjectAContent).apply();
compilation = loadProjectA.currentPackage().getCompilation();
dependencyGraph = compilation.getResolution().dependencyGraph();
for (ResolvedPackageDependency graphNode : dependencyGraph.getNodes()) {
PackageManifest manifest = graphNode.packageInstance().manifest();
if (manifest.name().value().equals("projectB")) {
Assert.fail("ProjectB found in dependency after editing ProjectA");
}
}
FileUtils.deleteDirectory(projectBCachePath.toFile());
depCompileResult = BCompileUtil.compileAndCacheBala("projects_for_resolution_tests/projectB2");
if (depCompileResult.getErrorCount() > 0) {
Assert.fail("Package B contains compilations error");
}
String oldMainProjectAContent = "import samjs/projectB;\n" + "\n" + "public function getHello() returns " +
"(string) {\n" + "    return projectB:hello();\n" + "}";
Module oldModuleProjectA = loadProjectA.currentPackage().getDefaultModule();
mainDocumentId = defaultModuleProjectA.documentIds()
.stream()
.filter(documentId -> oldModuleProjectA.document(documentId).name().equals("main.bal"))
.findFirst();
if (mainDocumentId.isEmpty()) {
Assert.fail("Failed to retrieve the document ID");
}
document = defaultModuleProjectA.document(mainDocumentId.get());
document.modify().withContent(oldMainProjectAContent).apply();
compilation = loadProjectA.currentPackage().getCompilation();
Assert.assertFalse(compilation.diagnosticResult().errorCount() == 0, "Package A has compiled successfully " +
"when it should fail");
}


Code after addressing the review:
public void testClearingEnvironmentCache() throws IOException {
if (isWindows()) {
throw new SkipException("Skipping tests on Windows");
}
Path projectBCachePath = testBuildDirectory.resolve("repo").resolve("cache").resolve("samjs").resolve(
"projectB");
FileUtils.deleteDirectory(projectBCachePath.toFile());
CompileResult depCompileResult = BCompileUtil.compileAndCacheBala("projects_for_resolution_tests/projectB1");
if (depCompileResult.getErrorCount() > 0) {
Assert.fail("Package B contains compilations error");
}
Path projectA = RESOURCE_DIRECTORY.resolve("projectA");
Project loadProjectA = TestUtils.loadBuildProject(projectA);
PackageCompilation compilation = loadProjectA.currentPackage().getCompilation();
DependencyGraph<ResolvedPackageDependency> dependencyGraph = compilation.getResolution().dependencyGraph();
for (ResolvedPackageDependency graphNode : dependencyGraph.getNodes()) {
PackageManifest manifest = graphNode.packageInstance().manifest();
if (manifest.name().value().equals("projectB")) {
Assert.assertEquals(manifest.version().toString(), "1.0.0");
}
}
String newMainProjectAContent = "";
Module defaultModuleProjectA = loadProjectA.currentPackage().getDefaultModule();
Optional<DocumentId> mainDocumentId =
defaultModuleProjectA.documentIds()
.stream()
.filter(documentId -> defaultModuleProjectA.document(documentId).name().equals("main.bal"))
.findFirst();
if (mainDocumentId.isEmpty()) {
Assert.fail("Failed to retrieve the document ID");
}
Document document = defaultModuleProjectA.document(mainDocumentId.get());
document.modify().withContent(newMainProjectAContent).apply();
compilation = loadProjectA.currentPackage().getCompilation();
dependencyGraph = compilation.getResolution().dependencyGraph();
for (ResolvedPackageDependency graphNode : dependencyGraph.getNodes()) {
PackageManifest manifest = graphNode.packageInstance().manifest();
if (manifest.name().value().equals("projectB")) {
Assert.fail("ProjectB found in dependency after editing ProjectA");
}
}
FileUtils.deleteDirectory(projectBCachePath.toFile());
depCompileResult = BCompileUtil.compileAndCacheBala("projects_for_resolution_tests/projectB2");
if (depCompileResult.getErrorCount() > 0) {
Assert.fail("Package B contains compilations error");
}
FileUtils.deleteDirectory(projectBCachePath.toFile());
String oldMainProjectAContent = "import samjs/projectB;\n" + "\n" + "public function getHello() returns " +
"(string) {\n" + "    return projectB:hello();\n" + "}";
Module oldModuleProjectA = loadProjectA.currentPackage().getDefaultModule();
mainDocumentId = defaultModuleProjectA.documentIds()
.stream()
.filter(documentId -> oldModuleProjectA.document(documentId).name().equals("main.bal"))
.findFirst();
if (mainDocumentId.isEmpty()) {
Assert.fail("Failed to retrieve the document ID");
}
document = defaultModuleProjectA.document(mainDocumentId.get());
document.modify().withContent(oldMainProjectAContent).apply();
compilation = loadProjectA.currentPackage().getCompilation();
Assert.assertNotEquals(compilation.diagnosticResult().errorCount(), 0, "Package A has compiled successfully " +
"when it should fail");
}