Skip to content

Commit 7f90596

Browse files
committed
Тесты на новый компонент
1 parent 8c3ab32 commit 7f90596

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
* This file is a part of BSL Language Server.
3+
*
4+
* Copyright (c) 2018-2022
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;
23+
24+
import com.github._1c_syntax.bsl.languageserver.configuration.LanguageServerConfiguration;
25+
import com.github._1c_syntax.bsl.languageserver.context.ServerContext;
26+
import com.github._1c_syntax.bsl.languageserver.context.events.ServerContextPopulatedEvent;
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.services.LanguageClient;
30+
import org.junit.jupiter.api.Test;
31+
import org.springframework.beans.factory.annotation.Autowired;
32+
import org.springframework.boot.test.context.SpringBootTest;
33+
import org.springframework.boot.test.mock.mockito.MockBean;
34+
import org.springframework.boot.test.mock.mockito.SpyBean;
35+
36+
import static org.mockito.ArgumentMatchers.any;
37+
import static org.mockito.Mockito.never;
38+
import static org.mockito.Mockito.times;
39+
import static org.mockito.Mockito.verify;
40+
41+
@SpringBootTest
42+
@CleanupContextBeforeClassAndAfterEachTestMethod
43+
class AnalyzeProjectOnStartTest {
44+
45+
@Autowired
46+
private AnalyzeProjectOnStart analyzeProjectOnStart;
47+
48+
@Autowired
49+
private LanguageServerConfiguration configuration;
50+
@SpyBean
51+
private ServerContext serverContext;
52+
53+
@MockBean
54+
private LanguageClient languageClient;
55+
@Autowired
56+
private LanguageClientHolder languageClientHolder;
57+
58+
@Test
59+
void noExecutionIfDisabled() {
60+
// given
61+
configuration.getDiagnosticsOptions().setAnalyzeOnStart(false);
62+
languageClientHolder.connect(languageClient);
63+
64+
// when
65+
analyzeProjectOnStart.handleEvent(new ServerContextPopulatedEvent(serverContext));
66+
67+
verify(serverContext, never()).getDocuments(any());
68+
verify(languageClient, never()).publishDiagnostics(any());
69+
}
70+
71+
@Test
72+
void noExecutionIfLanguageClientIsNotConnected() {
73+
// given
74+
configuration.getDiagnosticsOptions().setAnalyzeOnStart(true);
75+
languageClientHolder.connect(null);
76+
77+
// when
78+
analyzeProjectOnStart.handleEvent(new ServerContextPopulatedEvent(serverContext));
79+
80+
verify(serverContext, never()).getDocuments(any());
81+
verify(languageClient, never()).publishDiagnostics(any());
82+
}
83+
84+
@Test
85+
void runAnalysisIfEnabled() {
86+
// given
87+
configuration.getDiagnosticsOptions().setAnalyzeOnStart(true);
88+
languageClientHolder.connect(languageClient);
89+
90+
var documentContext = TestUtils.getDocumentContext("A = 0", serverContext);
91+
92+
// when
93+
analyzeProjectOnStart.handleEvent(new ServerContextPopulatedEvent(serverContext));
94+
95+
verify(serverContext, times(1)).getDocuments();
96+
verify(languageClient, times(1)).publishDiagnostics(any());
97+
}
98+
}

0 commit comments

Comments
 (0)