-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1d09212
commit c07820b
Showing
4 changed files
with
89 additions
and
5 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
87 changes: 87 additions & 0 deletions
87
src/test/java/org/sonarlint/intellij/analysis/AnalysisStateTests.kt
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,87 @@ | ||
package org.sonarlint.intellij.analysis | ||
|
||
import com.intellij.openapi.progress.ProgressIndicator | ||
import com.intellij.openapi.vfs.VirtualFile | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.jupiter.api.Test | ||
import org.mockito.Mockito | ||
import org.sonarlint.intellij.AbstractSonarLintLightTests | ||
import org.sonarlint.intellij.trigger.TriggerType | ||
|
||
class AnalysisStateTests : AbstractSonarLintLightTests() { | ||
|
||
private val file1 = Mockito.mock(VirtualFile::class.java) | ||
private val file2 = Mockito.mock(VirtualFile::class.java) | ||
private val callback = Mockito.mock(AnalysisCallback::class.java) | ||
private val progress = Mockito.mock(ProgressIndicator::class.java) | ||
|
||
@Test | ||
fun should_find_redundant_analysis_for_non_snapshot() { | ||
val randomUuid1 = java.util.UUID.randomUUID() | ||
val randomUuid2 = java.util.UUID.randomUUID() | ||
val filesToAnalyze = mutableListOf(file1, file2) | ||
|
||
val analysisState = AnalysisState(randomUuid1, callback, filesToAnalyze, module, TriggerType.EDITOR_OPEN, progress) | ||
val analysisState2 = AnalysisState(randomUuid2, callback, filesToAnalyze, module, TriggerType.BINDING_UPDATE, progress) | ||
|
||
assertThat(analysisState.isRedundant(analysisState2)).isTrue() | ||
assertThat(analysisState2.isRedundant(analysisState)).isTrue() | ||
} | ||
|
||
@Test | ||
fun should_find_redundant_analysis_for_snapshot() { | ||
val randomUuid1 = java.util.UUID.randomUUID() | ||
val randomUuid2 = java.util.UUID.randomUUID() | ||
val filesToAnalyze = mutableListOf(file1, file2) | ||
|
||
val analysisState = AnalysisState(randomUuid1, callback, filesToAnalyze, module, TriggerType.ALL, progress) | ||
val analysisState2 = AnalysisState(randomUuid2, callback, filesToAnalyze, module, TriggerType.CHANGED_FILES, progress) | ||
|
||
assertThat(analysisState.isRedundant(analysisState2)).isTrue() | ||
assertThat(analysisState2.isRedundant(analysisState)).isTrue() | ||
} | ||
|
||
@Test | ||
fun should_not_find_redundant_analysis_for_different_types() { | ||
val randomUuid1 = java.util.UUID.randomUUID() | ||
val randomUuid2 = java.util.UUID.randomUUID() | ||
val filesToAnalyze = mutableListOf(file1, file2) | ||
|
||
val analysisState = AnalysisState(randomUuid1, callback, filesToAnalyze, module, TriggerType.EDITOR_OPEN, progress) | ||
val analysisState2 = AnalysisState(randomUuid2, callback, filesToAnalyze, module, TriggerType.CHANGED_FILES, progress) | ||
|
||
assertThat(analysisState.isRedundant(analysisState2)).isFalse() | ||
assertThat(analysisState2.isRedundant(analysisState)).isFalse() | ||
} | ||
|
||
@Test | ||
fun should_not_find_redundant_analysis_with_different_files() { | ||
val randomUuid1 = java.util.UUID.randomUUID() | ||
val randomUuid2 = java.util.UUID.randomUUID() | ||
val filesToAnalyze1 = mutableListOf(file1) | ||
val filesToAnalyze2 = mutableListOf(file2) | ||
|
||
|
||
val analysisState = AnalysisState(randomUuid1, callback, filesToAnalyze1, module, TriggerType.EDITOR_OPEN, progress) | ||
val analysisState2 = AnalysisState(randomUuid2, callback, filesToAnalyze2, module, TriggerType.EDITOR_CHANGE, progress) | ||
|
||
assertThat(analysisState.isRedundant(analysisState2)).isFalse() | ||
assertThat(analysisState2.isRedundant(analysisState)).isFalse() | ||
} | ||
|
||
@Test | ||
fun should_find_redundant_analysis_for_subset_files() { | ||
val randomUuid1 = java.util.UUID.randomUUID() | ||
val randomUuid2 = java.util.UUID.randomUUID() | ||
val filesToAnalyze1 = mutableListOf(file1) | ||
val filesToAnalyze2 = mutableListOf(file1, file2) | ||
|
||
|
||
val analysisState = AnalysisState(randomUuid1, callback, filesToAnalyze1, module, TriggerType.EDITOR_OPEN, progress) | ||
val analysisState2 = AnalysisState(randomUuid2, callback, filesToAnalyze2, module, TriggerType.EDITOR_CHANGE, progress) | ||
|
||
assertThat(analysisState.isRedundant(analysisState2)).isTrue() | ||
assertThat(analysisState2.isRedundant(analysisState)).isFalse() | ||
} | ||
|
||
} |
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