Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,25 @@ public void GeneratedAnnotation() throws Exception {
JakartaForJavaAssert.assertJavaDiagnostics(diagnosticsParams, utils, d1, d2);
}

@Test
public void testIncorrectGeneratedAnnotation() throws Exception {
// Set up the module and file where a non-Jakarta Generated annotation is used
Module module = createMavenModule(new File("src/test/resources/projects/maven/jakarta-sample"));
IPsiUtils utils = PsiUtilsLSImpl.getInstance(getProject());

// The file path to a Java file that includes an incorrectly qualified Generated annotation
VirtualFile javaFile = LocalFileSystem.getInstance().refreshAndFindFileByPath(
ModuleUtilCore.getModuleDirPath(module) +
"/src/main/java/io/openliberty/sample/jakarta/annotations/IncorrectGeneratedAnnotation.java"
);
String uri = VfsUtilCore.virtualToIoFile(javaFile).toURI().toString();

// Adding a test to ensure no diagnostics are triggered for any non-matching annotation or import path similar to "jakarta.annotation.Generated"
JakartaJavaDiagnosticsParams diagnosticsParams = new JakartaJavaDiagnosticsParams();
diagnosticsParams.setUris(Arrays.asList(uri));

// Ensure no diagnostics are generated for any annotation or import that is not exactly "jakarta.annotation.Generated"
JakartaForJavaAssert.assertJavaDiagnostics(diagnosticsParams, utils);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,25 @@ public void GeneratedAnnotation() throws Exception {
CodeAction ca1 = ca(uri, "Remove all parameters", d2, te1);
assertJavaCodeAction(codeActionParams1, utils, ca, ca1);
}

@Test
public void testIncorrectPostConstructAnnotation() throws Exception {
// Set up the module and file where a non-Jakarta PostConstruct annotation is used
Module module = createMavenModule(new File("src/test/resources/projects/maven/jakarta-sample"));
IPsiUtils utils = PsiUtilsLSImpl.getInstance(getProject());

// The file path to a Java file that includes an incorrectly qualified PostConstruct annotation
VirtualFile javaFile = LocalFileSystem.getInstance().refreshAndFindFileByPath(
ModuleUtilCore.getModuleDirPath(module) +
"/src/main/java/io/openliberty/sample/jakarta/annotations/IncorrectPostConstructAnnotation.java"
);
String uri = VfsUtilCore.virtualToIoFile(javaFile).toURI().toString();

// Adding a test to ensure no diagnostics are triggered for any non-matching annotation or import path similar to "jakarta.annotation.PostConstruct"
JakartaJavaDiagnosticsParams diagnosticsParams = new JakartaJavaDiagnosticsParams();
diagnosticsParams.setUris(Arrays.asList(uri));

// Ensure no diagnostics are generated for any annotation or import that is not exactly "jakarta.annotation.PostConstruct"
assertJavaDiagnostics(diagnosticsParams, utils);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,25 @@ public void GeneratedAnnotation() throws Exception {
assertJavaCodeAction(codeActionParams1, utils, ca2, ca3);
}

@Test
public void testIncorrectPreDestroyAnnotation() throws Exception {
// Set up the module and file where a non-Jakarta PreDestroy annotation is used
Module module = createMavenModule(new File("src/test/resources/projects/maven/jakarta-sample"));
IPsiUtils utils = PsiUtilsLSImpl.getInstance(getProject());

// The file path to a Java file that includes an incorrectly qualified PreDestroy annotation
VirtualFile javaFile = LocalFileSystem.getInstance().refreshAndFindFileByPath(
ModuleUtilCore.getModuleDirPath(module) +
"/src/main/java/io/openliberty/sample/jakarta/annotations/IncorrectPreDestroyAnnotation.java"
);
String uri = VfsUtilCore.virtualToIoFile(javaFile).toURI().toString();

// Adding a test to ensure no diagnostics are triggered for any non-matching annotation or import path similar to "jakarta.annotation.PreDestroy"
JakartaJavaDiagnosticsParams diagnosticsParams = new JakartaJavaDiagnosticsParams();
diagnosticsParams.setUris(Arrays.asList(uri));

// Ensure no diagnostics are generated for any annotation or import that is not exactly "jakarta.annotation.PreDestroy"
assertJavaDiagnostics(diagnosticsParams, utils);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,25 @@ public void ResourceAnnotation() throws Exception {
assertJavaCodeAction(codeActionParams1, utils, ca1);
// }
}

@Test
public void testIncorrectResourceAnnotation() throws Exception {
// Set up the module and file where a non-Jakarta Resource annotation is used
Module module = createMavenModule(new File("src/test/resources/projects/maven/jakarta-sample"));
IPsiUtils utils = PsiUtilsLSImpl.getInstance(getProject());

// The file path to a Java file that includes an incorrectly qualified Resource annotation
VirtualFile javaFile = LocalFileSystem.getInstance().refreshAndFindFileByPath(
ModuleUtilCore.getModuleDirPath(module) +
"/src/main/java/io/openliberty/sample/jakarta/annotations/IncorrectResourceAnnotation.java"
);
String uri = VfsUtilCore.virtualToIoFile(javaFile).toURI().toString();

// Adding a test to ensure no diagnostics are triggered for any non-matching annotation or import path similar to "jakarta.annotation.Resource"
JakartaJavaDiagnosticsParams diagnosticsParams = new JakartaJavaDiagnosticsParams();
diagnosticsParams.setUris(Arrays.asList(uri));

// Ensure no diagnostics are generated for any annotation or import that is not exactly "jakarta.annotation.Resource"
assertJavaDiagnostics(diagnosticsParams, utils);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.openliberty.sample.jakarta.annotations;

import random.test.pkg.on.Generated;

@Generated()
public class IncorrectGeneratedAnnotation {

@Generated()
private Integer studentId;

@random.test.pkg.on.Generated()
private boolean isHappy;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.openliberty.sample.jakarta.annotations;

import jakarta.annotation.Resource;
import random.test.pkg.on.PostConstruct;

@Resource(type = Object.class, name = "aa")
public class IncorrectPostConstructAnnotation {

@PostConstruct
public void getHappinessRandom(String type) {

}

@random.test.pkg.on.PostConstruct
public void getRandom(String type) {

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package io.openliberty.sample.jakarta.annotations;

import random.test.pkg.on.PreDestroy;
import jakarta.annotation.Resource;

@Resource(type = Object.class, name = "aa")
public class IncorrectPreDestroyAnnotation {

private Integer studentId;

private boolean isHappy;

private boolean isSad;

@PreDestroy()
public Integer getStudentId() {
return this.studentId;
}

@random.test.pkg.on.PreDestroy()
public boolean getHappiness(String type) {
if (type.equals("happy")) return this.isHappy;
return this.isSad;
}
}



Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package io.openliberty.sample.jakarta.annotations;

import random.test.pkg.on.Resource;

public class IncorrectResourceAnnotation {

private Integer studentId;

@Resource
private boolean isSad;

@random.test.pkg.on.Resource
private boolean isHappy;

private String emailAddress;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package random.test.pkg.on;

public @interface Generated {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package random.test.pkg.on;

public @interface PostConstruct {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package random.test.pkg.on;

public @interface PreDestroy {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package random.test.pkg.on;

public @interface Resource {
}
Loading