1
+ /*
2
+ * This file is a part of BSL Language Server.
3
+ *
4
+ * Copyright (c) 2018-2023
5
+ * Alexey Sosnoviy <labotamy@gmail.com>, Nikita Fedkin <nixel2007@gmail.com> and contributors
6
+ *
7
+ * SPDX-License-Identifier: LGPL-3.0-or-later
8
+ *
9
+ * BSL Language Server is free software; you can redistribute it and/or
10
+ * modify it under the terms of the GNU Lesser General Public
11
+ * License as published by the Free Software Foundation; either
12
+ * version 3.0 of the License, or (at your option) any later version.
13
+ *
14
+ * BSL Language Server is distributed in the hope that it will be useful,
15
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
+ * Lesser General Public License for more details.
18
+ *
19
+ * You should have received a copy of the GNU Lesser General Public
20
+ * License along with BSL Language Server.
21
+ */
22
+ package com .github ._1c_syntax .bsl .languageserver .codelenses ;
23
+
24
+ import com .github ._1c_syntax .bsl .languageserver .codelenses .testrunner .TestRunnerAdapter ;
25
+ import com .github ._1c_syntax .bsl .languageserver .context .DocumentContext ;
26
+ import com .github ._1c_syntax .bsl .languageserver .events .LanguageServerInitializeRequestReceivedEvent ;
27
+ import com .github ._1c_syntax .bsl .languageserver .util .CleanupContextBeforeClassAndAfterEachTestMethod ;
28
+ import com .github ._1c_syntax .bsl .languageserver .util .TestUtils ;
29
+ import org .eclipse .lsp4j .ClientInfo ;
30
+ import org .eclipse .lsp4j .CodeLens ;
31
+ import org .eclipse .lsp4j .InitializeParams ;
32
+ import org .eclipse .lsp4j .services .LanguageServer ;
33
+ import org .junit .jupiter .api .BeforeEach ;
34
+ import org .junit .jupiter .api .Test ;
35
+ import org .springframework .beans .factory .annotation .Autowired ;
36
+ import org .springframework .boot .test .context .SpringBootTest ;
37
+ import org .springframework .boot .test .mock .mockito .SpyBean ;
38
+ import org .springframework .context .ApplicationEventPublisher ;
39
+
40
+ import java .util .List ;
41
+
42
+ import static com .github ._1c_syntax .bsl .languageserver .util .Assertions .assertThat ;
43
+ import static org .mockito .Mockito .mock ;
44
+ import static org .mockito .Mockito .when ;
45
+
46
+ @ SpringBootTest
47
+ @ CleanupContextBeforeClassAndAfterEachTestMethod
48
+ class RunAllTestsCodeLensSupplierTest {
49
+
50
+ @ Autowired
51
+ private RunAllTestsCodeLensSupplier supplier ;
52
+
53
+ @ Autowired
54
+ private ApplicationEventPublisher eventPublisher ;
55
+
56
+ @ SpyBean
57
+ private TestRunnerAdapter testRunnerAdapter ;
58
+
59
+ private DocumentContext documentContext ;
60
+
61
+ @ BeforeEach
62
+ void init () {
63
+ var filePath = "./src/test/resources/codelenses/RunAllTestsCodeLensSupplier.os" ;
64
+ documentContext = TestUtils .getDocumentContextFromFile (filePath );
65
+ }
66
+
67
+ @ Test
68
+ void noLensesIfClientIsNotSupported () {
69
+ // given
70
+ initializeServer ("Unknown client" );
71
+
72
+ // when
73
+ var codeLenses = supplier .getCodeLenses (documentContext );
74
+
75
+ // then
76
+ assertThat (codeLenses ).isEmpty ();
77
+ }
78
+
79
+ @ Test
80
+ void testDryRun () {
81
+ // given
82
+ initializeServer ("Visual Studio Code" );
83
+
84
+ // when
85
+ var codeLenses = supplier .getCodeLenses (documentContext );
86
+
87
+ // then
88
+ assertThat (codeLenses ).isNotNull ();
89
+ }
90
+
91
+ @ Test
92
+ void testRunWithMockedTestIds () {
93
+ // given
94
+ initializeServer ("Visual Studio Code" );
95
+
96
+ when (testRunnerAdapter .getTestIds (documentContext ))
97
+ .thenReturn (List .of ("testName" ));
98
+
99
+ // when
100
+ var codeLenses = supplier .getCodeLenses (documentContext );
101
+
102
+ // then
103
+ assertThat (codeLenses ).isNotNull ();
104
+ }
105
+
106
+ @ Test
107
+ void testResolve () {
108
+ // given
109
+ CodeLens codeLens = new CodeLens ();
110
+ DefaultCodeLensData codeLensData = new DefaultCodeLensData (
111
+ documentContext .getUri (),
112
+ supplier .getId ()
113
+ );
114
+
115
+ // when
116
+ var resolvedCodeLens = supplier .resolve (documentContext , codeLens , codeLensData );
117
+
118
+ // then
119
+ assertThat (resolvedCodeLens .getCommand ()).isNotNull ();
120
+ }
121
+
122
+ private void initializeServer (String clientName ) {
123
+ var initializeParams = new InitializeParams ();
124
+ initializeParams .setClientInfo (
125
+ new ClientInfo (clientName , "1.0.0" )
126
+ );
127
+
128
+ var event = new LanguageServerInitializeRequestReceivedEvent (
129
+ mock (LanguageServer .class ),
130
+ initializeParams
131
+ );
132
+ eventPublisher .publishEvent (event );
133
+ }
134
+ }
0 commit comments