Skip to content

Commit

Permalink
improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
saberduck committed May 23, 2024
1 parent 450ffd3 commit cbffffd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import static org.sonar.api.utils.log.LoggerLevel.DEBUG;
import static org.sonar.api.utils.log.LoggerLevel.ERROR;
import static org.sonar.api.utils.log.LoggerLevel.INFO;
import static org.sonar.api.utils.log.LoggerLevel.WARN;
import static org.slf4j.event.Level.DEBUG;
import static org.slf4j.event.Level.ERROR;
import static org.slf4j.event.Level.INFO;
import static org.slf4j.event.Level.WARN;
import static org.sonar.plugins.javascript.bridge.AnalysisMode.DEFAULT_LINTER_ID;
import static org.sonar.plugins.javascript.nodejs.NodeCommandBuilderImpl.NODE_EXECUTABLE_PROPERTY;

Expand All @@ -52,7 +52,6 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.junit.jupiter.api.io.TempDir;
import org.slf4j.event.Level;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
Expand All @@ -79,7 +78,7 @@ class BridgeServerImplTest {
private static final int TEST_TIMEOUT_SECONDS = 1;

@RegisterExtension
public LogTesterJUnit5 logTester = new LogTesterJUnit5().setLevel(Level.DEBUG);
public LogTesterJUnit5 logTester = new LogTesterJUnit5().setLevel(DEBUG);

@TempDir
Path moduleBase;
Expand All @@ -103,7 +102,7 @@ class BridgeServerImplTest {
private EmbeddedNode unsupportedEmbeddedRuntime;

@BeforeEach
public void setUp() throws Exception {
public void setUp() {
context = SensorContextTester.create(moduleBase);
context.fileSystem().setWorkDir(workDir);
tempFolder = new DefaultTempFolder(tempDir, true);
Expand All @@ -124,7 +123,7 @@ public void tearDown() {
}

@Test
void should_throw_when_not_existing_script() throws Exception {
void should_throw_when_not_existing_script() {
bridgeServer = createBridgeServer("NOT_EXISTING.js");
List<Path> deployedBundles = emptyList();

Expand All @@ -134,7 +133,7 @@ void should_throw_when_not_existing_script() throws Exception {
}

@Test
void should_throw_if_failed_to_build_node_command() throws Exception {
void should_throw_if_failed_to_build_node_command() {
NodeCommandBuilder nodeCommandBuilder = mock(
NodeCommandBuilder.class,
invocation -> {
Expand Down Expand Up @@ -184,7 +183,7 @@ void should_get_answer_from_server() throws Exception {
.setContents("alert('Fly, you fools!')")
.build();
JsAnalysisRequest request = createRequest(inputFile);
assertThat(bridgeServer.analyzeJavaScript(request).issues()).isEmpty();
assertThat(bridgeServer.analyzeJavaScript(request).issues()).hasSize(1);
}

@Test
Expand Down Expand Up @@ -238,7 +237,7 @@ void should_get_answer_from_server_for_ts_request() throws Exception {
null,
DEFAULT_LINTER_ID
);
assertThat(bridgeServer.analyzeTypeScript(request).issues()).isEmpty();
assertThat(bridgeServer.analyzeTypeScript(request).issues()).hasSize(1);
}

@Test
Expand All @@ -251,7 +250,7 @@ void should_get_answer_from_server_for_yaml_request() throws Exception {
.setContents("alert('Fly, you fools!')")
.build();
var request = createRequest(inputFile);
assertThat(bridgeServer.analyzeYaml(request).issues()).isEmpty();
assertThat(bridgeServer.analyzeYaml(request).issues()).hasSize(1);
}

@Nonnull
Expand Down Expand Up @@ -280,7 +279,7 @@ void should_get_answer_from_server_for_program_based_requests() throws Exception
// values from 'startServer.js'
assertThat(programCreated.programId()).isEqualTo("42");
assertThat(programCreated.projectReferences()).isEmpty();
assertThat(programCreated.files().size()).isEqualTo(3);
assertThat(programCreated.files()).hasSize(3);

JsAnalysisRequest request = new JsAnalysisRequest(
"/absolute/path/file.ts",
Expand All @@ -292,7 +291,7 @@ void should_get_answer_from_server_for_program_based_requests() throws Exception
programCreated.programId(),
DEFAULT_LINTER_ID
);
assertThat(bridgeServer.analyzeTypeScript(request).issues()).isEmpty();
assertThat(bridgeServer.analyzeTypeScript(request).issues()).hasSize(1);

assertThat(bridgeServer.deleteProgram(programCreated)).isTrue();
}
Expand Down Expand Up @@ -333,11 +332,11 @@ void should_get_answer_from_server_for_css_request() throws Exception {
inputFile.type().toString(),
Collections.emptyList()
);
assertThat(bridgeServer.analyzeCss(request).issues()).isEmpty();
assertThat(bridgeServer.analyzeCss(request).issues()).hasSize(1);
}

@Test
void should_throw_if_failed_to_start() throws Exception {
void should_throw_if_failed_to_start() {
bridgeServer = createBridgeServer("throw.js");
List<Path> deployedBundles = emptyList();

Expand Down Expand Up @@ -723,7 +722,7 @@ void test_ucfg_bundle_version() throws Exception {
}

@Test
void should_not_deploy_runtime_if_sonar_nodejs_executable_is_set() throws Exception {
void should_not_deploy_runtime_if_sonar_nodejs_executable_is_set() {
var existingDoesntMatterScript = "logging.js";
bridgeServer = createBridgeServer(existingDoesntMatterScript);
context.setSettings(new MapSettings().setProperty(NODE_EXECUTABLE_PROPERTY, "whatever"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,14 @@ const requestHandler = (request, response) => {
// /analyze-js
// /analyze-ts
// /analyze-css
response.end('{ issues: [] }');
// objects are created to have test coverage
response.end(`{ issues: [{line:0, column:0, endLine:0, endColumn:0,
quickFixes: [
{
edits: [{
loc: {}}]}]}],
highlights: [{location: {startLine: 0, startColumn: 0, endLine: 0, endColumn: 0}}],
metrics: {}, highlightedSymbols: [{}], cpdTokens: [{}] }`);
}
});
};
Expand Down

0 comments on commit cbffffd

Please sign in to comment.