mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
Merging test classes specified via @WithClasses on method and class level
This commit is contained in:
parent
8426b1af34
commit
260a685f65
@ -25,10 +25,13 @@ import java.net.URL;
|
|||||||
import java.net.URLClassLoader;
|
import java.net.URLClassLoader;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
import javax.tools.DiagnosticCollector;
|
import javax.tools.DiagnosticCollector;
|
||||||
import javax.tools.JavaCompiler;
|
import javax.tools.JavaCompiler;
|
||||||
import javax.tools.JavaCompiler.CompilationTask;
|
import javax.tools.JavaCompiler.CompilationTask;
|
||||||
@ -110,7 +113,7 @@ public abstract class MapperTestBase {
|
|||||||
@BeforeMethod
|
@BeforeMethod
|
||||||
public void generateMapperImplementation(Method testMethod) {
|
public void generateMapperImplementation(Method testMethod) {
|
||||||
diagnostics = new DiagnosticCollector<JavaFileObject>();
|
diagnostics = new DiagnosticCollector<JavaFileObject>();
|
||||||
List<File> sourceFiles = getSourceFiles( getTestClasses( testMethod ) );
|
Set<File> sourceFiles = getSourceFiles( getTestClasses( testMethod ) );
|
||||||
List<String> processorOptions = getProcessorOptions( testMethod );
|
List<String> processorOptions = getProcessorOptions( testMethod );
|
||||||
|
|
||||||
boolean compilationSuccessful = compile( diagnostics, sourceFiles, processorOptions );
|
boolean compilationSuccessful = compile( diagnostics, sourceFiles, processorOptions );
|
||||||
@ -182,22 +185,28 @@ public abstract class MapperTestBase {
|
|||||||
*
|
*
|
||||||
* @param testMethod The test method of interest
|
* @param testMethod The test method of interest
|
||||||
*
|
*
|
||||||
* @return A list containing the classes to be compiled for this test
|
* @return A set containing the classes to be compiled for this test
|
||||||
*/
|
*/
|
||||||
private List<Class<?>> getTestClasses(Method testMethod) {
|
private Set<Class<?>> getTestClasses(Method testMethod) {
|
||||||
WithClasses withClasses = testMethod.getAnnotation( WithClasses.class );
|
Set<Class<?>> testClasses = new HashSet<Class<?>>();
|
||||||
|
|
||||||
if ( withClasses == null ) {
|
WithClasses withClasses = testMethod.getAnnotation( WithClasses.class );
|
||||||
withClasses = this.getClass().getAnnotation( WithClasses.class );
|
if ( withClasses != null ) {
|
||||||
|
testClasses.addAll( Arrays.asList( withClasses.value() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( withClasses == null || withClasses.value().length == 0 ) {
|
withClasses = this.getClass().getAnnotation( WithClasses.class );
|
||||||
|
if ( withClasses != null ) {
|
||||||
|
testClasses.addAll( Arrays.asList( withClasses.value() ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( testClasses.isEmpty() ) {
|
||||||
throw new IllegalStateException(
|
throw new IllegalStateException(
|
||||||
"The classes to be compiled during the test must be specified via @WithClasses."
|
"The classes to be compiled during the test must be specified via @WithClasses."
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Arrays.asList( withClasses.value() );
|
return testClasses;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -222,8 +231,8 @@ public abstract class MapperTestBase {
|
|||||||
return String.format( "-A%s=%s", processorOption.name(), processorOption.value() );
|
return String.format( "-A%s=%s", processorOption.name(), processorOption.value() );
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<File> getSourceFiles(List<Class<?>> classes) {
|
private Set<File> getSourceFiles(Collection<Class<?>> classes) {
|
||||||
List<File> sourceFiles = new ArrayList<File>( classes.size() );
|
Set<File> sourceFiles = new HashSet<File>( classes.size() );
|
||||||
|
|
||||||
for ( Class<?> clazz : classes ) {
|
for ( Class<?> clazz : classes ) {
|
||||||
sourceFiles.add(
|
sourceFiles.add(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user