1313package org .eclipse .lsp4e .test ;
1414
1515import static org .eclipse .lsp4e .LanguageServiceAccessor .hasActiveLanguageServers ;
16- import static org .eclipse .lsp4e .test .utils .TestUtils .*;
17- import static org .junit .Assert .*;
16+ import static org .eclipse .lsp4e .test .utils .TestUtils .createUniqueTestFile ;
17+ import static org .eclipse .lsp4e .test .utils .TestUtils .openEditor ;
18+ import static org .eclipse .lsp4e .test .utils .TestUtils .waitForCondition ;
19+ import static org .junit .jupiter .api .Assertions .assertEquals ;
20+ import static org .junit .jupiter .api .Assertions .assertFalse ;
21+ import static org .junit .jupiter .api .Assertions .assertNotEquals ;
22+ import static org .junit .jupiter .api .Assertions .assertNull ;
23+ import static org .junit .jupiter .api .Assertions .assertThrows ;
24+ import static org .junit .jupiter .api .Assertions .assertTrue ;
25+ import static org .junit .jupiter .api .Assumptions .assumeTrue ;
1826
1927import java .util .Collections ;
2028import java .util .List ;
5563import org .eclipse .swt .custom .StyledText ;
5664import org .eclipse .swt .widgets .Display ;
5765import org .eclipse .ui .tests .harness .util .DisplayHelper ;
58- import org .junit .Assume ;
59- import org .junit .Test ;
66+ import org .junit .jupiter .api .Test ;
6067
6168public class LanguageServersTest extends AbstractTestWithProject {
6269
@@ -172,11 +179,11 @@ public synchronized CompletableFuture<Hover> hover(HoverParams position) {
172179 .withCapability (ServerCapabilities ::getHoverProvider )
173180 .computeAll (ls -> ls .getTextDocumentService ().hover (params ).thenApply (h -> h .getContents ().getLeft ().get (0 ).getLeft ()));
174181
175- assertEquals ("Should have had two responses" , 2 , result . size () );
182+ assertEquals (2 , result . size (), "Should have had two responses" );
176183
177184 final Object first = CompletableFuture .anyOf (result .get (0 ), result .get (1 )).join ();
178185
179- assertEquals ("HoverContent1 should have returned first, independently" , "HoverContent1" , first );
186+ assertEquals ("HoverContent1" , first , "HoverContent1 should have returned first, independently" );
180187
181188 List <String > hovers = result .stream ().map (CompletableFuture ::join ).toList ();
182189
@@ -195,7 +202,7 @@ public synchronized CompletableFuture<Hover> hover(HoverParams position) {
195202 @ Test
196203 public void testCollectAllUserCannotBlockListener () throws Exception {
197204 // This test will only work if a minimum of two tasks can be run in the common pool without blocking!
198- Assume . assumeTrue ("Test skipped as common thread pool does not have multiple executors" , ForkJoinPool . commonPool (). getParallelism () >= 2 );
205+ assumeTrue (ForkJoinPool . commonPool (). getParallelism () >= 2 , "Test skipped as common thread pool does not have multiple executors" );
199206 final var hoverResponse = new Hover (List .of (Either .forLeft ("HoverContent" )), new Range (new Position (0 , 0 ), new Position (0 , 10 )));
200207 MockLanguageServer .INSTANCE .setHover (hoverResponse );
201208
@@ -235,8 +242,8 @@ public void testCollectAllUserCannotBlockListener() throws Exception {
235242
236243 final String resultThread = resultThreadFuture .join ();
237244
238- assertTrue ("Second hover response should not have been blocked by the first but took " + secondResponseTime + " ms" , secondResponseTime < 1000 );
239- assertTrue (" Result should not have run on an LS listener thread but ran on " + resultThread , ! resultThread . startsWith ( "LS" ) );
245+ assertTrue (secondResponseTime < 1000 , "Second hover response should not have been blocked by the first but took " + secondResponseTime + " ms" );
246+ assertTrue (! resultThread . startsWith ( "LS" ), " Result should not have run on an LS listener thread but ran on " + resultThread );
240247 }
241248
242249 @ Test
@@ -283,7 +290,7 @@ public synchronized CompletableFuture<Hover> hover(HoverParams position) {
283290 Optional <String > result = response .join ();
284291 assertTrue (result .isPresent ());
285292
286- assertEquals ("HoverContent1 should have arrived first" , "HoverContent1" , result . get () );
293+ assertEquals ("HoverContent1" , result . get (), "HoverContent1 should have arrived first" );
287294
288295 // It won't *normally) matter in production but because the tests run quickly, make sure the test teardown doesn't
289296 // occur before the slower, ignored result has completed, otherwise will get a load of console noise
@@ -331,9 +338,9 @@ public synchronized CompletableFuture<Hover> hover(HoverParams position) {
331338 .computeFirst (ls -> ls .getTextDocumentService ().hover (params ).thenApply (h -> h == null ? null : h .getContents ().getLeft ().get (0 ).getLeft ()));
332339
333340 Optional <String > result = response .join ();
334- assertTrue ("Should have returned a result" , result . isPresent () );
341+ assertTrue (result . isPresent (), "Should have returned a result" );
335342
336- assertEquals ("HoverContent2 should have been the result" , "HoverContent2" , result . get () );
343+ assertEquals ("HoverContent2" , result . get (), "HoverContent2 should have been the result" );
337344
338345 }
339346
@@ -366,7 +373,7 @@ public synchronized CompletableFuture<Hover> hover(HoverParams position) {
366373 .computeFirst (ls -> ls .getTextDocumentService ().hover (params ).thenApply (h -> h == null ? null : h .getContents ().getLeft ().get (0 ).getLeft ()));
367374
368375 Optional <String > result = response .join ();
369- assertTrue ("Should not have returned a result" , result . isEmpty () );
376+ assertTrue (result . isEmpty (), "Should not have returned a result" );
370377 }
371378
372379 @ Test
@@ -410,9 +417,9 @@ public synchronized CompletableFuture<Hover> hover(HoverParams position) {
410417 .computeFirst (ls -> ls .getTextDocumentService ().hover (params ).thenApply (h -> h == null ? Collections .emptyList () : List .of (h .getContents ().getLeft ().get (0 ).getLeft ())));
411418
412419 Optional <List <String >> result = response .join ();
413- assertTrue ("Should have returned a result" , result . isPresent () );
420+ assertTrue (result . isPresent (), "Should have returned a result" );
414421
415- assertEquals ("HoverContent2 should have been the result " , "HoverContent2" , result .get ().get (0 ));
422+ assertEquals ("HoverContent2" , result .get ().get (0 ), "HoverContent2 should have been the result" );
416423 }
417424
418425 /**
@@ -492,7 +499,7 @@ public synchronized CompletableFuture<Hover> hover(HoverParams position) {
492499 message .append (" Too Late " );message .append (i );
493500 message .append (System .lineSeparator ());
494501 });
495- assertTrue (message . toString (), tooEarlyHover .isEmpty () && tooLateHover .isEmpty ());
502+ assertTrue (tooEarlyHover .isEmpty () && tooLateHover .isEmpty (), message . toString ());
496503 }
497504
498505 /**
@@ -580,8 +587,8 @@ public synchronized CompletableFuture<Hover> hover(HoverParams position) {
580587
581588 final long finishTime = System .currentTimeMillis () - startTime ;
582589
583- assertTrue (String .format ("Dispatch should not have blocked but took %d ms vs overall test time of %d ms" , dispatchTime , finishTime ), dispatchTime < 1000 );
584- assertEquals ("Should not have been any messages dispatched on UI thread" , 0 , uiDispatchCount . get () );
590+ assertTrue (dispatchTime < 1000 , String .format ("Dispatch should not have blocked but took %d ms vs overall test time of %d ms" , dispatchTime , finishTime ));
591+ assertEquals (0 , uiDispatchCount . get (), "Should not have been any messages dispatched on UI thread" );
585592 }
586593
587594 @ Test
@@ -590,7 +597,7 @@ public void testAnyMatchingIsNonBlocking() throws Exception {
590597 long start = System .currentTimeMillis ();
591598 assertFalse (LanguageServers .forProject (project ).anyMatching ());
592599 long duration = System .currentTimeMillis () - start ;
593- assertTrue ("LanguageServers.anyMatching() took too long: " + duration + "ms" , duration < 100 );
600+ assertTrue (duration < 100 , "LanguageServers.anyMatching() took too long: " + duration + "ms" );
594601
595602 // test with one slow LS available
596603 MockLanguageServer .INSTANCE .setTimeToProceedQueries (5_000 );
@@ -600,7 +607,7 @@ public void testAnyMatchingIsNonBlocking() throws Exception {
600607 try {
601608 assertTrue (LanguageServers .forProject (project ).anyMatching ());
602609 duration = System .currentTimeMillis () - start ;
603- assertTrue ("LanguageServers.anyMatching() took too long: " + duration + "ms" , duration < 100 );
610+ assertTrue (duration < 100 , "LanguageServers.anyMatching() took too long: " + duration + "ms" );
604611 } finally {
605612 editor1 .getSite ().getPage ().closeEditor (editor1 , false );
606613 }
@@ -617,7 +624,7 @@ public void testNoMatchingServers() throws Exception {
617624
618625 LanguageServerDocumentExecutor executor = LanguageServers .forDocument (document ).withFilter (sc -> false );
619626
620- assertFalse ("Should not have been any valid LS" , executor . anyMatching () );
627+ assertFalse (executor . anyMatching (), "Should not have been any valid LS" );
621628
622629 final var params = new HoverParams ();
623630 final var position = new Position ();
@@ -626,10 +633,10 @@ public void testNoMatchingServers() throws Exception {
626633 params .setPosition (position );
627634
628635 Optional <?> result = executor .computeFirst (ls -> ls .getTextDocumentService ().hover (params )).get (10 , TimeUnit .SECONDS );
629- assertFalse ("Should not have had a result" , result . isPresent () );
636+ assertFalse (result . isPresent (), "Should not have had a result" );
630637
631638 List <?> collectedResult = executor .collectAll (ls -> ls .getTextDocumentService ().hover (params )).get (10 , TimeUnit .SECONDS );
632- assertTrue ("Should not have had a result" , collectedResult . isEmpty () );
639+ assertTrue (collectedResult . isEmpty (), "Should not have had a result" );
633640
634641 List <CompletableFuture <Hover >> allResults = executor .computeAll (ls -> ls .getTextDocumentService ().hover (params ));
635642 for (CompletableFuture <Hover > f : allResults ) {
@@ -638,7 +645,7 @@ public void testNoMatchingServers() throws Exception {
638645 }
639646 }
640647
641- @ Test ( expected = CompletionException . class )
648+ @ Test
642649 public void testComputeFirstBubblesException () throws Exception {
643650 MockLanguageServer .INSTANCE .setTextDocumentService (new MockTextDocumentService (MockLanguageServer .INSTANCE ::buildMaybeDelayedFuture ) {
644651 @ Override
@@ -664,11 +671,14 @@ public synchronized CompletableFuture<Hover> hover(HoverParams position) {
664671 position .setLine (0 );
665672 params .setPosition (position );
666673
667- CompletableFuture <Optional <String >> response = LanguageServers .forDocument (document )
668- .withCapability (ServerCapabilities ::getHoverProvider )
669- .computeFirst (ls -> ls .getTextDocumentService ().hover (params ).thenApply (h -> h == null ? null : h .getContents ().getLeft ().get (0 ).getLeft ()));
674+ assertThrows (CompletionException .class , () -> {
675+ CompletableFuture <Optional <String >> response = LanguageServers .forDocument (document )
676+ .withCapability (ServerCapabilities ::getHoverProvider )
677+ .computeFirst (ls -> ls .getTextDocumentService ().hover (params )
678+ .thenApply (h -> h == null ? null : h .getContents ().getLeft ().get (0 ).getLeft ()));
670679
671- response .join ();
680+ response .join ();
681+ });
672682 }
673683
674684 /**
@@ -700,8 +710,8 @@ public void testWrapperWrapsSameLS() throws Exception {
700710
701711 final var matching = new AtomicInteger ();
702712
703- assertEquals ("Should have had two responses" , 2 , result . size () );
704- assertNotEquals ("LS should have been different proxies" , result .get (0 ).second (), result .get (1 ).second ());
713+ assertEquals (2 , result . size (), "Should have had two responses" );
714+ assertNotEquals (result .get (0 ).second (), result .get (1 ).second (), "LS should have been different proxies" );
705715 result .forEach (p -> {
706716 p .first ().execute (ls -> {
707717 if (ls == p .second ()) {
@@ -711,7 +721,7 @@ public void testWrapperWrapsSameLS() throws Exception {
711721 }).join ();
712722 });
713723
714- assertEquals ("Wrapper should have used same LS" , 2 , matching . get () );
724+ assertEquals (2 , matching . get (), "Wrapper should have used same LS" );
715725 }
716726
717727 /**
0 commit comments