forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ArC: detect incorrect PostConstruct and PreDestroy
- resolves quarkusio#43751
- Loading branch information
Showing
2 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
.../src/test/java/io/quarkus/arc/test/wrongannotations/WrongPostConstructPreDestroyTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package io.quarkus.arc.test.wrongannotations; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
import javax.annotation.PostConstruct; | ||
import javax.annotation.PreDestroy; | ||
|
||
import jakarta.inject.Singleton; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.runtime.util.ExceptionUtil; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class WrongPostConstructPreDestroyTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot(root -> root | ||
.addClasses(MySingleton.class)) | ||
.assertException(t -> { | ||
Throwable rootCause = ExceptionUtil.getRootCause(t); | ||
assertTrue(rootCause.getMessage().contains("javax.annotation.PostConstruct"), t.toString()); | ||
assertTrue(rootCause.getMessage().contains("javax.annotation.PreDestroy"), t.toString()); | ||
}); | ||
|
||
@Test | ||
public void testValidationFailed() { | ||
// This method should not be invoked | ||
fail(); | ||
} | ||
|
||
@Singleton | ||
static class MySingleton { | ||
|
||
@PostConstruct | ||
void init() { | ||
} | ||
|
||
@PreDestroy | ||
void destroy() { | ||
} | ||
|
||
} | ||
|
||
} |