Skip to content

Commit

Permalink
Added integration test for generic managed bean class
Browse files Browse the repository at this point in the history
  • Loading branch information
KidoVin01 committed Dec 1, 2021
1 parent b3ac527 commit d06b37a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,10 @@ else if (!hasParameterizedInjectConstructor)
*/
if (isManagedBean) {
boolean isClassGeneric = type.getTypeParameters().length != 0;

if (isClassGeneric && managedBeanAnnotations.stream()
.anyMatch(annotation -> !annotation.equals("Dependent"))) {
diagnostics.add(createDiagnostic(type, unit, "Managed bean class of generic type must have scope @dependent.",
boolean isDependent = !managedBeanAnnotations.stream().anyMatch(annotation -> !annotation.equals("Dependent"));
if (isClassGeneric && !isDependent) {
diagnostics.add(createDiagnostic(type, unit, "Managed bean class of generic type must have scope @Dependent",
DIAGNOSTIC_CODE));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@

package org.eclipse.lsp4jakarta.jdt.core.di;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

import org.eclipse.lsp4j.DiagnosticSeverity;

public class DependencyInjectionConstants {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import jakarta.enterprise.context.*;

@RequestScoped
public class ManagedBean {
public class ManagedBean<T> {
public int a;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,27 @@ public void managedBeanAnnotations() throws Exception {
diagnosticsParams.setUris(Arrays.asList(uri));

// test expected diagnostic
Diagnostic d = d(6, 12, 13,
Diagnostic d1 = d(6, 12, 13,
"A managed bean with a non-static public field must not declare any scope other than @Dependent",
DiagnosticSeverity.Error, "jakarta-cdi", "InvalidManagedBeanAnnotation");

Diagnostic d2 = d(5, 13, 24,
"Managed bean class of generic type must have scope @Dependent",
DiagnosticSeverity.Error, "jakarta-cdi", "InvalidManagedBeanAnnotation");

assertJavaDiagnostics(diagnosticsParams, JDT_UTILS, d);
assertJavaDiagnostics(diagnosticsParams, JDT_UTILS, d1, d2);

// test expected quick-fix
JakartaJavaCodeActionParams codeActionParams = createCodeActionParams(uri, d);
TextEdit te = te(4, 0, 5, 0, "@Dependent\n");
CodeAction ca = ca(uri, "Replace current scope with @Dependent", d, te);
assertJavaCodeAction(codeActionParams, JDT_UTILS, ca);
// Assert for the diagnostic d1
JakartaJavaCodeActionParams codeActionParams1 = createCodeActionParams(uri, d1);
TextEdit te1 = te(4, 0, 5, 0, "@Dependent\n");
CodeAction ca1 = ca(uri, "Replace current scope with @Dependent", d1, te1);
assertJavaCodeAction(codeActionParams1, JDT_UTILS, ca1);

// Assert for the diagnostic d2
JakartaJavaCodeActionParams codeActionParams2 = createCodeActionParams(uri, d2);
TextEdit te2 = te(4, 0, 5, 0, "@Dependent\n");
CodeAction ca2 = ca(uri, "Replace current scope with @Dependent", d2, te2);
assertJavaCodeAction(codeActionParams2, JDT_UTILS, ca2);
}

@Test
Expand Down

0 comments on commit d06b37a

Please sign in to comment.