Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modification to ensure no incorrect import or annotation in PreDestroy Annotation #5

Merged
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 @@ -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
@@ -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,4 @@
package random.test.pkg.on;

public @interface PreDestroy {
}
Loading