diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/MapperTestBase.java b/processor/src/test/java/org/mapstruct/ap/testutil/MapperTestBase.java
index 388aa32ab..1a88566b6 100644
--- a/processor/src/test/java/org/mapstruct/ap/testutil/MapperTestBase.java
+++ b/processor/src/test/java/org/mapstruct/ap/testutil/MapperTestBase.java
@@ -40,6 +40,7 @@ import javax.tools.ToolProvider;
import org.mapstruct.ap.MappingProcessor;
import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult;
import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome;
+import org.mapstruct.ap.testutil.compilation.annotation.ProcessorOption;
import org.mapstruct.ap.testutil.compilation.model.CompilationOutcomeDescriptor;
import org.mapstruct.ap.testutil.compilation.model.DiagnosticDescriptor;
import org.testng.annotations.BeforeClass;
@@ -51,9 +52,15 @@ import static org.fest.assertions.Assertions.assertThat;
* Base class for all mapper tests.
*
* The classes to be compiled for a given test method must be specified via
- * {@link WithClasses}. Optionally the expected compilation outcome and expected
- * diagnostics can be specified via {@link ExpectedCompilationOutcome}. If no
- * outcome is specified, a successful compilation is assumed.
+ * {@link WithClasses}. In addition the following things can be configured
+ * optionally :
+ *
+ * - Processor options to be considered during compilation via
+ * {@link ProcessorOption}.
+ * - The expected compilation outcome and expected diagnostics can be
+ * specified via {@link ExpectedCompilationOutcome}. If no outcome is specified,
+ * a successful compilation is assumed.
+ *
*
* @author Gunnar Morling
*/
@@ -104,8 +111,9 @@ public abstract class MapperTestBase {
public void generateMapperImplementation(Method testMethod) {
diagnostics = new DiagnosticCollector();
List sourceFiles = getSourceFiles( getTestClasses( testMethod ) );
+ List processorOptions = getProcessorOptions( testMethod );
- boolean compilationSuccessful = compile( diagnostics, sourceFiles );
+ boolean compilationSuccessful = compile( diagnostics, sourceFiles, processorOptions );
CompilationOutcomeDescriptor actualResult = CompilationOutcomeDescriptor.forResult(
sourceDir,
@@ -196,6 +204,28 @@ public abstract class MapperTestBase {
return Arrays.asList( withClasses.value() );
}
+ /**
+ * Returns the processor options to be used this test.
+ *
+ * @param testMethod The test method of interest
+ *
+ * @return A list containing the processor options to be used for this test
+ */
+ private List getProcessorOptions(Method testMethod) {
+ ProcessorOption processorOption = testMethod.getAnnotation( ProcessorOption.class );
+
+ if ( processorOption == null ) {
+ processorOption = this.getClass().getAnnotation( ProcessorOption.class );
+ }
+
+ return processorOption != null ? Arrays.asList( asOptionString( processorOption ) ) :
+ Collections.emptyList();
+ }
+
+ private String asOptionString(ProcessorOption processorOption) {
+ return String.format( "-A%s=%s", processorOption.name(), processorOption.value() );
+ }
+
private List getSourceFiles(List> classes) {
List sourceFiles = new ArrayList( classes.size() );
@@ -213,7 +243,8 @@ public abstract class MapperTestBase {
return sourceFiles;
}
- private boolean compile(DiagnosticCollector diagnostics, Iterable sourceFiles) {
+ private boolean compile(DiagnosticCollector diagnostics, Iterable sourceFiles,
+ List processorOptions) {
StandardJavaFileManager fileManager = compiler.getStandardFileManager( null, null, null );
Iterable extends JavaFileObject> compilationUnits = fileManager.getJavaFileObjectsFromFiles( sourceFiles );
@@ -231,7 +262,7 @@ public abstract class MapperTestBase {
null,
fileManager,
diagnostics,
- Collections.emptyList(),
+ processorOptions,
null,
compilationUnits
);
diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/compilation/annotation/ProcessorOption.java b/processor/src/test/java/org/mapstruct/ap/testutil/compilation/annotation/ProcessorOption.java
new file mode 100644
index 000000000..30502aa57
--- /dev/null
+++ b/processor/src/test/java/org/mapstruct/ap/testutil/compilation/annotation/ProcessorOption.java
@@ -0,0 +1,49 @@
+/**
+ * Copyright 2012-2013 Gunnar Morling (http://www.gunnarmorling.de/)
+ * and/or other contributors as indicated by the @authors tag. See the
+ * copyright.txt file in the distribution for a full listing of all
+ * contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.mapstruct.ap.testutil.compilation.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * An annotation processor option to be used for a test. Will be passed in the
+ * form {@code -Aname=value} to the compiler.
+ *
+ * @author Gunnar Morling
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ ElementType.TYPE, ElementType.METHOD })
+public @interface ProcessorOption {
+
+ /**
+ * The name of the processor option.
+ *
+ * @return The name of the processor option.
+ */
+ String name();
+
+ /**
+ * The value of the processor option.
+ *
+ * @return The value of the processor option.
+ */
+ String value();
+}