Skip to content

Commit 55a9244

Browse files
committed
more tests
1 parent 74a766b commit 55a9244

File tree

4 files changed

+167
-2
lines changed

4 files changed

+167
-2
lines changed
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
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+
}

src/test/java/com/github/_1c_syntax/bsl/languageserver/codelenses/RunTestCodeLensSupplierTest.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
*/
2222
package com.github._1c_syntax.bsl.languageserver.codelenses;
2323

24+
import com.github._1c_syntax.bsl.languageserver.codelenses.testrunner.TestRunnerAdapter;
2425
import com.github._1c_syntax.bsl.languageserver.context.DocumentContext;
2526
import com.github._1c_syntax.bsl.languageserver.events.LanguageServerInitializeRequestReceivedEvent;
2627
import com.github._1c_syntax.bsl.languageserver.util.CleanupContextBeforeClassAndAfterEachTestMethod;
@@ -33,11 +34,14 @@
3334
import org.junit.jupiter.api.Test;
3435
import org.springframework.beans.factory.annotation.Autowired;
3536
import org.springframework.boot.test.context.SpringBootTest;
37+
import org.springframework.boot.test.mock.mockito.SpyBean;
3638
import org.springframework.context.ApplicationEventPublisher;
3739

40+
import java.util.List;
41+
3842
import static com.github._1c_syntax.bsl.languageserver.util.Assertions.assertThat;
3943
import static org.mockito.Mockito.mock;
40-
44+
import static org.mockito.Mockito.when;
4145

4246
@SpringBootTest
4347
@CleanupContextBeforeClassAndAfterEachTestMethod
@@ -49,11 +53,14 @@ class RunTestCodeLensSupplierTest {
4953
@Autowired
5054
private ApplicationEventPublisher eventPublisher;
5155

56+
@SpyBean
57+
private TestRunnerAdapter testRunnerAdapter;
58+
5259
private DocumentContext documentContext;
5360

5461
@BeforeEach
5562
void init() {
56-
var filePath = "./src/test/resources/codelenses/RunTestCodeLensSupplier.bsl";
63+
var filePath = "./src/test/resources/codelenses/RunTestCodeLensSupplier.os";
5764
documentContext = TestUtils.getDocumentContextFromFile(filePath);
5865
}
5966

@@ -81,6 +88,21 @@ void testDryRun() {
8188
assertThat(codeLenses).isNotNull();
8289
}
8390

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+
84106
@Test
85107
void testResolve() {
86108
// given
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
&Тест
2+
Процедура Тест1() Экспорт
3+
А = 0;
4+
КонецПроцедуры
5+
6+
&Тест
7+
Процедура Тест2() Экспорт
8+
Б = 0;
9+
КонецПроцедуры

0 commit comments

Comments
 (0)