Skip to content

Commit

Permalink
Added Cute Unit Test Implementations for Tests without passing in Ele…
Browse files Browse the repository at this point in the history
…ments
  • Loading branch information
tobiasstamann committed Jan 25, 2024
1 parent d71c389 commit 5571f36
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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 <PROCESSOR> The processor under test. init method will be called and {@link ToolingProvider} will be set.
*/
public abstract class APTKUnitTestProcessorForTestingAnnotationProcessorsWithouPassIn<PROCESSOR extends Processor> implements UnitTestForTestingAnnotationProcessorsWithoutPassIn<PROCESSOR> {


/**
* 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);
}
Original file line number Diff line number Diff line change
@@ -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);
}

0 comments on commit 5571f36

Please sign in to comment.