Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(bazel): added tests for optionsFactory translation of user input…
… (List<FilterableEnumValue<WorkspaceRule>> ) to a Set of WorkspaceRules
- Loading branch information
Steve Billings
committed
Jul 13, 2020
1 parent
4d7afb6
commit 23abaae
Showing
1 changed file
with
66 additions
and
0 deletions.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
src/test/java/com/synopsys/integration/detect/configuration/DetectableOptionFactoryTest.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,66 @@ | ||
package com.synopsys.integration.detect.configuration; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mockito; | ||
|
||
import com.synopsys.integration.configuration.config.PropertyConfiguration; | ||
import com.synopsys.integration.configuration.property.types.enumfilterable.FilterableEnumValue; | ||
import com.synopsys.integration.detectable.detectables.bazel.BazelDetectableOptions; | ||
import com.synopsys.integration.detectable.detectables.bazel.WorkspaceRule; | ||
|
||
public class DetectableOptionFactoryTest { | ||
|
||
@Test | ||
public void testBazelDependencyRulesNone() { | ||
List<FilterableEnumValue<WorkspaceRule>> userProvidedRulesValue = | ||
Arrays.asList(FilterableEnumValue.noneValue()); | ||
Set<WorkspaceRule> derivedRules = doBazelDependencyRulesTest(userProvidedRulesValue); | ||
assertEquals(0, derivedRules.size()); | ||
} | ||
|
||
@Test | ||
public void testBazelDependencyRulesAll() { | ||
List<FilterableEnumValue<WorkspaceRule>> userProvidedRulesValue = | ||
Arrays.asList(FilterableEnumValue.allValue()); | ||
Set<WorkspaceRule> derivedRules = doBazelDependencyRulesTest(userProvidedRulesValue); | ||
derivedRules.contains(WorkspaceRule.MAVEN_INSTALL); | ||
derivedRules.contains(WorkspaceRule.MAVEN_JAR); | ||
derivedRules.contains(WorkspaceRule.HASKELL_CABAL_LIBRARY); | ||
} | ||
|
||
@Test | ||
public void testBazelDependencyRulesOne() { | ||
List<FilterableEnumValue<WorkspaceRule>> userProvidedRulesValue = | ||
Arrays.asList(FilterableEnumValue.value(WorkspaceRule.MAVEN_INSTALL)); | ||
Set<WorkspaceRule> derivedRules = doBazelDependencyRulesTest(userProvidedRulesValue); | ||
assertEquals(1, derivedRules.size()); | ||
derivedRules.contains(WorkspaceRule.MAVEN_INSTALL); | ||
} | ||
|
||
@Test | ||
public void testBazelDependencyRulesTwo() { | ||
List<FilterableEnumValue<WorkspaceRule>> userProvidedRulesValue = | ||
Arrays.asList(FilterableEnumValue.value(WorkspaceRule.MAVEN_INSTALL), | ||
FilterableEnumValue.value(WorkspaceRule.HASKELL_CABAL_LIBRARY)); | ||
Set<WorkspaceRule> derivedRules = doBazelDependencyRulesTest(userProvidedRulesValue); | ||
assertEquals(2, derivedRules.size()); | ||
derivedRules.contains(WorkspaceRule.MAVEN_INSTALL); | ||
derivedRules.contains(WorkspaceRule.HASKELL_CABAL_LIBRARY); | ||
} | ||
|
||
private Set<WorkspaceRule> doBazelDependencyRulesTest(List<FilterableEnumValue<WorkspaceRule>> userProvidedRulesValue) { | ||
PropertyConfiguration detectConfiguration = Mockito.mock(PropertyConfiguration.class); | ||
DetectableOptionFactory factory = new DetectableOptionFactory(detectConfiguration, | ||
null, null, null); | ||
Mockito.when(detectConfiguration.getValue(DetectProperties.Companion.getDETECT_BAZEL_DEPENDENCY_RULE())) | ||
.thenReturn(userProvidedRulesValue); | ||
BazelDetectableOptions options = factory.createBazelDetectableOptions(); | ||
return options.getBazelDependencyRules(); | ||
} | ||
} |