|
1 | 1 | package io.snyk.languageserver;
|
2 | 2 |
|
| 3 | +import static org.mockito.ArgumentMatchers.anyString; |
3 | 4 | import static org.mockito.Mockito.clearAllCaches;
|
4 | 5 | import static org.mockito.Mockito.mock;
|
5 | 6 | import static org.mockito.Mockito.when;
|
|
8 | 9 | import java.io.IOException;
|
9 | 10 |
|
10 | 11 | import org.eclipse.core.net.proxy.IProxyService;
|
| 12 | +import org.eclipse.jface.resource.ImageRegistry; |
| 13 | +import org.eclipse.swt.graphics.Image; |
11 | 14 | import org.junit.jupiter.api.AfterEach;
|
12 | 15 | import org.junit.jupiter.api.BeforeEach;
|
| 16 | +import org.mockito.Mock; |
| 17 | +import org.mockito.MockitoAnnotations; |
13 | 18 |
|
14 | 19 | import io.snyk.eclipse.plugin.preferences.InMemoryPreferenceStore;
|
15 | 20 | import io.snyk.eclipse.plugin.preferences.Preferences;
|
16 | 21 | import io.snyk.eclipse.plugin.properties.preferences.PreferencesUtils;
|
17 | 22 |
|
18 | 23 | public class LsBaseTest {
|
19 |
| - protected LsRuntimeEnvironment environment = null; |
20 |
| - protected IProxyService proxyServiceMock; |
21 |
| - |
22 |
| - private File lsFile = getTempFile(); |
23 |
| - |
24 |
| - @BeforeEach |
25 |
| - protected void setUp() { |
26 |
| - clearAllCaches(); |
27 |
| - if (lsFile.exists()) |
28 |
| - lsFile.delete(); |
29 |
| - lsFile = getTempFile(); |
30 |
| - environment = mock(LsRuntimeEnvironment.class); |
31 |
| - InMemoryPreferenceStore store = new InMemoryPreferenceStore(); |
32 |
| - Preferences prefs = Preferences.getInstance(store); |
33 |
| - PreferencesUtils.setPreferences(prefs); |
34 |
| - prefs.setTest(true); |
35 |
| - |
36 |
| - when(environment.getArch()).thenReturn("amd64"); |
37 |
| - when(environment.getOs()).thenReturn("linux"); |
38 |
| - when(environment.getDownloadBinaryName()).thenReturn("snyk-ls_testVersion_linux_amd64"); |
39 |
| - proxyServiceMock = mock(IProxyService.class); |
40 |
| - when(environment.getProxyService()).thenReturn(proxyServiceMock); |
41 |
| - } |
42 |
| - |
43 |
| - @AfterEach |
44 |
| - protected void tearDown() { |
45 |
| - lsFile.delete(); |
46 |
| - clearAllCaches(); |
47 |
| - } |
48 |
| - |
49 |
| - protected File getTempFile() { |
50 |
| - try { |
51 |
| - File tempFile = File.createTempFile("ls-test", "tmp"); |
52 |
| - tempFile.deleteOnExit(); |
53 |
| - return tempFile; |
54 |
| - } catch (IOException e) { |
55 |
| - throw new RuntimeException(e); |
56 |
| - } |
57 |
| - } |
| 24 | + protected LsRuntimeEnvironment environment = null; |
| 25 | + protected IProxyService proxyServiceMock; |
| 26 | + |
| 27 | + private File lsFile = getTempFile(); |
| 28 | + @Mock |
| 29 | + private ImageRegistry imageRegistry; |
| 30 | + |
| 31 | + @BeforeEach |
| 32 | + protected void setUp() { |
| 33 | + clearAllCaches(); |
| 34 | + if (lsFile.exists()) |
| 35 | + lsFile.delete(); |
| 36 | + lsFile = getTempFile(); |
| 37 | + environment = mock(LsRuntimeEnvironment.class); |
| 38 | + InMemoryPreferenceStore store = new InMemoryPreferenceStore(); |
| 39 | + Preferences prefs = Preferences.getInstance(store); |
| 40 | + PreferencesUtils.setPreferences(prefs); |
| 41 | + prefs.setTest(true); |
| 42 | + |
| 43 | + MockitoAnnotations.openMocks(this); |
| 44 | + when(imageRegistry.get(anyString())).thenReturn(mock(Image.class)); |
| 45 | + |
| 46 | + when(environment.getArch()).thenReturn("amd64"); |
| 47 | + when(environment.getOs()).thenReturn("linux"); |
| 48 | + when(environment.getDownloadBinaryName()).thenReturn("snyk-ls_testVersion_linux_amd64"); |
| 49 | + proxyServiceMock = mock(IProxyService.class); |
| 50 | + when(environment.getProxyService()).thenReturn(proxyServiceMock); |
| 51 | + } |
| 52 | + |
| 53 | + @AfterEach |
| 54 | + protected void tearDown() { |
| 55 | + lsFile.delete(); |
| 56 | + clearAllCaches(); |
| 57 | + } |
| 58 | + |
| 59 | + protected File getTempFile() { |
| 60 | + try { |
| 61 | + File tempFile = File.createTempFile("ls-test", "tmp"); |
| 62 | + tempFile.deleteOnExit(); |
| 63 | + return tempFile; |
| 64 | + } catch (IOException e) { |
| 65 | + throw new RuntimeException(e); |
| 66 | + } |
| 67 | + } |
58 | 68 | }
|
0 commit comments