This repository has been archived by the owner on Feb 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from snyk/fix/isFullRescanRequested_should_be_…
…false_after_scan_finished fix: isFullRescanRequested() should be False after rescan finished and before UI updates [ROAD-439]
- Loading branch information
Showing
13 changed files
with
401 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/test/java/ai/deepcode/javaclient/core/RunUtilsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package ai.deepcode.javaclient.core; | ||
|
||
import ai.deepcode.javaclient.core.mocks.*; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.junit.Test; | ||
|
||
import java.util.Collection; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
|
||
public class RunUtilsTest { | ||
|
||
@Test | ||
public void isRescanShownAsNotRequestedAfterScanFinishedTest() { | ||
|
||
final boolean[] isFullRescanRequested = {true}; | ||
|
||
// ---------------------------- setup -------------------------- | ||
final PlatformDependentUtilsBase pdUtils = new PlatformDependentUtilsAbstractMock() {}; | ||
final DeepCodeParamsBase deepCodeParams = new DeepCodeParamsMock(); | ||
final DCLoggerBase dcLogger = new LoggerMock(); | ||
|
||
final HashContentUtilsBase hashContentUtils = new HashContentUtilsMock(pdUtils); | ||
|
||
final DeepCodeIgnoreInfoHolderBase ignoreInfoHolder = | ||
new DeepCodeIgnoreInfoHolderMock(hashContentUtils, pdUtils, dcLogger); | ||
|
||
final AnalysisDataBase analysisData = | ||
new AnalysisDataBaseMock(pdUtils, hashContentUtils, deepCodeParams, dcLogger) { | ||
@Override | ||
public void updateCachedResultsForFiles( | ||
@NotNull Object project, | ||
@NotNull Collection<Object> allProjectFiles, | ||
@NotNull Object progress) {} | ||
}; | ||
|
||
final DeepCodeUtilsBase deepCodeUtils = | ||
new DeepCodeUtilsMock(analysisData, deepCodeParams, ignoreInfoHolder, pdUtils, dcLogger); | ||
|
||
final String project = "Project"; | ||
|
||
RunUtilsBase runUtilsMock = | ||
new RunUtilsBaseMock(pdUtils, hashContentUtils, analysisData, deepCodeUtils, dcLogger) { | ||
@Override | ||
protected void updateAnalysisResultsUIPresentation( | ||
@NotNull Object project, @NotNull Collection<Object> files) { | ||
isFullRescanRequested[0] = isFullRescanRequested(project); | ||
} | ||
}; | ||
|
||
// --------------------------- actual test -------------------- | ||
runUtilsMock.rescanInBackgroundCancellableDelayed(project, 0, false, false); | ||
|
||
assertFalse( | ||
"isFullRescanRequested() should be False after rescan finished and before UI updates", | ||
isFullRescanRequested[0]); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/test/java/ai/deepcode/javaclient/core/mocks/AnalysisDataBaseMock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package ai.deepcode.javaclient.core.mocks; | ||
|
||
import ai.deepcode.javaclient.core.*; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.Collection; | ||
|
||
public class AnalysisDataBaseMock extends AnalysisDataBase { | ||
|
||
public AnalysisDataBaseMock( | ||
@NotNull PlatformDependentUtilsBase platformDependentUtils, | ||
@NotNull HashContentUtilsBase hashContentUtils, | ||
@NotNull DeepCodeParamsBase deepCodeParams, | ||
@NotNull DCLoggerBase dcLogger) { | ||
super(platformDependentUtils, hashContentUtils, deepCodeParams, dcLogger); | ||
} | ||
|
||
@Override | ||
protected void updateUIonFilesRemovalFromCache(@NotNull Collection<Object> files) {} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/test/java/ai/deepcode/javaclient/core/mocks/DeepCodeIgnoreInfoHolderMock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package ai.deepcode.javaclient.core.mocks; | ||
|
||
import ai.deepcode.javaclient.core.*; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class DeepCodeIgnoreInfoHolderMock extends DeepCodeIgnoreInfoHolderBase { | ||
|
||
public DeepCodeIgnoreInfoHolderMock( | ||
@NotNull HashContentUtilsBase hashContentUtils, | ||
@NotNull PlatformDependentUtilsBase pdUtils, | ||
@NotNull DCLoggerBase dcLogger) { | ||
super(hashContentUtils, pdUtils, dcLogger); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/test/java/ai/deepcode/javaclient/core/mocks/DeepCodeParamsMock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package ai.deepcode.javaclient.core.mocks; | ||
|
||
import ai.deepcode.javaclient.core.DeepCodeParamsBase; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class DeepCodeParamsMock extends DeepCodeParamsBase { | ||
|
||
public DeepCodeParamsMock() { | ||
super( | ||
true, | ||
"", | ||
false, | ||
false, | ||
1, | ||
"", | ||
"", | ||
"", | ||
() -> 1000L); | ||
} | ||
|
||
@Override | ||
public boolean consentGiven(@NotNull Object project) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public void setConsentGiven(@NotNull Object project) {} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/test/java/ai/deepcode/javaclient/core/mocks/DeepCodeUtilsMock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package ai.deepcode.javaclient.core.mocks; | ||
|
||
import ai.deepcode.javaclient.core.*; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.Collection; | ||
import java.util.Collections; | ||
|
||
public class DeepCodeUtilsMock extends DeepCodeUtilsBase { | ||
|
||
public DeepCodeUtilsMock( | ||
@NotNull AnalysisDataBase analysisData, | ||
@NotNull DeepCodeParamsBase deepCodeParams, | ||
@NotNull DeepCodeIgnoreInfoHolderBase ignoreInfoHolder, | ||
@NotNull PlatformDependentUtilsBase pdUtils, | ||
@NotNull DCLoggerBase dcLogger) { | ||
super(analysisData, deepCodeParams, ignoreInfoHolder, pdUtils, dcLogger); | ||
} | ||
|
||
@Override | ||
protected Collection<Object> allProjectFiles(@NotNull Object project) { | ||
return Collections.emptySet(); | ||
} | ||
|
||
@Override | ||
protected long getFileLength(@NotNull Object file) { | ||
return 0; | ||
} | ||
|
||
@Override | ||
protected String getFileExtention(@NotNull Object file) { | ||
return ""; | ||
} | ||
|
||
@Override | ||
protected boolean isGitIgnoredExternalCheck(@NotNull Object file) { | ||
return false; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/test/java/ai/deepcode/javaclient/core/mocks/HashContentUtilsMock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package ai.deepcode.javaclient.core.mocks; | ||
|
||
import ai.deepcode.javaclient.core.HashContentUtilsBase; | ||
import ai.deepcode.javaclient.core.PlatformDependentUtilsBase; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
|
||
public class HashContentUtilsMock extends HashContentUtilsBase { | ||
|
||
public HashContentUtilsMock(@NotNull PlatformDependentUtilsBase platformDependentUtils) { | ||
super(platformDependentUtils); | ||
} | ||
|
||
@Override | ||
public @NotNull String doGetFileContent(@NotNull Object file) { | ||
try { | ||
return Files.readString(Paths.get(((File) file).getAbsolutePath())); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
Oops, something went wrong.