Skip to content

Commit

Permalink
Merge pull request #510 from mezarin/addMissingJaxrsTests
Browse files Browse the repository at this point in the history
Add missing JAX-RS code action tests
  • Loading branch information
mezarin authored Jan 12, 2024
2 parents 9f30d72 + efb5bde commit 53004c0
Showing 1 changed file with 52 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2021, 2023 IBM Corporation, Matthew Shocrylas and others.
* Copyright (c) 2021, 2024 IBM Corporation, Matthew Shocrylas and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand All @@ -13,16 +13,23 @@

package org.eclipse.lsp4jakarta.jdt.jaxrs;

import static org.eclipse.lsp4jakarta.jdt.core.JakartaForJavaAssert.assertJavaCodeAction;
import static org.eclipse.lsp4jakarta.jdt.core.JakartaForJavaAssert.assertJavaDiagnostics;
import static org.eclipse.lsp4jakarta.jdt.core.JakartaForJavaAssert.ca;
import static org.eclipse.lsp4jakarta.jdt.core.JakartaForJavaAssert.createCodeActionParams;
import static org.eclipse.lsp4jakarta.jdt.core.JakartaForJavaAssert.d;
import static org.eclipse.lsp4jakarta.jdt.core.JakartaForJavaAssert.te;

import java.util.Arrays;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.Path;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.lsp4j.CodeAction;
import org.eclipse.lsp4j.Diagnostic;
import org.eclipse.lsp4j.DiagnosticSeverity;
import org.eclipse.lsp4j.TextEdit;
import org.eclipse.lsp4jakarta.commons.JakartaJavaCodeActionParams;
import org.eclipse.lsp4jakarta.commons.JakartaJavaDiagnosticsParams;
import org.eclipse.lsp4jakarta.jdt.core.BaseJakartaTest;
import org.eclipse.lsp4jakarta.jdt.core.utils.IJDTUtils;
Expand Down Expand Up @@ -80,7 +87,7 @@ public void NoPublicConstructor() throws Exception {
JakartaJavaDiagnosticsParams diagnosticsParams = new JakartaJavaDiagnosticsParams();
diagnosticsParams.setUris(Arrays.asList(uri));

// test expected diagnostics
// Test expected diagnostics.
Diagnostic d1 = d(7, 12, 36,
"Root resource classes are instantiated by the JAX-RS runtime and MUST have a public constructor.",
DiagnosticSeverity.Error, "jakarta-jaxrs", "NoPublicConstructors");
Expand All @@ -90,6 +97,26 @@ public void NoPublicConstructor() throws Exception {
DiagnosticSeverity.Error, "jakarta-jaxrs", "NoPublicConstructors");

assertJavaDiagnostics(diagnosticsParams, IJDT_UTILS, d1, d2);

// Test expected quick fixes for diagnostic 1 (private constructor).
String newText1 = "public NoPublicConstructorClass() {\n }\n\n ";
String newText2 = "public";
JakartaJavaCodeActionParams codeActionParams1 = createCodeActionParams(uri, d1);
TextEdit te1 = te(7, 4, 7, 4, newText1);
TextEdit te2 = te(7, 4, 7, 11, newText2);
CodeAction ca1 = ca(uri, "Add a default 'public' constructor to this class", d1, te1);
CodeAction ca2 = ca(uri, "Make constructor public", d1, te2);

assertJavaCodeAction(codeActionParams1, IJDT_UTILS, ca1, ca2);

// Test expected quick fixes for diagnostic 2 (protected constructor).
JakartaJavaCodeActionParams codeActionParams2 = createCodeActionParams(uri, d2);
TextEdit te3 = te(7, 4, 7, 4, newText1);
TextEdit te4 = te(11, 4, 11, 13, newText2);
CodeAction ca3 = ca(uri, "Add a default 'public' constructor to this class", d2, te3);
CodeAction ca4 = ca(uri, "Make constructor public", d2, te4);

assertJavaCodeAction(codeActionParams2, IJDT_UTILS, ca3, ca4);
}

@Test
Expand All @@ -101,6 +128,7 @@ public void NoPublicConstructorProviderClass() throws Exception {
JakartaJavaDiagnosticsParams diagnosticsParams = new JakartaJavaDiagnosticsParams();
diagnosticsParams.setUris(Arrays.asList(uri));

// Test expected diagnostics.
Diagnostic d1 = d(19, 12, 44,
"Provider classes are instantiated by the JAX-RS runtime and MUST have a public constructor.",
DiagnosticSeverity.Error, "jakarta-jaxrs", "NoPublicConstructors");
Expand All @@ -110,5 +138,27 @@ public void NoPublicConstructorProviderClass() throws Exception {
DiagnosticSeverity.Error, "jakarta-jaxrs", "NoPublicConstructors");

assertJavaDiagnostics(diagnosticsParams, IJDT_UTILS, d1, d2);

// Test expected quick fixes for diagnostic 1 (private constructor).
String newText1 = "public NoPublicConstructorProviderClass() {\n }\n\n ";
String newText2 = "public";

JakartaJavaCodeActionParams codeActionParams = createCodeActionParams(uri, d1);
TextEdit te1 = te(19, 4, 19, 4, newText1);
TextEdit te2 = te(19, 4, 19, 11, newText2);
CodeAction ca1 = ca(uri, "Add a default 'public' constructor to this class", d1, te1);
CodeAction ca2 = ca(uri, "Make constructor public", d1, te2);

assertJavaCodeAction(codeActionParams, IJDT_UTILS, ca1, ca2);

// Test expected quick fixes for diagnostic 2 (protected constructor).
JakartaJavaCodeActionParams codeActionParams2 = createCodeActionParams(uri, d2);
TextEdit te3 = te(19, 4, 19, 4, newText1);
TextEdit te4 = te(23, 4, 23, 13, newText2);
CodeAction ca3 = ca(uri, "Add a default 'public' constructor to this class", d2, te3);
CodeAction ca4 = ca(uri, "Make constructor public", d2, te4);

assertJavaCodeAction(codeActionParams2, IJDT_UTILS, ca3, ca4);

}
}

0 comments on commit 53004c0

Please sign in to comment.