Skip to content
This repository has been archived by the owner on Feb 1, 2023. It is now read-only.

Commit

Permalink
Merge pull request #26 from snyk/fix/isFullRescanRequested_should_be_…
Browse files Browse the repository at this point in the history
…false_after_scan_finished

fix: isFullRescanRequested() should be False after rescan finished and before UI updates [ROAD-439]
  • Loading branch information
ArtsiomCh authored Oct 19, 2021
2 parents 58419e2 + a11175d commit 75041d1
Show file tree
Hide file tree
Showing 13 changed files with 401 additions and 131 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## [2.1.12] - 2020-10-17
- fix: isFullRescanRequested() should be False after rescan finished and before UI updates.

## [2.1.11] - 2020-10-05
- added param: "waiting results" timeout.

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {

group = "io.snyk.code.sdk"
archivesBaseName = "snyk-code-client"
version = "2.1.11"
version = "2.1.12"

repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ public void updateCachedAnalysisResults(@NotNull Object project, @NotNull Object
analysisData.updateCachedResultsForFiles(project, allSupportedFilesInProject, progress);

} finally {
projectsWithFullRescanRequested.remove(project);
updateAnalysisResultsUIPresentation(
project, analysisData.getAllFilesWithSuggestions(project));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package ai.deepcode.javaclient.core;

import ai.deepcode.javaclient.core.mocks.DeepCodeIgnoreInfoHolderMock;
import ai.deepcode.javaclient.core.mocks.HashContentUtilsMock;
import ai.deepcode.javaclient.core.mocks.LoggerMock;
import ai.deepcode.javaclient.core.mocks.PlatformDependentUtilsAbstractMock;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.junit.Test;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Collections;
import java.util.function.Consumer;

import static org.junit.Assert.*;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

public class DeepCodeIgnoreInfoHolderTest {

Expand Down Expand Up @@ -121,47 +121,7 @@ public void scanAllMissedIgnoreFiles() {
assertTrue(ignoreInfoHolder.isIgnoredFile(new File(basicProject, "2.js")));
}

@NotNull
private DeepCodeIgnoreInfoHolderBase getNewIgnoreInfoHolder() {
return new DeepCodeIgnoreInfoHolderBase(
new MockHashContentUtils(), new MockPlatformDependentUtils(), new MockLogger()) {
};
}

private class MockHashContentUtils extends HashContentUtilsBase {
protected MockHashContentUtils() {
super(new MockPlatformDependentUtils());
}

@Override
public @NotNull String doGetFileContent(@NotNull Object file) {
try {
return Files.readString(Paths.get(((File)file).getAbsolutePath()));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}

private class MockLogger extends DCLoggerBase {

protected MockLogger() {
super(
() -> System.out::println,
() -> System.out::println,
() -> true,
() -> true,
"ai.deepcode",
"");
}

@Override
protected String getExtraInfo() {
return "";
}
}

private class MockPlatformDependentUtils extends PlatformDependentUtilsBase {
private PlatformDependentUtilsBase pdUtils = new PlatformDependentUtilsAbstractMock() {
@Override
public @NotNull Object getProject(@NotNull Object file) {
final String filePath = ((File)file).getPath();
Expand All @@ -182,94 +142,20 @@ private class MockPlatformDependentUtils extends PlatformDependentUtilsBase {

@Override
public @NotNull String getFilePath(@NotNull Object file) {
return ((File) file).getPath().replaceAll("\\\\", "/"); // case for Windows base path
return ((File) file).getPath().replaceAll("\\\\", "/"); // case for Windows base path
}

@Override
public @NotNull String getDirPath(@NotNull Object file) {
return ((File) file).getParent().replaceAll("\\\\", "/"); // case for Windows base path
return ((File) file).getParent().replaceAll("\\\\", "/"); // case for Windows base path
}
};

// ------------------------------ don't needed below ---------------------------
@Override
protected @NotNull String getProjectBasedFilePath(@NotNull Object file) {
return null;
}

@Override
public Object getFileByDeepcodedPath(String path, Object project) {
return null;
}

@Override
public Object[] getOpenProjects() {
return new Object[0];
}

@Override
public long getFileSize(@NotNull Object file) {
return 0;
}

@Override
public int getLineStartOffset(@NotNull Object file, int line) {
return 0;
}

@Override
public void runInBackgroundCancellable(
@NotNull Object file, @NotNull String title, @NotNull Consumer<Object> progressConsumer) {}

@Override
public void runInBackground(
@NotNull Object project,
@NotNull String title,
@NotNull Consumer<Object> progressConsumer) {}

@Override
public void cancelRunningIndicators(@NotNull Object project) {}

@Override
public void doFullRescan(@NotNull Object project) {}

@Override
public void refreshPanel(@NotNull Object project) {}

@Override
public boolean isLogged(@Nullable Object project, boolean userActionNeeded) {
return false;
}

@Override
public void progressSetText(@Nullable Object progress, String text) {}

@Override
public void progressCheckCanceled(@Nullable Object progress) {}

@Override
public boolean progressCanceled(@Nullable Object progress) {
return false;
}

@Override
public void progressSetFraction(@Nullable Object progress, double fraction) {}

@Override
public void showInBrowser(@NotNull String url) {}

@Override
public void showLoginLink(@Nullable Object project, String message) {}

@Override
public void showConsentRequest(Object project, boolean userActionNeeded) {}

@Override
public void showInfo(String message, @Nullable Object project) {}

@Override
public void showWarn(String message, @Nullable Object project, boolean wasWarnShown) {}

@Override
public void showError(String message, @Nullable Object project) {}
@NotNull
private DeepCodeIgnoreInfoHolderBase getNewIgnoreInfoHolder() {
return new DeepCodeIgnoreInfoHolderMock(
new HashContentUtilsMock(pdUtils),
pdUtils,
new LoggerMock());
}
}
58 changes: 58 additions & 0 deletions src/test/java/ai/deepcode/javaclient/core/RunUtilsTest.java
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]);
}
}
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) {}
}
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);
}
}
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) {}
}
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;
}
}
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);
}
}
}
Loading

0 comments on commit 75041d1

Please sign in to comment.