From 5571f361a29a7586f514551da1bc36819b40d4ca Mon Sep 17 00:00:00 2001 From: Tobias Stamann Date: Thu, 25 Jan 2024 16:12:57 +0100 Subject: [PATCH] Added Cute Unit Test Implementations for Tests without passing in Elements --- ...stingAnnotationProcessorsWithouPassIn.java | 48 +++++++++++++++++++ .../APTKUnitTestProcessorWithoutPassIn.java | 38 +++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 cute/src/main/java/io/toolisticon/aptk/cute/APTKUnitTestProcessorForTestingAnnotationProcessorsWithouPassIn.java create mode 100644 cute/src/main/java/io/toolisticon/aptk/cute/APTKUnitTestProcessorWithoutPassIn.java diff --git a/cute/src/main/java/io/toolisticon/aptk/cute/APTKUnitTestProcessorForTestingAnnotationProcessorsWithouPassIn.java b/cute/src/main/java/io/toolisticon/aptk/cute/APTKUnitTestProcessorForTestingAnnotationProcessorsWithouPassIn.java new file mode 100644 index 00000000..d6cdc4b1 --- /dev/null +++ b/cute/src/main/java/io/toolisticon/aptk/cute/APTKUnitTestProcessorForTestingAnnotationProcessorsWithouPassIn.java @@ -0,0 +1,48 @@ +package io.toolisticon.aptk.cute; + +import io.toolisticon.aptk.common.ToolingProvider; +import io.toolisticon.cute.UnitTestForTestingAnnotationProcessorsWithoutPassIn; + +import javax.annotation.processing.ProcessingEnvironment; +import javax.annotation.processing.Processor; +import javax.lang.model.element.Element; + +/** + * Convenient unit test processor for testing annotation processors build with the APTK with toolisticon's cute framework. + * + * @param The processor under test. init method will be called and {@link ToolingProvider} will be set. + */ +public abstract class APTKUnitTestProcessorForTestingAnnotationProcessorsWithouPassIn implements UnitTestForTestingAnnotationProcessorsWithoutPassIn { + + + /** + * The original unit test processor method. Contains logic to initialize the ToolingProvider. + * Will be called by cute framework. Propagates call to aptkUnitTest method after initializations. + * + * @param processor The processor under test + * @param processingEnvironment the processing environment + */ + @Override + public final void unitTest(PROCESSOR processor, ProcessingEnvironment processingEnvironment) { + + try { + // do initializations + ToolingProvider.setTooling(processingEnvironment); + + // propagate to unit test implementation + this.aptkUnitTest(processor, processingEnvironment); + + } finally { + ToolingProvider.clearTooling(); + } + + } + + /** + * The unit test method. + * + * @param unit the initialized processor under test + * @param processingEnvironment the processingEnvironment + */ + public abstract void aptkUnitTest(PROCESSOR unit, ProcessingEnvironment processingEnvironment); +} diff --git a/cute/src/main/java/io/toolisticon/aptk/cute/APTKUnitTestProcessorWithoutPassIn.java b/cute/src/main/java/io/toolisticon/aptk/cute/APTKUnitTestProcessorWithoutPassIn.java new file mode 100644 index 00000000..6fa7ba78 --- /dev/null +++ b/cute/src/main/java/io/toolisticon/aptk/cute/APTKUnitTestProcessorWithoutPassIn.java @@ -0,0 +1,38 @@ +package io.toolisticon.aptk.cute; + +import io.toolisticon.aptk.common.ToolingProvider; +import io.toolisticon.cute.UnitTestWithoutPassIn; + +import javax.annotation.processing.ProcessingEnvironment; + +public abstract class APTKUnitTestProcessorWithoutPassIn implements UnitTestWithoutPassIn { + + /** + * The original unit test processor method. Contains logic to initialize the ToolingProvider. + * Will be called by cute framework. Propagates call to aptkUnitTest method after initializations. + * + * @param processingEnvironment the processing environment + */ + @Override + public final void unitTest(ProcessingEnvironment processingEnvironment) { + + try { + // do initializations + ToolingProvider.setTooling(processingEnvironment); + + // propagate to unit test implementation + this.aptkUnitTest(processingEnvironment); + + } finally { + ToolingProvider.clearTooling(); + } + + } + + /** + * The unit test method. + * + * @param processingEnvironment the processingEnvironment + */ + public abstract void aptkUnitTest(ProcessingEnvironment processingEnvironment); +} \ No newline at end of file