Skip to content

Commit e9b5e27

Browse files
committed
fix: ignore calling workbench if in test
1 parent 9217d96 commit e9b5e27

3 files changed

Lines changed: 22 additions & 11 deletions

File tree

plugin/src/main/java/io/snyk/eclipse/plugin/html/BaseHtmlProvider.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import org.eclipse.ui.themes.ITheme;
1212
import org.eclipse.ui.themes.IThemeManager;
1313

14+
import io.snyk.eclipse.plugin.properties.preferences.Preferences;
15+
1416
public class BaseHtmlProvider {
1517
private final Random random = new Random();
1618
private final Map<String, String> colorCache = new HashMap<>();
@@ -67,16 +69,19 @@ public String replaceCssVariables(String html) {
6769
}
6870

6971
public String getColorAsHex(String colorKey, String defaultColor) {
70-
return colorCache.computeIfAbsent(colorKey, key -> {
71-
ColorRegistry colorRegistry = getColorRegistry();
72-
Color color = colorRegistry.get(colorKey);
73-
if (color == null) {
74-
return defaultColor;
75-
} else {
76-
RGB rgb = color.getRGB();
77-
return String.format("#%02x%02x%02x", rgb.red, rgb.green, rgb.blue);
78-
}
79-
});
72+
if(Preferences.getInstance().isTest()) {
73+
return "";
74+
}
75+
return colorCache.computeIfAbsent(colorKey, key -> {
76+
ColorRegistry colorRegistry = getColorRegistry();
77+
Color color = colorRegistry.get(colorKey);
78+
if (color == null) {
79+
return defaultColor;
80+
} else {
81+
RGB rgb = color.getRGB();
82+
return String.format("#%02x%02x%02x", rgb.red, rgb.green, rgb.blue);
83+
}
84+
});
8085
}
8186

8287
private ColorRegistry colorRegistry;

plugin/src/main/java/io/snyk/eclipse/plugin/html/CodeHtmlProvider.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import org.eclipse.ui.themes.ITheme;
55
import org.eclipse.ui.themes.IThemeManager;
66

7+
import io.snyk.eclipse.plugin.properties.preferences.Preferences;
8+
79
public class CodeHtmlProvider extends BaseHtmlProvider {
810
private static CodeHtmlProvider instance = new CodeHtmlProvider();
911

@@ -64,7 +66,11 @@ private ITheme getCurrentTheme() {
6466
currentTheme = themeManager.getCurrentTheme();
6567
return currentTheme;
6668
}
69+
6770
private String getThemeScript() {
71+
if(Preferences.getInstance().isTest()) {
72+
return "";
73+
}
6874
ITheme currentTheme = getCurrentTheme();
6975
String themeId = currentTheme.getId().toLowerCase();
7076

tests/src/test/java/io/snyk/eclipse/plugin/html/HtmlProviderFactoryTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import io.snyk.eclipse.plugin.domain.ProductConstants;
1111
import io.snyk.languageserver.LsBaseTest;
1212

13-
public class HtmlProviderFactoryTest {
13+
public class HtmlProviderFactoryTest extends LsBaseTest {
1414
@Test
1515
void htmlProviderFactoryReturnsCorrectType() throws Exception {
1616
var cut = HtmlProviderFactory.GetHtmlProvider(ProductConstants.DISPLAYED_CODE_SECURITY);

0 commit comments

Comments
 (0)