2727import io .snyk .eclipse .plugin .analytics .AnalyticsEvent ;
2828import io .snyk .eclipse .plugin .analytics .AnalyticsSender ;
2929import io .snyk .eclipse .plugin .domain .ProductConstants ;
30- import io .snyk .eclipse .plugin .properties .preferences .InMemoryPreferenceStore ;
3130import io .snyk .eclipse .plugin .properties .preferences .Preferences ;
3231import io .snyk .eclipse .plugin .views .snyktoolview .ISnykToolView ;
3332import io .snyk .languageserver .LsBaseTest ;
4039import io .snyk .languageserver .protocolextension .messageObjects .scanResults .Issue ;
4140
4241class SnykExtendedLanguageClientTest extends LsBaseTest {
43- private InMemoryPreferenceStore store = new InMemoryPreferenceStore ();
4442 private SnykExtendedLanguageClient cut ;
4543 private Preferences pref ;
44+ private ISnykToolView toolWindowMock ;
45+
4646 @ BeforeEach
47+ @ Override
4748 protected void setUp () {
48- store = new InMemoryPreferenceStore ();
49- pref = Preferences .getInstance (store );
49+ super . setUp ();
50+ pref = Preferences .getInstance ();
5051 // we don't want the wizard to pop up, so we set a dummy token
5152 pref .store (Preferences .AUTH_TOKEN_KEY , "dummy" );
53+ toolWindowMock = mock (ISnykToolView .class );
5254 }
5355
5456 @ Test
@@ -59,7 +61,7 @@ void testAddTrustedPathsAddsPathToPreferenceStore() {
5961 cut = new SnykExtendedLanguageClient ();
6062 cut .addTrustedPaths (param );
6163
62- assertEquals ("trusted/path" , store . getString (Preferences .TRUSTED_FOLDERS , "" ));
64+ assertEquals ("trusted/path" , pref . getPref (Preferences .TRUSTED_FOLDERS , "" ));
6365 }
6466
6567 @ Test
@@ -70,7 +72,7 @@ void testAddTrustedPathsDeduplicatesAndTrims() {
7072 cut = new SnykExtendedLanguageClient ();
7173 cut .addTrustedPaths (param );
7274
73- assertEquals ("trusted/path" , store . getString (Preferences .TRUSTED_FOLDERS , "" ));
75+ assertEquals ("trusted/path" , pref . getPref (Preferences .TRUSTED_FOLDERS , "" ));
7476 }
7577
7678 @ Test
@@ -121,11 +123,11 @@ void testSendsPluginInstalledEventOnFirstStart() {
121123 var captor = ArgumentCaptor .forClass (AnalyticsEvent .class );
122124 verify (asMock ).logEvent (captor .capture (), any ());
123125 verifyNoMoreInteractions (asMock );
124-
126+
125127 assertEquals ("plugin installed" , captor .getValue ().getInteractionType ());
126128 }
127129 }
128-
130+
129131 @ Test
130132 void testDoesNotSendPluginInstalledEventOnSecondStart () {
131133 try (MockedStatic <AnalyticsSender > mockedAnalyticsSender = mockStatic (AnalyticsSender .class )) {
@@ -138,7 +140,7 @@ void testDoesNotSendPluginInstalledEventOnSecondStart() {
138140 verifyNoMoreInteractions (asMock );
139141 }
140142 }
141-
143+
142144 @ Test
143145 void testPublishDiagnosticsShouldChangeCache () {
144146 // Test Add to cache
@@ -151,8 +153,8 @@ void testPublishDiagnosticsShouldChangeCache() {
151153 var diagnostic = new Diagnostic ();
152154 diagnostic .setSource ("Snyk Code" );
153155
154- var issue = new Issue ("myId" , null , null , null , false , null , false , null , null , null );
155- ObjectMapper objectMapper = new ObjectMapper ();
156+ var issue = new Issue ("myId" , null , null , null , false , null , false , null , null , null );
157+ ObjectMapper objectMapper = new ObjectMapper ();
156158 String res ;
157159 try {
158160 res = objectMapper .writeValueAsString (issue );
@@ -165,14 +167,13 @@ void testPublishDiagnosticsShouldChangeCache() {
165167 var future = cut .publishDiagnostics316 (param );
166168 try {
167169 future .get (5 , TimeUnit .SECONDS );
168- }
169- catch (Exception ex ){
170+ } catch (Exception ex ) {
170171
171172 }
172173 var actualIssueList = issueCache .getCodeIssuesForPath (filePath );
173174 assertEquals (1 , actualIssueList .size ());
174175 assertEquals ("myId" , actualIssueList .stream ().findFirst ().get ().id ());
175-
176+
176177 // Test remove from cache
177178 param = new PublishDiagnosticsParams ();
178179 param .setUri (uri );
@@ -181,55 +182,54 @@ void testPublishDiagnosticsShouldChangeCache() {
181182 future = cut .publishDiagnostics316 (param );
182183 try {
183184 future .get (5 , TimeUnit .SECONDS );
184- }
185- catch (Exception ex ){
185+ } catch (Exception ex ) {
186186
187187 }
188188 assertEquals (true , issueCache .getCodeIssuesForPath (filePath ).isEmpty ());
189189 }
190-
190+
191191 @ Test
192- void testSnykScanUpdatesRootNodeStatus () {
192+ void testSnykScanUpdatesRootNodeStatus () {
193193 var param = new SnykScanParam ();
194194 param .setStatus ("inProgress" );
195195 param .setProduct (ProductConstants .CODE );
196196 param .setFolderPath ("a/b/c" );
197- ISnykToolView toolWindowMock = mock (ISnykToolView .class );
198197 TreeNode productNode = new TreeNode ("Code Issues" );
199198 when (toolWindowMock .getProductNode (param .getProduct ())).thenReturn (productNode );
200-
199+
201200 cut = new SnykExtendedLanguageClient ();
202201 cut .setToolWindow (toolWindowMock );
203202 cut .snykScan (param );
204-
203+
205204 // expect "scanning..."
206205 verify (toolWindowMock ).getProductNode (param .getProduct ());
207206 verify (toolWindowMock ).setNodeText (productNode , "Scanning..." );
208207 }
209-
208+
210209 @ Test
211210 void testSnykScanAddsToScanStateHashMap () {
212211 var scanState = ScanState .getInstance ();
213212 var param = new SnykScanParam ();
214213 param .setStatus ("inProgress" );
215214 param .setProduct (ProductConstants .CODE );
216215 param .setFolderPath ("a/b/c" );
217-
216+
218217 cut = new SnykExtendedLanguageClient ();
218+ cut .setToolWindow (toolWindowMock );
219219 cut .snykScan (param );
220-
220+
221221 var expectedKey = new ScanInProgressKey ("a/b/c" , "code" );
222222 var actualState = scanState .isScanInProgress (expectedKey );
223223 assertEquals (true , actualState );
224-
224+
225225 param = new SnykScanParam ();
226226 param .setStatus ("success" );
227227 param .setProduct (ProductConstants .CODE );
228228 param .setFolderPath ("a/b/c" );
229-
229+
230230 cut = new SnykExtendedLanguageClient ();
231231 cut .snykScan (param );
232-
232+
233233 expectedKey = new ScanInProgressKey ("a/b/c" , "code" );
234234 actualState = scanState .isScanInProgress (expectedKey );
235235 assertEquals (false , actualState );
0 commit comments