#140, #132 - create a JUnit based test runner that is able to replace the test classloader correctly and is safe for parallel execution of test classes and methods

- migrate all tests to JUnit and remove testNG dependencies
This commit is contained in:
Andreas Gudian 2014-04-02 22:52:33 +02:00 committed by Gunnar Morling
parent 25849adfee
commit a41cad17bd
60 changed files with 536 additions and 326 deletions

View File

@ -35,8 +35,8 @@
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.testng</groupId> <groupId>junit</groupId>
<artifactId>testng</artifactId> <artifactId>junit</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -18,11 +18,11 @@
*/ */
package org.mapstruct; package org.mapstruct;
import static org.fest.assertions.Assertions.assertThat;
import org.junit.Test;
import org.mapstruct.factory.Mappers; import org.mapstruct.factory.Mappers;
import org.mapstruct.test.model.Foo; import org.mapstruct.test.model.Foo;
import org.testng.annotations.Test;
import static org.fest.assertions.Assertions.assertThat;
/** /**
* Unit test for {@link Mappers}. * Unit test for {@link Mappers}.

View File

@ -41,8 +41,8 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.testng</groupId> <groupId>junit</groupId>
<artifactId>testng</artifactId> <artifactId>junit</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
@ -61,8 +61,8 @@
<artifactId>javax.inject</artifactId> <artifactId>javax.inject</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.jboss.arquillian.testng</groupId> <groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-testng-container</artifactId> <artifactId>arquillian-junit-container</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
@ -76,8 +76,8 @@
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.jboss.arquillian.testng</groupId> <groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-testng-core</artifactId> <artifactId>arquillian-junit-core</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -18,10 +18,10 @@
*/ */
package org.mapstruct.itest; package org.mapstruct.itest;
import org.testng.annotations.Test;
import static org.fest.assertions.Assertions.assertThat; import static org.fest.assertions.Assertions.assertThat;
import org.junit.Test;
public class ConversionTest { public class ConversionTest {
@Test @Test

View File

@ -18,24 +18,26 @@
*/ */
package org.mapstruct.itest.cdi; package org.mapstruct.itest.cdi;
import static org.fest.assertions.Assertions.assertThat;
import javax.inject.Inject; import javax.inject.Inject;
import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.testng.Arquillian; import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset; import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mapstruct.itest.cdi.other.DateMapper; import org.mapstruct.itest.cdi.other.DateMapper;
import org.testng.annotations.Test;
import static org.fest.assertions.Assertions.assertThat;
/** /**
* Test for generation of CDI-based mapper implementations. * Test for generation of CDI-based mapper implementations.
* *
* @author Gunnar Morling * @author Gunnar Morling
*/ */
public class CdiBasedMapperTest extends Arquillian { @RunWith( Arquillian.class )
public class CdiBasedMapperTest {
@Inject @Inject
private SourceTargetMapper mapper; private SourceTargetMapper mapper;

View File

@ -18,41 +18,29 @@
*/ */
package org.mapstruct.itest.jaxb; package org.mapstruct.itest.jaxb;
import static org.fest.assertions.Assertions.assertThat;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement; import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException; import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller; import javax.xml.bind.Marshaller;
import org.jboss.arquillian.container.test.api.Deployment; import org.junit.Test;
import org.jboss.arquillian.testng.Arquillian;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.mapstruct.itest.jaxb.xsd.test1.ObjectFactory; import org.mapstruct.itest.jaxb.xsd.test1.ObjectFactory;
import org.mapstruct.itest.jaxb.xsd.test1.OrderType; import org.mapstruct.itest.jaxb.xsd.test1.OrderType;
import org.testng.annotations.Test;
import static org.fest.assertions.Assertions.assertThat;
/** /**
* Test for generation of JAXB based mapper implementations. * Test for generation of JAXB based mapper implementations.
* *
* @author Sjaak Derksen * @author Sjaak Derksen
*/ */
public class JaxbBasedMapperTest extends Arquillian { public class JaxbBasedMapperTest {
@Deployment
public static JavaArchive createDeployment() {
return ShrinkWrap.create( JavaArchive.class )
.addPackage( SourceTargetMapper.class.getPackage() )
.addPackage( org.mapstruct.itest.jaxb.xsd.test1.ObjectFactory.class.getPackage() )
.addPackage( org.mapstruct.itest.jaxb.xsd.test2.ObjectFactory.class.getPackage() );
}
@Test @Test
public void shouldMapJaxb() throws ParseException, JAXBException { public void shouldMapJaxb() throws ParseException, JAXBException {

View File

@ -22,12 +22,13 @@ import static org.fest.assertions.Assertions.assertThat;
import javax.inject.Inject; import javax.inject.Inject;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mapstruct.itest.jsr330.Jsr330BasedMapperTest.SpringTestConfig; import org.mapstruct.itest.jsr330.Jsr330BasedMapperTest.SpringTestConfig;
import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.testng.annotations.Test;
/** /**
* Test for generation of JSR-330-based Mapper implementations * Test for generation of JSR-330-based Mapper implementations
@ -35,7 +36,8 @@ import org.testng.annotations.Test;
* @author Andreas Gudian * @author Andreas Gudian
*/ */
@ContextConfiguration(classes = SpringTestConfig.class ) @ContextConfiguration(classes = SpringTestConfig.class )
public class Jsr330BasedMapperTest extends AbstractTestNGSpringContextTests { @RunWith( SpringJUnit4ClassRunner.class )
public class Jsr330BasedMapperTest {
@Configuration @Configuration
@ComponentScan(basePackageClasses = Jsr330BasedMapperTest.class) @ComponentScan(basePackageClasses = Jsr330BasedMapperTest.class)
public static class SpringTestConfig { public static class SpringTestConfig {

View File

@ -18,15 +18,16 @@
*/ */
package org.mapstruct.itest.spring; package org.mapstruct.itest.spring;
import static org.fest.assertions.Assertions.assertThat;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mapstruct.itest.spring.SpringBasedMapperTest.SpringTestConfig; import org.mapstruct.itest.spring.SpringBasedMapperTest.SpringTestConfig;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.testng.annotations.Test;
import static org.fest.assertions.Assertions.assertThat;
/** /**
* Test for generation of Spring-based Mapper implementations * Test for generation of Spring-based Mapper implementations
@ -34,7 +35,8 @@ import static org.fest.assertions.Assertions.assertThat;
* @author Andreas Gudian * @author Andreas Gudian
*/ */
@ContextConfiguration(classes = SpringTestConfig.class ) @ContextConfiguration(classes = SpringTestConfig.class )
public class SpringBasedMapperTest extends AbstractTestNGSpringContextTests { @RunWith( SpringJUnit4ClassRunner.class )
public class SpringBasedMapperTest {
@Configuration @Configuration
@ComponentScan(basePackageClasses = SpringBasedMapperTest.class) @ComponentScan(basePackageClasses = SpringBasedMapperTest.class)
public static class SpringTestConfig { public static class SpringTestConfig {

View File

@ -100,11 +100,6 @@
<artifactId>freemarker</artifactId> <artifactId>freemarker</artifactId>
<version>2.3.19</version> <version>2.3.19</version>
</dependency> </dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.3.1</version>
</dependency>
<dependency> <dependency>
<groupId>org.easytesting</groupId> <groupId>org.easytesting</groupId>
<artifactId>fest-assert</artifactId> <artifactId>fest-assert</artifactId>
@ -120,7 +115,11 @@
<artifactId>hickory</artifactId> <artifactId>hickory</artifactId>
<version>${com.jolira.hickory.version}</version> <version>${com.jolira.hickory.version}</version>
</dependency> </dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
<!-- CDI, Weld, Arquillian --> <!-- CDI, Weld, Arquillian -->
<dependency> <dependency>
<groupId>javax.enterprise</groupId> <groupId>javax.enterprise</groupId>

View File

@ -60,8 +60,8 @@
<!-- Test --> <!-- Test -->
<dependency> <dependency>
<groupId>org.testng</groupId> <groupId>junit</groupId>
<artifactId>testng</artifactId> <artifactId>junit</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -20,10 +20,11 @@ package org.mapstruct.ap.test.abstractclass;
import static org.fest.assertions.Assertions.assertThat; import static org.fest.assertions.Assertions.assertThat;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.MapperTestBase;
import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithClasses;
import org.testng.annotations.Test; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
/** /**
* Test for the generation of implementation of abstract base classes. * Test for the generation of implementation of abstract base classes.
@ -32,7 +33,8 @@ import org.testng.annotations.Test;
*/ */
@WithClasses( { Source.class, Target.class, SourceTargetMapper.class, AbstractBaseMapper.class, @WithClasses( { Source.class, Target.class, SourceTargetMapper.class, AbstractBaseMapper.class,
BaseMapperInterface.class } ) BaseMapperInterface.class } )
public class AbstractClassTest extends MapperTestBase { @RunWith( AnnotationProcessorTestRunner.class )
public class AbstractClassTest {
@Test @Test
@IssueKey( "64" ) @IssueKey( "64" )

View File

@ -21,12 +21,13 @@ package org.mapstruct.ap.test.accessibility;
import static java.lang.reflect.Modifier.isPrivate; import static java.lang.reflect.Modifier.isPrivate;
import static java.lang.reflect.Modifier.isProtected; import static java.lang.reflect.Modifier.isProtected;
import static java.lang.reflect.Modifier.isPublic; import static java.lang.reflect.Modifier.isPublic;
import static org.testng.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.MapperTestBase;
import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithClasses;
import org.testng.annotations.Test; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
/** /**
* Test for different accessibility modifiers * Test for different accessibility modifiers
@ -34,7 +35,8 @@ import org.testng.annotations.Test;
* @author Andreas Gudian * @author Andreas Gudian
*/ */
@WithClasses({ Source.class, Target.class, DefaultSourceTargetMapperAbstr.class, DefaultSourceTargetMapperIfc.class }) @WithClasses({ Source.class, Target.class, DefaultSourceTargetMapperAbstr.class, DefaultSourceTargetMapperIfc.class })
public class AccessibilityTest extends MapperTestBase { @RunWith( AnnotationProcessorTestRunner.class )
public class AccessibilityTest {
@Test @Test
@IssueKey("103") @IssueKey("103")

View File

@ -38,29 +38,31 @@ import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar; import javax.xml.datatype.XMLGregorianCalendar;
import javax.xml.namespace.QName; import javax.xml.namespace.QName;
import org.mapstruct.ap.testutil.MapperTestBase; import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithClasses;
import org.testng.annotations.AfterClass; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
/** /**
* Test for the generation of built-in mapping methods. * Test for the generation of built-in mapping methods.
* *
* @author Sjaak Derksen * @author Sjaak Derksen
*/ */
public class BuiltInTest extends MapperTestBase { @RunWith(AnnotationProcessorTestRunner.class)
public class BuiltInTest {
private TimeZone originalTimeZone; private static TimeZone originalTimeZone;
@BeforeClass @BeforeClass
public void setDefaultTimeZoneToCet() { public static void setDefaultTimeZoneToCet() {
originalTimeZone = TimeZone.getDefault(); originalTimeZone = TimeZone.getDefault();
TimeZone.setDefault( TimeZone.getTimeZone( "Europe/Berlin" ) ); TimeZone.setDefault( TimeZone.getTimeZone( "Europe/Berlin" ) );
} }
@AfterClass @AfterClass
public void restoreOriginalTimeZone() { public static void restoreOriginalTimeZone() {
TimeZone.setDefault( originalTimeZone ); TimeZone.setDefault( originalTimeZone );
} }

View File

@ -19,6 +19,7 @@
package org.mapstruct.ap.test.builtin; package org.mapstruct.ap.test.builtin;
import java.util.List; import java.util.List;
import javax.xml.datatype.XMLGregorianCalendar; import javax.xml.datatype.XMLGregorianCalendar;
/** /**

View File

@ -19,6 +19,7 @@
package org.mapstruct.ap.test.builtin; package org.mapstruct.ap.test.builtin;
import java.util.List; import java.util.List;
import javax.xml.datatype.XMLGregorianCalendar; import javax.xml.datatype.XMLGregorianCalendar;
import org.mapstruct.IterableMapping; import org.mapstruct.IterableMapping;

View File

@ -19,6 +19,7 @@
package org.mapstruct.ap.test.builtin; package org.mapstruct.ap.test.builtin;
import java.util.Map; import java.util.Map;
import javax.xml.bind.JAXBElement; import javax.xml.bind.JAXBElement;
import javax.xml.datatype.XMLGregorianCalendar; import javax.xml.datatype.XMLGregorianCalendar;

View File

@ -19,6 +19,7 @@
package org.mapstruct.ap.test.builtin; package org.mapstruct.ap.test.builtin;
import java.util.Map; import java.util.Map;
import javax.xml.bind.JAXBElement; import javax.xml.bind.JAXBElement;
import javax.xml.datatype.XMLGregorianCalendar; import javax.xml.datatype.XMLGregorianCalendar;

View File

@ -21,6 +21,7 @@ package org.mapstruct.ap.test.builtin;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import javax.xml.bind.JAXBElement; import javax.xml.bind.JAXBElement;
import javax.xml.datatype.XMLGregorianCalendar; import javax.xml.datatype.XMLGregorianCalendar;

View File

@ -21,6 +21,7 @@ package org.mapstruct.ap.test.builtin;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import javax.xml.datatype.XMLGregorianCalendar; import javax.xml.datatype.XMLGregorianCalendar;
public class Target { public class Target {

View File

@ -29,13 +29,15 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.MapperTestBase;
import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithClasses;
import org.testng.annotations.Test; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
@WithClasses({ Source.class, Target.class, Colour.class, SourceTargetMapper.class }) @WithClasses({ Source.class, Target.class, Colour.class, SourceTargetMapper.class })
public class CollectionMappingTest extends MapperTestBase { @RunWith(AnnotationProcessorTestRunner.class)
public class CollectionMappingTest {
@Test @Test
@IssueKey("6") @IssueKey("6")

View File

@ -18,6 +18,9 @@
*/ */
package org.mapstruct.ap.test.collection.defaultimplementation; package org.mapstruct.ap.test.collection.defaultimplementation;
import static org.fest.assertions.Assertions.assertThat;
import static org.fest.assertions.MapAssert.entry;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
@ -33,13 +36,11 @@ import java.util.SortedSet;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ConcurrentNavigableMap; import java.util.concurrent.ConcurrentNavigableMap;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.MapperTestBase;
import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithClasses;
import org.testng.annotations.Test; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
import static org.fest.assertions.Assertions.assertThat;
import static org.fest.assertions.MapAssert.entry;
@WithClasses({ @WithClasses({
Source.class, Source.class,
@ -48,7 +49,8 @@ import static org.fest.assertions.MapAssert.entry;
TargetFoo.class, TargetFoo.class,
SourceTargetMapper.class SourceTargetMapper.class
}) })
public class DefaultCollectionImplementationTest extends MapperTestBase { @RunWith(AnnotationProcessorTestRunner.class)
public class DefaultCollectionImplementationTest {
@Test @Test
@IssueKey("6") @IssueKey("6")

View File

@ -20,20 +20,22 @@ package org.mapstruct.ap.test.collection.erroneous;
import javax.tools.Diagnostic.Kind; import javax.tools.Diagnostic.Kind;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.MapperTestBase;
import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithClasses;
import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult;
import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic;
import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome;
import org.testng.annotations.Test; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
/** /**
* Test for illegal mappings between collection types, iterable and non-iterable types etc. * Test for illegal mappings between collection types, iterable and non-iterable types etc.
* *
* @author Gunnar Morling * @author Gunnar Morling
*/ */
public class ErroneousCollectionMappingTest extends MapperTestBase { @RunWith(AnnotationProcessorTestRunner.class)
public class ErroneousCollectionMappingTest {
@Test @Test
@IssueKey("6") @IssueKey("6")

View File

@ -18,17 +18,19 @@
*/ */
package org.mapstruct.ap.test.collection.iterabletononiterable; package org.mapstruct.ap.test.collection.iterabletononiterable;
import java.util.Arrays;
import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.MapperTestBase;
import org.mapstruct.ap.testutil.WithClasses;
import org.testng.annotations.Test;
import static org.fest.assertions.Assertions.assertThat; import static org.fest.assertions.Assertions.assertThat;
import java.util.Arrays;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.WithClasses;
import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
@WithClasses({ Source.class, Target.class, SourceTargetMapper.class, StringListMapper.class }) @WithClasses({ Source.class, Target.class, SourceTargetMapper.class, StringListMapper.class })
public class IterableToNonIterableMappingTest extends MapperTestBase { @RunWith(AnnotationProcessorTestRunner.class)
public class IterableToNonIterableMappingTest {
@Test @Test
@IssueKey("6") @IssueKey("6")

View File

@ -26,10 +26,11 @@ import java.util.GregorianCalendar;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.MapperTestBase;
import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithClasses;
import org.testng.annotations.Test; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
/** /**
* Test for implementation of {@code Map} mapping methods. * Test for implementation of {@code Map} mapping methods.
@ -38,7 +39,8 @@ import org.testng.annotations.Test;
*/ */
@WithClasses({ SourceTargetMapper.class, CustomNumberMapper.class, Source.class, Target.class }) @WithClasses({ SourceTargetMapper.class, CustomNumberMapper.class, Source.class, Target.class })
@IssueKey("44") @IssueKey("44")
public class MapMappingTest extends MapperTestBase { @RunWith(AnnotationProcessorTestRunner.class)
public class MapMappingTest {
@Test @Test
public void shouldCreateMapMethodImplementation() { public void shouldCreateMapMethodImplementation() {

View File

@ -18,22 +18,23 @@
*/ */
package org.mapstruct.ap.test.complex; package org.mapstruct.ap.test.complex;
import static org.fest.assertions.Assertions.assertThat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
import java.util.List; import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mapstruct.ap.test.complex.other.DateMapper; import org.mapstruct.ap.test.complex.other.DateMapper;
import org.mapstruct.ap.test.complex.source.Car; import org.mapstruct.ap.test.complex.source.Car;
import org.mapstruct.ap.test.complex.source.Category; import org.mapstruct.ap.test.complex.source.Category;
import org.mapstruct.ap.test.complex.source.Person; import org.mapstruct.ap.test.complex.source.Person;
import org.mapstruct.ap.test.complex.target.CarDto; import org.mapstruct.ap.test.complex.target.CarDto;
import org.mapstruct.ap.test.complex.target.PersonDto; import org.mapstruct.ap.test.complex.target.PersonDto;
import org.mapstruct.ap.testutil.MapperTestBase;
import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithClasses;
import org.testng.annotations.Test; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
import static org.fest.assertions.Assertions.assertThat;
@WithClasses({ @WithClasses({
Car.class, Car.class,
@ -44,7 +45,8 @@ import static org.fest.assertions.Assertions.assertThat;
Category.class, Category.class,
DateMapper.class DateMapper.class
}) })
public class CarMapperTest extends MapperTestBase { @RunWith(AnnotationProcessorTestRunner.class)
public class CarMapperTest {
@Test @Test
public void shouldProvideMapperInstance() throws Exception { public void shouldProvideMapperInstance() throws Exception {

View File

@ -18,14 +18,16 @@
*/ */
package org.mapstruct.ap.test.conversion; package org.mapstruct.ap.test.conversion;
import org.mapstruct.ap.testutil.MapperTestBase;
import org.mapstruct.ap.testutil.WithClasses;
import org.testng.annotations.Test;
import static org.fest.assertions.Assertions.assertThat; import static org.fest.assertions.Assertions.assertThat;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mapstruct.ap.testutil.WithClasses;
import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
@WithClasses({ Source.class, Target.class, SourceTargetMapper.class }) @WithClasses({ Source.class, Target.class, SourceTargetMapper.class })
public class ConversionTest extends MapperTestBase { @RunWith(AnnotationProcessorTestRunner.class)
public class ConversionTest {
@Test @Test
public void shouldApplyConversions() { public void shouldApplyConversions() {

View File

@ -18,22 +18,24 @@
*/ */
package org.mapstruct.ap.test.conversion.bignumbers; package org.mapstruct.ap.test.conversion.bignumbers;
import static org.fest.assertions.Assertions.assertThat;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.BigInteger; import java.math.BigInteger;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.MapperTestBase;
import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithClasses;
import org.testng.annotations.Test; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
import static org.fest.assertions.Assertions.assertThat;
/** /**
* Tests conversions between {@link BigInteger} and numbers as well as String. * Tests conversions between {@link BigInteger} and numbers as well as String.
* *
* @author Gunnar Morling * @author Gunnar Morling
*/ */
public class BigNumbersConversionTest extends MapperTestBase { @RunWith(AnnotationProcessorTestRunner.class)
public class BigNumbersConversionTest {
@Test @Test
@IssueKey("21") @IssueKey("21")

View File

@ -18,19 +18,20 @@
*/ */
package org.mapstruct.ap.test.conversion.date; package org.mapstruct.ap.test.conversion.date;
import static org.fest.assertions.Assertions.assertThat;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.MapperTestBase;
import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithClasses;
import org.testng.annotations.BeforeMethod; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
import org.testng.annotations.Test;
import static org.fest.assertions.Assertions.assertThat;
/** /**
* Tests application of format strings for conversions between strings and dates. * Tests application of format strings for conversions between strings and dates.
@ -43,9 +44,10 @@ import static org.fest.assertions.Assertions.assertThat;
SourceTargetMapper.class SourceTargetMapper.class
}) })
@IssueKey("43") @IssueKey("43")
public class DateConversionTest extends MapperTestBase { @RunWith(AnnotationProcessorTestRunner.class)
public class DateConversionTest {
@BeforeMethod @Before
public void setDefaultLocale() { public void setDefaultLocale() {
Locale.setDefault( Locale.GERMAN ); Locale.setDefault( Locale.GERMAN );
} }

View File

@ -22,13 +22,14 @@ import static org.fest.assertions.Assertions.assertThat;
import java.math.BigDecimal; import java.math.BigDecimal;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.MapperTestBase;
import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithClasses;
import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult;
import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic;
import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome;
import org.testng.annotations.Test; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
/** /**
* Tests for the invocation of generic methods for mapping bean properties. * Tests for the invocation of generic methods for mapping bean properties.
@ -41,7 +42,8 @@ import org.testng.annotations.Test;
TypeA.class, TypeB.class, TypeC.class TypeA.class, TypeB.class, TypeC.class
}) })
@IssueKey(value = "79") @IssueKey(value = "79")
public class ConversionTest extends MapperTestBase { @RunWith(AnnotationProcessorTestRunner.class)
public class ConversionTest {
@Test @Test
@WithClasses({ Source.class, Target.class, SourceTargetMapper.class }) @WithClasses({ Source.class, Target.class, SourceTargetMapper.class })

View File

@ -18,18 +18,20 @@
*/ */
package org.mapstruct.ap.test.conversion.nativetypes; package org.mapstruct.ap.test.conversion.nativetypes;
import org.mapstruct.ap.testutil.MapperTestBase;
import org.mapstruct.ap.testutil.WithClasses;
import org.testng.annotations.Test;
import static org.fest.assertions.Assertions.assertThat; import static org.fest.assertions.Assertions.assertThat;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mapstruct.ap.testutil.WithClasses;
import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
@WithClasses({ @WithClasses({
BooleanSource.class, BooleanSource.class,
BooleanTarget.class, BooleanTarget.class,
BooleanMapper.class BooleanMapper.class
}) })
public class BooleanConversionTest extends MapperTestBase { @RunWith(AnnotationProcessorTestRunner.class)
public class BooleanConversionTest {
@Test @Test
public void shouldApplyBooleanConversion() { public void shouldApplyBooleanConversion() {

View File

@ -18,18 +18,20 @@
*/ */
package org.mapstruct.ap.test.conversion.nativetypes; package org.mapstruct.ap.test.conversion.nativetypes;
import org.mapstruct.ap.testutil.MapperTestBase;
import org.mapstruct.ap.testutil.WithClasses;
import org.testng.annotations.Test;
import static org.fest.assertions.Assertions.assertThat; import static org.fest.assertions.Assertions.assertThat;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mapstruct.ap.testutil.WithClasses;
import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
@WithClasses({ @WithClasses({
CharSource.class, CharSource.class,
CharTarget.class, CharTarget.class,
CharMapper.class CharMapper.class
}) })
public class CharConversionTest extends MapperTestBase { @RunWith(AnnotationProcessorTestRunner.class)
public class CharConversionTest {
@Test @Test
public void shouldApplyCharConversion() { public void shouldApplyCharConversion() {

View File

@ -18,12 +18,13 @@
*/ */
package org.mapstruct.ap.test.conversion.nativetypes; package org.mapstruct.ap.test.conversion.nativetypes;
import org.mapstruct.ap.testutil.MapperTestBase;
import org.mapstruct.ap.testutil.WithClasses;
import org.testng.annotations.Test;
import static org.fest.assertions.Assertions.assertThat; import static org.fest.assertions.Assertions.assertThat;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mapstruct.ap.testutil.WithClasses;
import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
@WithClasses({ @WithClasses({
ByteSource.class, ByteSource.class,
ByteTarget.class, ByteTarget.class,
@ -51,7 +52,8 @@ import static org.fest.assertions.Assertions.assertThat;
DoubleWrapperTarget.class, DoubleWrapperTarget.class,
SourceTargetMapper.class SourceTargetMapper.class
}) })
public class NumberConversionTest extends MapperTestBase { @RunWith(AnnotationProcessorTestRunner.class)
public class NumberConversionTest {
@Test @Test
public void shouldApplyByteConversions() { public void shouldApplyByteConversions() {

View File

@ -18,14 +18,16 @@
*/ */
package org.mapstruct.ap.test.conversion.precedence; package org.mapstruct.ap.test.conversion.precedence;
import org.mapstruct.ap.testutil.MapperTestBase;
import org.mapstruct.ap.testutil.WithClasses;
import org.testng.annotations.Test;
import static org.fest.assertions.Assertions.assertThat; import static org.fest.assertions.Assertions.assertThat;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mapstruct.ap.testutil.WithClasses;
import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
@WithClasses({ Source.class, Target.class, SourceTargetMapper.class, IntegerStringMapper.class }) @WithClasses({ Source.class, Target.class, SourceTargetMapper.class, IntegerStringMapper.class })
public class ConversionTest extends MapperTestBase { @RunWith(AnnotationProcessorTestRunner.class)
public class ConversionTest {
@Test @Test
public void shouldInvokeMappingMethodInsteadOfConversion() { public void shouldInvokeMappingMethodInsteadOfConversion() {

View File

@ -18,18 +18,20 @@
*/ */
package org.mapstruct.ap.test.conversion.string; package org.mapstruct.ap.test.conversion.string;
import org.mapstruct.ap.testutil.MapperTestBase;
import org.mapstruct.ap.testutil.WithClasses;
import org.testng.annotations.Test;
import static org.fest.assertions.Assertions.assertThat; import static org.fest.assertions.Assertions.assertThat;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mapstruct.ap.testutil.WithClasses;
import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
@WithClasses({ @WithClasses({
Source.class, Source.class,
Target.class, Target.class,
SourceTargetMapper.class SourceTargetMapper.class
}) })
public class StringConversionTest extends MapperTestBase { @RunWith(AnnotationProcessorTestRunner.class)
public class StringConversionTest {
@Test @Test
public void shouldApplyStringConversions() { public void shouldApplyStringConversions() {

View File

@ -18,18 +18,20 @@
*/ */
package org.mapstruct.ap.test.decorator; package org.mapstruct.ap.test.decorator;
import static org.fest.assertions.Assertions.assertThat;
import java.util.Calendar; import java.util.Calendar;
import javax.tools.Diagnostic.Kind; import javax.tools.Diagnostic.Kind;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.MapperTestBase;
import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithClasses;
import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult;
import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic;
import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome;
import org.testng.annotations.Test; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
import static org.fest.assertions.Assertions.assertThat;
/** /**
* Test for the application of decorators. * Test for the application of decorators.
@ -43,7 +45,8 @@ import static org.fest.assertions.Assertions.assertThat;
AddressDto.class AddressDto.class
}) })
@IssueKey("163") @IssueKey("163")
public class DecoratorTest extends MapperTestBase { @RunWith(AnnotationProcessorTestRunner.class)
public class DecoratorTest {
@Test @Test
@WithClasses({ @WithClasses({

View File

@ -18,17 +18,18 @@
*/ */
package org.mapstruct.ap.test.enums; package org.mapstruct.ap.test.enums;
import static org.fest.assertions.Assertions.assertThat;
import javax.tools.Diagnostic.Kind; import javax.tools.Diagnostic.Kind;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.MapperTestBase;
import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithClasses;
import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult;
import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic;
import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome;
import org.testng.annotations.Test; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
import static org.fest.assertions.Assertions.assertThat;
/** /**
* Test for the generation and invocation of enum mapping methods. * Test for the generation and invocation of enum mapping methods.
@ -37,7 +38,8 @@ import static org.fest.assertions.Assertions.assertThat;
*/ */
@IssueKey("128") @IssueKey("128")
@WithClasses({ OrderMapper.class, OrderEntity.class, OrderType.class, OrderDto.class, ExternalOrderType.class }) @WithClasses({ OrderMapper.class, OrderEntity.class, OrderType.class, OrderDto.class, ExternalOrderType.class })
public class EnumMappingTest extends MapperTestBase { @RunWith(AnnotationProcessorTestRunner.class)
public class EnumMappingTest {
@Test @Test
public void shouldGenerateEnumMappingMethod() { public void shouldGenerateEnumMappingMethod() {

View File

@ -18,14 +18,15 @@
*/ */
package org.mapstruct.ap.test.erroneous.ambiguousfactorymethod; package org.mapstruct.ap.test.erroneous.ambiguousfactorymethod;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mapstruct.ap.test.erroneous.ambiguousfactorymethod.a.BarFactory; import org.mapstruct.ap.test.erroneous.ambiguousfactorymethod.a.BarFactory;
import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.MapperTestBase;
import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithClasses;
import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult;
import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic;
import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome;
import org.testng.annotations.Test; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
/** /**
* @author Sjaak Derksen * @author Sjaak Derksen
@ -35,7 +36,8 @@ import org.testng.annotations.Test;
Bar.class, Foo.class, BarFactory.class, Source.class, SourceTargetMapperAndBarFactory.class, Bar.class, Foo.class, BarFactory.class, Source.class, SourceTargetMapperAndBarFactory.class,
Target.class Target.class
}) })
public class FactoryTest extends MapperTestBase { @RunWith(AnnotationProcessorTestRunner.class)
public class FactoryTest {
@Test @Test
@IssueKey("81") @IssueKey("81")

View File

@ -20,13 +20,14 @@ package org.mapstruct.ap.test.erroneous.attributereference;
import javax.tools.Diagnostic.Kind; import javax.tools.Diagnostic.Kind;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.MapperTestBase;
import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithClasses;
import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult;
import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic;
import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome;
import org.testng.annotations.Test; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
/** /**
* Test for using unknown attributes in {@code @Mapping}. * Test for using unknown attributes in {@code @Mapping}.
@ -34,7 +35,8 @@ import org.testng.annotations.Test;
* @author Gunnar Morling * @author Gunnar Morling
*/ */
@WithClasses({ ErroneousMapper.class, Source.class, Target.class, AnotherTarget.class }) @WithClasses({ ErroneousMapper.class, Source.class, Target.class, AnotherTarget.class })
public class ErroneousMappingsTest extends MapperTestBase { @RunWith(AnnotationProcessorTestRunner.class)
public class ErroneousMappingsTest {
@Test @Test
@IssueKey("11") @IssueKey("11")

View File

@ -20,13 +20,14 @@ package org.mapstruct.ap.test.erroneous.typemismatch;
import javax.tools.Diagnostic.Kind; import javax.tools.Diagnostic.Kind;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.MapperTestBase;
import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithClasses;
import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult;
import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic;
import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome;
import org.testng.annotations.Test; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
/** /**
* Tests failures expected for unmappable attributes. * Tests failures expected for unmappable attributes.
@ -34,7 +35,8 @@ import org.testng.annotations.Test;
* @author Gunnar Morling * @author Gunnar Morling
*/ */
@WithClasses({ ErroneousMapper.class, Source.class, Target.class }) @WithClasses({ ErroneousMapper.class, Source.class, Target.class })
public class ErroneousMappingsTest extends MapperTestBase { @RunWith(AnnotationProcessorTestRunner.class)
public class ErroneousMappingsTest {
@Test @Test
@IssueKey("6") @IssueKey("6")

View File

@ -25,11 +25,12 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mapstruct.ap.test.factories.a.BarFactory; import org.mapstruct.ap.test.factories.a.BarFactory;
import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.MapperTestBase;
import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithClasses;
import org.testng.annotations.Test; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
/** /**
* @author Sjaak Derksen * @author Sjaak Derksen
@ -40,7 +41,8 @@ import org.testng.annotations.Test;
org.mapstruct.ap.test.factories.b.BarFactory.class, Source.class, SourceTargetMapperAndBar2Factory.class, org.mapstruct.ap.test.factories.b.BarFactory.class, Source.class, SourceTargetMapperAndBar2Factory.class,
Target.class, CustomList.class, CustomListImpl.class, CustomMap.class, CustomMapImpl.class, FactoryCreatable.class Target.class, CustomList.class, CustomListImpl.class, CustomMap.class, CustomMapImpl.class, FactoryCreatable.class
}) })
public class FactoryTest extends MapperTestBase { @RunWith(AnnotationProcessorTestRunner.class)
public class FactoryTest {
@Test @Test
public void shouldUseTwoFactoryMethods() { public void shouldUseTwoFactoryMethods() {
Target target = SourceTargetMapperAndBar2Factory.INSTANCE.sourceToTarget( createSource() ); Target target = SourceTargetMapperAndBar2Factory.INSTANCE.sourceToTarget( createSource() );

View File

@ -18,13 +18,14 @@
*/ */
package org.mapstruct.ap.test.imports; package org.mapstruct.ap.test.imports;
import static org.fest.assertions.Assertions.assertThat;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mapstruct.ap.test.imports.from.Foo; import org.mapstruct.ap.test.imports.from.Foo;
import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.MapperTestBase;
import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithClasses;
import org.testng.annotations.Test; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
import static org.fest.assertions.Assertions.assertThat;
/** /**
* Test for generating a mapper which references types whose names clash with names of used annotations and exceptions. * Test for generating a mapper which references types whose names clash with names of used annotations and exceptions.
@ -41,7 +42,8 @@ import static org.fest.assertions.Assertions.assertThat;
Foo.class, Foo.class,
org.mapstruct.ap.test.imports.to.Foo.class org.mapstruct.ap.test.imports.to.Foo.class
}) })
public class ConflictingTypesNamesTest extends MapperTestBase { @RunWith(AnnotationProcessorTestRunner.class)
public class ConflictingTypesNamesTest {
@Test @Test
public void mapperImportingTypesWithConflictingNamesCanBeGenerated() { public void mapperImportingTypesWithConflictingNamesCanBeGenerated() {

View File

@ -18,20 +18,22 @@
*/ */
package org.mapstruct.ap.test.inheritance; package org.mapstruct.ap.test.inheritance;
import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.MapperTestBase;
import org.mapstruct.ap.testutil.WithClasses;
import org.testng.annotations.Test;
import static org.fest.assertions.Assertions.assertThat; import static org.fest.assertions.Assertions.assertThat;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.WithClasses;
import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
/** /**
* Test for propagation of attributes inherited from super types. * Test for propagation of attributes inherited from super types.
* *
* @author Gunnar Morling * @author Gunnar Morling
*/ */
@WithClasses({ SourceBase.class, SourceExt.class, TargetBase.class, TargetExt.class, SourceTargetMapper.class }) @WithClasses({ SourceBase.class, SourceExt.class, TargetBase.class, TargetExt.class, SourceTargetMapper.class })
public class InheritanceTest extends MapperTestBase { @RunWith(AnnotationProcessorTestRunner.class)
public class InheritanceTest {
@Test @Test
@IssueKey("17") @IssueKey("17")

View File

@ -22,19 +22,21 @@ import static org.fest.assertions.Assertions.assertThat;
import javax.tools.Diagnostic.Kind; import javax.tools.Diagnostic.Kind;
import org.mapstruct.ap.testutil.MapperTestBase; import org.junit.Test;
import org.junit.runner.RunWith;
import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithClasses;
import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult;
import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic;
import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome;
import org.testng.annotations.Test; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
/** /**
* Test for setting an attribute where the target attribute of a super-type. * Test for setting an attribute where the target attribute of a super-type.
* *
* @author Gunnar Morling * @author Gunnar Morling
*/ */
public class AttributeInheritanceTest extends MapperTestBase { @RunWith(AnnotationProcessorTestRunner.class)
public class AttributeInheritanceTest {
@Test @Test
@WithClasses({ Source.class, Target.class, SourceTargetMapper.class }) @WithClasses({ Source.class, Target.class, SourceTargetMapper.class })

View File

@ -18,18 +18,20 @@
*/ */
package org.mapstruct.ap.test.inheritance.complex; package org.mapstruct.ap.test.inheritance.complex;
import static org.fest.assertions.Assertions.assertThat;
import java.util.Arrays; import java.util.Arrays;
import javax.tools.Diagnostic.Kind; import javax.tools.Diagnostic.Kind;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.MapperTestBase;
import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithClasses;
import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult;
import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic;
import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome;
import org.testng.annotations.Test; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
import static org.fest.assertions.Assertions.assertThat;
/** /**
* Test for propagation of attributes inherited from super types. * Test for propagation of attributes inherited from super types.
@ -41,7 +43,8 @@ import static org.fest.assertions.Assertions.assertThat;
SourceExt.class, SourceExt2.class, SourceExt.class, SourceExt2.class,
TargetComposite.class, AdditionalFooSource.class TargetComposite.class, AdditionalFooSource.class
}) })
public class ComplexInheritanceTest extends MapperTestBase { @RunWith(AnnotationProcessorTestRunner.class)
public class ComplexInheritanceTest {
@Test @Test
@IssueKey("34") @IssueKey("34")

View File

@ -22,13 +22,14 @@ import static org.fest.assertions.Assertions.assertThat;
import javax.xml.bind.annotation.XmlElementDecl; import javax.xml.bind.annotation.XmlElementDecl;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mapstruct.ap.test.jaxb.selection.test1.OrderType; import org.mapstruct.ap.test.jaxb.selection.test1.OrderType;
import org.mapstruct.ap.test.jaxb.selection.test2.ObjectFactory; import org.mapstruct.ap.test.jaxb.selection.test2.ObjectFactory;
import org.mapstruct.ap.test.jaxb.selection.test2.OrderShippingDetailsType; import org.mapstruct.ap.test.jaxb.selection.test2.OrderShippingDetailsType;
import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.MapperTestBase;
import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithClasses;
import org.testng.annotations.Test; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
/** /**
* Test for the selection of JAXB mapping and factory methods based on the "name" and "scope" attributes * Test for the selection of JAXB mapping and factory methods based on the "name" and "scope" attributes
@ -42,7 +43,8 @@ import org.testng.annotations.Test;
OrderDto.class, OrderShippingDetailsDto.class, OrderType.class, OrderShippingDetailsType.class, OrderDto.class, OrderShippingDetailsDto.class, OrderType.class, OrderShippingDetailsType.class,
OrderMapper.class OrderMapper.class
}) })
public class JaxbFactoryMethodSelectionTest extends MapperTestBase { @RunWith(AnnotationProcessorTestRunner.class)
public class JaxbFactoryMethodSelectionTest {
@Test @Test
public void shouldMatchOnNameAndOrScope() { public void shouldMatchOnNameAndOrScope() {

View File

@ -19,13 +19,15 @@
package org.mapstruct.ap.test.mapperconfig; package org.mapstruct.ap.test.mapperconfig;
import static org.fest.assertions.Assertions.assertThat; import static org.fest.assertions.Assertions.assertThat;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.MapperTestBase;
import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithClasses;
import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult;
import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic;
import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome;
import org.testng.annotations.Test; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
/** /**
* *
@ -42,7 +44,8 @@ import org.testng.annotations.Test;
CustomMapperViaMapperConfig.class, CustomMapperViaMapperConfig.class,
SourceTargetMapper.class SourceTargetMapper.class
} ) } )
public class ConfigTest extends MapperTestBase { @RunWith(AnnotationProcessorTestRunner.class)
public class ConfigTest {
@Test @Test
@WithClasses( { Target.class, SourceTargetMapper.class } ) @WithClasses( { Target.class, SourceTargetMapper.class } )

View File

@ -18,19 +18,20 @@
*/ */
package org.mapstruct.ap.test.naming; package org.mapstruct.ap.test.naming;
import static org.fest.assertions.Assertions.assertThat;
import static org.fest.assertions.MapAssert.entry;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.MapperTestBase;
import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithClasses;
import org.testng.annotations.Test; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
import static org.fest.assertions.Assertions.assertThat;
import static org.fest.assertions.MapAssert.entry;
/** /**
* Test for aming of variables/members which conflict with keywords or parameter names. * Test for aming of variables/members which conflict with keywords or parameter names.
@ -39,7 +40,8 @@ import static org.fest.assertions.MapAssert.entry;
*/ */
@WithClasses({ SourceTargetMapper.class, While.class, Break.class, Source.class }) @WithClasses({ SourceTargetMapper.class, While.class, Break.class, Source.class })
@IssueKey("53") @IssueKey("53")
public class VariableNamingTest extends MapperTestBase { @RunWith(AnnotationProcessorTestRunner.class)
public class VariableNamingTest {
@Test @Test
public void shouldGenerateImplementationsOfMethodsWithProblematicVariableNmes() { public void shouldGenerateImplementationsOfMethodsWithProblematicVariableNmes() {

View File

@ -18,8 +18,11 @@
*/ */
package org.mapstruct.ap.test.nestedmethodcall; package org.mapstruct.ap.test.nestedmethodcall;
import static org.fest.assertions.Assertions.assertThat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.xml.bind.JAXBElement; import javax.xml.bind.JAXBElement;
import javax.xml.datatype.DatatypeConfigurationException; import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeConstants; import javax.xml.datatype.DatatypeConstants;
@ -27,12 +30,11 @@ import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar; import javax.xml.datatype.XMLGregorianCalendar;
import javax.xml.namespace.QName; import javax.xml.namespace.QName;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.MapperTestBase;
import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithClasses;
import org.testng.annotations.Test; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
import static org.fest.assertions.Assertions.assertThat;
/** /**
* Test for the nested invocation of mapping methods. * Test for the nested invocation of mapping methods.
@ -47,7 +49,8 @@ import static org.fest.assertions.Assertions.assertThat;
OrderDetailsType.class, OrderDetailsType.class,
OrderType.class OrderType.class
}) })
public class NestedMappingMethodInvocationTest extends MapperTestBase { @RunWith(AnnotationProcessorTestRunner.class)
public class NestedMappingMethodInvocationTest {
private static final QName QNAME = new QName( "dont-care" ); private static final QName QNAME = new QName( "dont-care" );

View File

@ -20,6 +20,7 @@
package org.mapstruct.ap.test.nestedmethodcall; package org.mapstruct.ap.test.nestedmethodcall;
import java.util.List; import java.util.List;
import javax.xml.bind.JAXBElement; import javax.xml.bind.JAXBElement;
/** /**

View File

@ -20,6 +20,7 @@
package org.mapstruct.ap.test.nestedmethodcall; package org.mapstruct.ap.test.nestedmethodcall;
import java.util.List; import java.util.List;
import javax.xml.bind.JAXBElement; import javax.xml.bind.JAXBElement;
import javax.xml.datatype.XMLGregorianCalendar; import javax.xml.datatype.XMLGregorianCalendar;

View File

@ -20,6 +20,7 @@
package org.mapstruct.ap.test.nestedmethodcall; package org.mapstruct.ap.test.nestedmethodcall;
import java.util.List; import java.util.List;
import javax.xml.bind.JAXBElement; import javax.xml.bind.JAXBElement;
import javax.xml.datatype.XMLGregorianCalendar; import javax.xml.datatype.XMLGregorianCalendar;

View File

@ -18,13 +18,14 @@
*/ */
package org.mapstruct.ap.test.oneway; package org.mapstruct.ap.test.oneway;
import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.MapperTestBase;
import org.mapstruct.ap.testutil.WithClasses;
import org.testng.annotations.Test;
import static org.fest.assertions.Assertions.assertThat; import static org.fest.assertions.Assertions.assertThat;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.WithClasses;
import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
/** /**
* Test for propagation of attribute without setter in source and getter in * Test for propagation of attribute without setter in source and getter in
* target. * target.
@ -32,7 +33,8 @@ import static org.fest.assertions.Assertions.assertThat;
* @author Gunnar Morling * @author Gunnar Morling
*/ */
@WithClasses({ Source.class, Target.class, SourceTargetMapper.class }) @WithClasses({ Source.class, Target.class, SourceTargetMapper.class })
public class OnewayTest extends MapperTestBase { @RunWith(AnnotationProcessorTestRunner.class)
public class OnewayTest {
@Test @Test
@IssueKey("17") @IssueKey("17")

View File

@ -26,10 +26,11 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.MapperTestBase;
import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithClasses;
import org.testng.annotations.Test; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
/** /**
* @author Andreas Gudian * @author Andreas Gudian
@ -38,7 +39,8 @@ import org.testng.annotations.Test;
@IssueKey( "82" ) @IssueKey( "82" )
@WithClasses( { Bar.class, Foo.class, FooMapper.class, ReferencedCustomMapper.class, Source.class, @WithClasses( { Bar.class, Foo.class, FooMapper.class, ReferencedCustomMapper.class, Source.class,
SourceTargetMapper.class, Target.class, BaseType.class, SomeType.class, SomeOtherType.class } ) SourceTargetMapper.class, Target.class, BaseType.class, SomeType.class, SomeOtherType.class } )
public class ReferencedMapperTest extends MapperTestBase { @RunWith(AnnotationProcessorTestRunner.class)
public class ReferencedMapperTest {
@Test @Test
public void referencedMappersAreInstatiatedCorrectly() { public void referencedMappersAreInstatiatedCorrectly() {
Target target = SourceTargetMapper.INSTANCE.sourceToTarget( createSource() ); Target target = SourceTargetMapper.INSTANCE.sourceToTarget( createSource() );

View File

@ -18,16 +18,17 @@
*/ */
package org.mapstruct.ap.test.references.samename; package org.mapstruct.ap.test.references.samename;
import static org.fest.assertions.Assertions.assertThat;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mapstruct.ap.test.references.samename.a.AnotherSourceTargetMapper; import org.mapstruct.ap.test.references.samename.a.AnotherSourceTargetMapper;
import org.mapstruct.ap.test.references.samename.a.CustomMapper; import org.mapstruct.ap.test.references.samename.a.CustomMapper;
import org.mapstruct.ap.test.references.samename.model.Source; import org.mapstruct.ap.test.references.samename.model.Source;
import org.mapstruct.ap.test.references.samename.model.Target; import org.mapstruct.ap.test.references.samename.model.Target;
import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.MapperTestBase;
import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithClasses;
import org.testng.annotations.Test; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
import static org.fest.assertions.Assertions.assertThat;
/** /**
* Test for referring several mappers with the same simple name. * Test for referring several mappers with the same simple name.
@ -44,7 +45,8 @@ import static org.fest.assertions.Assertions.assertThat;
Jsr330SourceTargetMapper.class, Jsr330SourceTargetMapper.class,
AnotherSourceTargetMapper.class AnotherSourceTargetMapper.class
}) })
public class SeveralReferencedMappersWithSameSimpleNameTest extends MapperTestBase { @RunWith(AnnotationProcessorTestRunner.class)
public class SeveralReferencedMappersWithSameSimpleNameTest {
@Test @Test
public void severalMappersWithSameSimpleNameCanBeReferenced() { public void severalMappersWithSameSimpleNameCanBeReferenced() {

View File

@ -18,19 +18,20 @@
*/ */
package org.mapstruct.ap.test.severalsources; package org.mapstruct.ap.test.severalsources;
import static org.fest.assertions.Assertions.assertThat;
import javax.lang.model.SourceVersion; import javax.lang.model.SourceVersion;
import javax.tools.Diagnostic.Kind; import javax.tools.Diagnostic.Kind;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.MapperTestBase;
import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithClasses;
import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult;
import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic;
import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome;
import org.mapstruct.ap.testutil.compilation.annotation.ProcessorOption; import org.mapstruct.ap.testutil.compilation.annotation.ProcessorOption;
import org.testng.annotations.Test; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
import static org.fest.assertions.Assertions.assertThat;
/** /**
* Test for propagation of attribute without setter in source and getter in * Test for propagation of attribute without setter in source and getter in
@ -39,7 +40,8 @@ import static org.fest.assertions.Assertions.assertThat;
* @author Gunnar Morling * @author Gunnar Morling
*/ */
@IssueKey("31") @IssueKey("31")
public class SeveralSourceParametersTest extends MapperTestBase { @RunWith(AnnotationProcessorTestRunner.class)
public class SeveralSourceParametersTest {
@Test @Test
@WithClasses({ Person.class, Address.class, DeliveryAddress.class, SourceTargetMapper.class }) @WithClasses({ Person.class, Address.class, DeliveryAddress.class, SourceTargetMapper.class })

View File

@ -24,10 +24,11 @@ import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.MapperTestBase;
import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithClasses;
import org.testng.annotations.Test; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
/** /**
* Test for the generation of implementation of abstract base classes. * Test for the generation of implementation of abstract base classes.
@ -38,7 +39,8 @@ import org.testng.annotations.Test;
Source.class, Target.class, SourceTargetMapper.class, TimeAndFormat.class, Source.class, Target.class, SourceTargetMapper.class, TimeAndFormat.class,
TimeAndFormatMapper.class TimeAndFormatMapper.class
}) })
public class SourcePropertyMapSeveralTimesTest extends MapperTestBase { @RunWith(AnnotationProcessorTestRunner.class)
public class SourcePropertyMapSeveralTimesTest {
@Test @Test
@IssueKey("94") @IssueKey("94")

View File

@ -18,18 +18,19 @@
*/ */
package org.mapstruct.ap.test.unmappedtarget; package org.mapstruct.ap.test.unmappedtarget;
import static org.fest.assertions.Assertions.assertThat;
import javax.tools.Diagnostic.Kind; import javax.tools.Diagnostic.Kind;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.MapperTestBase;
import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithClasses;
import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult;
import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic;
import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome;
import org.mapstruct.ap.testutil.compilation.annotation.ProcessorOption; import org.mapstruct.ap.testutil.compilation.annotation.ProcessorOption;
import org.testng.annotations.Test; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
import static org.fest.assertions.Assertions.assertThat;
/** /**
* Tests expected diagnostics for unmapped target properties. * Tests expected diagnostics for unmapped target properties.
@ -37,7 +38,8 @@ import static org.fest.assertions.Assertions.assertThat;
* @author Gunnar Morling * @author Gunnar Morling
*/ */
@IssueKey("35") @IssueKey("35")
public class UnmappedTargetTest extends MapperTestBase { @RunWith(AnnotationProcessorTestRunner.class)
public class UnmappedTargetTest {
@Test @Test
@WithClasses({ Source.class, Target.class, SourceTargetMapper.class }) @WithClasses({ Source.class, Target.class, SourceTargetMapper.class })

View File

@ -0,0 +1,78 @@
/**
* Copyright 2012-2014 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.runner;
import java.net.URL;
import org.junit.runners.BlockJUnit4ClassRunner;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.Statement;
/**
* A JUnit4 runner for Annotation Processor tests.
* <p>
* Test classes and test methods are safe to be executed in parallel.
*
* @author Andreas Gudian
*/
public class AnnotationProcessorTestRunner extends BlockJUnit4ClassRunner {
static final ModifiableURLClassLoader TEST_CLASS_LOADER = new ModifiableURLClassLoader();
/**
* @param klass the test class
* @throws Exception see {@link BlockJUnit4ClassRunner#BlockJUnit4ClassRunner(Class)}
*/
public AnnotationProcessorTestRunner(Class<?> klass) throws Exception {
super( replaceClassLoaderAndClass( klass ) );
}
/**
* newly loads the class with the test class loader and sets that loader as context class loader of the thread
*
* @param klass the class to replace
* @return the class loaded with the test class loader
*/
private static Class<?> replaceClassLoaderAndClass(Class<?> klass) {
String classFileName = klass.getName().replace( ".", "/" ) + ".class";
URL classResource = klass.getClassLoader().getResource( classFileName );
String fullyQualifiedUrl = classResource.toExternalForm();
String basePath = fullyQualifiedUrl.substring( 0, fullyQualifiedUrl.length() - classFileName.length() );
TEST_CLASS_LOADER.addURL( basePath );
Thread.currentThread().setContextClassLoader( TEST_CLASS_LOADER );
try {
return TEST_CLASS_LOADER.loadClass( klass.getName() );
}
catch ( ClassNotFoundException e ) {
throw new RuntimeException( e );
}
}
@Override
protected Statement methodBlock(FrameworkMethod method) {
Statement statement = super.methodBlock( method );
statement = new CompilingStatement( statement, method, TEST_CLASS_LOADER );
return statement;
}
}

View File

@ -16,15 +16,12 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.mapstruct.ap.testutil; package org.mapstruct.ap.testutil.runner;
import static org.fest.assertions.Assertions.assertThat; import static org.fest.assertions.Assertions.assertThat;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Method;
import java.net.URL;
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.Collection;
@ -33,9 +30,7 @@ import java.util.Comparator;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import javax.tools.DiagnosticCollector; import javax.tools.DiagnosticCollector;
@ -46,42 +41,32 @@ import javax.tools.StandardJavaFileManager;
import javax.tools.StandardLocation; import javax.tools.StandardLocation;
import javax.tools.ToolProvider; import javax.tools.ToolProvider;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.Statement;
import org.mapstruct.ap.MappingProcessor; import org.mapstruct.ap.MappingProcessor;
import org.mapstruct.ap.testutil.WithClasses;
import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult;
import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome;
import org.mapstruct.ap.testutil.compilation.annotation.ProcessorOption; import org.mapstruct.ap.testutil.compilation.annotation.ProcessorOption;
import org.mapstruct.ap.testutil.compilation.model.CompilationOutcomeDescriptor; import org.mapstruct.ap.testutil.compilation.model.CompilationOutcomeDescriptor;
import org.mapstruct.ap.testutil.compilation.model.DiagnosticDescriptor; import org.mapstruct.ap.testutil.compilation.model.DiagnosticDescriptor;
import org.testng.annotations.BeforeMethod;
/** /**
* Base class for all mapper tests. * A JUnit4 statement that performs source generation using the annotation processor and compiles those sources.
* </p>
* The classes to be compiled for a given test method must be specified via
* {@link WithClasses}. In addition the following things can be configured
* optionally :
* <ul>
* <li>Processor options to be considered during compilation via
* {@link ProcessorOption}.</li>
* <li>The expected compilation outcome and expected diagnostics can be
* specified via {@link ExpectedCompilationOutcome}. If no outcome is specified,
* a successful compilation is assumed.</li>
* </ul>
* *
* @author Gunnar Morling * @author Andreas Gudian
*/ */
public abstract class MapperTestBase { class CompilingStatement extends Statement {
/**
* Property to specify the sub-directory below /target/ where the generated files are placed
*/
public static final String MAPPER_TEST_OUTPUT_DIR_PROPERTY = "mapper.test.output.dir";
private static final String TARGET_COMPILATION_TESTS = "/target/"
+ System.getProperty( MAPPER_TEST_OUTPUT_DIR_PROPERTY, "compilation-tests" ) + "_";
private static final String LINE_SEPARATOR = System.getProperty( "line.separator" ); private static final String LINE_SEPARATOR = System.getProperty( "line.separator" );
private static final DiagnosticDescriptorComparator COMPARATOR = new DiagnosticDescriptorComparator(); private static final DiagnosticDescriptorComparator COMPARATOR = new DiagnosticDescriptorComparator();
private static final String TARGET_COMPILATION_TESTS = "/target/" + System.getProperty( private static final ThreadLocal<Integer> THREAD_NUMBER = new ThreadLocal<Integer>() {
"mapper.test.output.dir",
"compilation-tests"
) + "_";
private static Map<Integer, Integer> threadsWithEnhancedClassloader = new ConcurrentHashMap<Integer, Integer>();
private static ThreadLocal<Integer> threadNumber = new ThreadLocal<Integer>() {
private AtomicInteger highWaterMark = new AtomicInteger( 0 ); private AtomicInteger highWaterMark = new AtomicInteger( 0 );
@Override @Override
@ -90,22 +75,36 @@ public abstract class MapperTestBase {
} }
}; };
private static ThreadLocal<CompilationCache> compilationCache = new ThreadLocal<CompilationCache>() { private static final ThreadLocal<CompilationCache> COMPILATION_CACHE = new ThreadLocal<CompilationCache>() {
@Override @Override
protected CompilationCache initialValue() { protected CompilationCache initialValue() {
return new CompilationCache(); return new CompilationCache();
} }
}; };
private static final List<String> LIBRARIES = Arrays.asList( "mapstruct.jar", "guava.jar", "javax.inject.jar" );
private final Statement next;
private final FrameworkMethod method;
private final ModifiableURLClassLoader classloader;
private JavaCompiler compiler; private JavaCompiler compiler;
private String sourceDir; private String sourceDir;
private String classOutputDir; private String classOutputDir;
private String sourceOutputDir; private String sourceOutputDir;
private List<File> classPath; private List<File> classPath;
private final List<String> libraries;
public MapperTestBase() { public CompilingStatement(Statement next, FrameworkMethod method, ModifiableURLClassLoader classloader) {
this.libraries = Arrays.asList( "mapstruct.jar", "guava.jar", "javax.inject.jar" ); this.next = next;
this.method = method;
this.classloader = classloader;
}
@Override
public void evaluate() throws Throwable {
generateMapperImplementation();
next.evaluate();
} }
protected void setupCompiler() throws Exception { protected void setupCompiler() throws Exception {
@ -113,7 +112,7 @@ public abstract class MapperTestBase {
String basePath = getBasePath(); String basePath = getBasePath();
Integer i = threadNumber.get(); Integer i = THREAD_NUMBER.get();
sourceDir = basePath + "/src/test/java"; sourceDir = basePath + "/src/test/java";
classOutputDir = basePath + TARGET_COMPILATION_TESTS + i + "/classes"; classOutputDir = basePath + TARGET_COMPILATION_TESTS + i + "/classes";
@ -122,51 +121,35 @@ public abstract class MapperTestBase {
String testDependenciesDir = basePath + "/target/test-dependencies/"; String testDependenciesDir = basePath + "/target/test-dependencies/";
classPath = new ArrayList<File>(); classPath = new ArrayList<File>();
for ( String library : libraries ) { for ( String library : LIBRARIES ) {
classPath.add( new File( testDependenciesDir, library ) ); classPath.add( new File( testDependenciesDir, library ) );
} }
createOutputDirs(); createOutputDirs();
// TODO #140 Is there a better way to do this? classloader.addOutputDir( classOutputDir );
if ( !threadsWithEnhancedClassloader.containsKey( i ) ) {
// we need to make sure that the the generated classes are loaded by the same classloader as the test has
// been loaded already. Otherwise some tests won't work.
URLClassLoader classLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();
Class<?> clazz = URLClassLoader.class;
Method method = clazz.getDeclaredMethod( "addURL", new Class[] { URL.class } );
method.setAccessible( true );
method.invoke( classLoader, new File( classOutputDir ).toURI().toURL() );
threadsWithEnhancedClassloader.put( i, i );
}
} }
@BeforeMethod protected void generateMapperImplementation() throws Exception {
public void generateMapperImplementation(Method testMethod) throws Exception { CompilationResultHolder compilationResult = compile( getTestClasses(), getProcessorOptions() );
CompilationResultHolder compilationResult =
compile( getTestClasses( testMethod ), getProcessorOptions( testMethod ) );
CompilationOutcomeDescriptor actualResult = CompilationOutcomeDescriptor.forResult( CompilationOutcomeDescriptor actualResult =
sourceDir, CompilationOutcomeDescriptor.forResult(
compilationResult.compilationSuccessful, sourceDir,
compilationResult.diagnostics.getDiagnostics() compilationResult.compilationSuccessful,
); compilationResult.diagnostics.getDiagnostics() );
CompilationOutcomeDescriptor expectedResult = CompilationOutcomeDescriptor.forExpectedCompilationResult( CompilationOutcomeDescriptor expectedResult =
testMethod.getAnnotation( ExpectedCompilationOutcome.class ) CompilationOutcomeDescriptor.forExpectedCompilationResult(
); method.getAnnotation( ExpectedCompilationOutcome.class ) );
if ( expectedResult.getCompilationResult() == CompilationResult.SUCCEEDED ) { if ( expectedResult.getCompilationResult() == CompilationResult.SUCCEEDED ) {
assertThat( actualResult.getCompilationResult() ) assertThat( actualResult.getCompilationResult() ).describedAs(
.describedAs( "Compilation failed. Diagnostics: " + compilationResult.diagnostics.getDiagnostics() ).isEqualTo(
"Compilation failed. Diagnostics: " + compilationResult.diagnostics.getDiagnostics() CompilationResult.SUCCEEDED );
)
.isEqualTo( CompilationResult.SUCCEEDED );
} }
else { else {
assertThat( actualResult.getCompilationResult() ) assertThat( actualResult.getCompilationResult() ).describedAs(
.describedAs( "Compilation succeeded but should have failed." ) "Compilation succeeded but should have failed." ).isEqualTo( CompilationResult.FAILED );
.isEqualTo( CompilationResult.FAILED );
} }
assertDiagnostics( actualResult.getDiagnostics(), expectedResult.getDiagnostics() ); assertDiagnostics( actualResult.getDiagnostics(), expectedResult.getDiagnostics() );
@ -188,9 +171,8 @@ public abstract class MapperTestBase {
actualDiagnostics.toString().replace( ", ", LINE_SEPARATOR ), actualDiagnostics.toString().replace( ", ", LINE_SEPARATOR ),
LINE_SEPARATOR, LINE_SEPARATOR,
LINE_SEPARATOR, LINE_SEPARATOR,
expectedDiagnostics.toString().replace( ", ", LINE_SEPARATOR ) expectedDiagnostics.toString().replace( ", ", LINE_SEPARATOR ) ) ).hasSize(
) expectedDiagnostics.size() );
).hasSize( expectedDiagnostics.size() );
while ( actualIterator.hasNext() ) { while ( actualIterator.hasNext() ) {
@ -209,9 +191,7 @@ public abstract class MapperTestBase {
"Unexpected message for diagnostic %s:%s %s", "Unexpected message for diagnostic %s:%s %s",
actual.getSourceFileName(), actual.getSourceFileName(),
actual.getLine(), actual.getLine(),
actual.getKind() actual.getKind() ) ).matches( ".*" + expected.getMessage() + ".*" );
)
).matches( ".*" + expected.getMessage() + ".*" );
} }
} }
@ -219,26 +199,24 @@ public abstract class MapperTestBase {
* Returns the classes to be compiled for this test. * Returns the classes to be compiled for this test.
* *
* @param testMethod The test method of interest * @param testMethod The test method of interest
*
* @return A set containing the classes to be compiled for this test * @return A set containing the classes to be compiled for this test
*/ */
private Set<Class<?>> getTestClasses(Method testMethod) { private Set<Class<?>> getTestClasses() {
Set<Class<?>> testClasses = new HashSet<Class<?>>(); Set<Class<?>> testClasses = new HashSet<Class<?>>();
WithClasses withClasses = testMethod.getAnnotation( WithClasses.class ); WithClasses withClasses = method.getAnnotation( WithClasses.class );
if ( withClasses != null ) { if ( withClasses != null ) {
testClasses.addAll( Arrays.asList( withClasses.value() ) ); testClasses.addAll( Arrays.asList( withClasses.value() ) );
} }
withClasses = this.getClass().getAnnotation( WithClasses.class ); withClasses = method.getMethod().getDeclaringClass().getAnnotation( WithClasses.class );
if ( withClasses != null ) { if ( withClasses != null ) {
testClasses.addAll( Arrays.asList( withClasses.value() ) ); testClasses.addAll( Arrays.asList( withClasses.value() ) );
} }
if ( testClasses.isEmpty() ) { 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 testClasses; return testClasses;
@ -248,18 +226,17 @@ public abstract class MapperTestBase {
* Returns the processor options to be used this test. * Returns the processor options to be used this test.
* *
* @param testMethod The test method of interest * @param testMethod The test method of interest
*
* @return A list containing the processor options to be used for this test * @return A list containing the processor options to be used for this test
*/ */
private List<String> getProcessorOptions(Method testMethod) { private List<String> getProcessorOptions() {
ProcessorOption processorOption = testMethod.getAnnotation( ProcessorOption.class ); ProcessorOption processorOption = method.getAnnotation( ProcessorOption.class );
if ( processorOption == null ) { if ( processorOption == null ) {
processorOption = this.getClass().getAnnotation( ProcessorOption.class ); processorOption = method.getMethod().getDeclaringClass().getAnnotation( ProcessorOption.class );
} }
return processorOption != null ? Arrays.asList( asOptionString( processorOption ) ) : return processorOption != null ? Arrays.asList( asOptionString( processorOption ) )
Collections.<String>emptyList(); : Collections.<String> emptyList();
} }
private String asOptionString(ProcessorOption processorOption) { private String asOptionString(ProcessorOption processorOption) {
@ -270,14 +247,8 @@ public abstract class MapperTestBase {
Set<File> sourceFiles = new HashSet<File>( classes.size() ); Set<File> sourceFiles = new HashSet<File>( classes.size() );
for ( Class<?> clazz : classes ) { for ( Class<?> clazz : classes ) {
sourceFiles.add( sourceFiles.add( new File( sourceDir + File.separator + clazz.getName().replace( ".", File.separator )
new File( + ".java" ) );
sourceDir +
File.separator +
clazz.getName().replace( ".", File.separator ) +
".java"
)
);
} }
return sourceFiles; return sourceFiles;
@ -287,7 +258,7 @@ public abstract class MapperTestBase {
throws Exception { throws Exception {
CompilationRequest request = new CompilationRequest( sourceClasses, processorOptions ); CompilationRequest request = new CompilationRequest( sourceClasses, processorOptions );
CompilationCache cache = compilationCache.get(); CompilationCache cache = COMPILATION_CACHE.get();
if ( request.equals( cache.lastRequest ) ) { if ( request.equals( cache.lastRequest ) ) {
return cache.lastResult; return cache.lastResult;
} }
@ -308,14 +279,8 @@ public abstract class MapperTestBase {
throw new RuntimeException( e ); throw new RuntimeException( e );
} }
CompilationTask task = compiler.getTask( CompilationTask task =
null, compiler.getTask( null, fileManager, diagnostics, processorOptions, null, compilationUnits );
fileManager,
diagnostics,
processorOptions,
null,
compilationUnits
);
task.setProcessors( Arrays.asList( new MappingProcessor() ) ); task.setProcessors( Arrays.asList( new MappingProcessor() ) );
CompilationResultHolder resultHolder = new CompilationResultHolder( diagnostics, task.call() ); CompilationResultHolder resultHolder = new CompilationResultHolder( diagnostics, task.call() );

View File

@ -0,0 +1,85 @@
/**
* Copyright 2012-2014 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.runner;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
/**
* A parallel capable class loader for which additional URLs can be added after construction, and that will force
* classes from org.mapstruct.at.test.** packages to be loaded with this instance
*
* @author Andreas Gudian
*/
public class ModifiableURLClassLoader extends URLClassLoader {
private static final String ORG_MAPSTRUCT_AP_TEST = "org.mapstruct.ap.test.";
static {
ClassLoader.registerAsParallelCapable();
}
private ConcurrentMap<URL, URL> addedURLs = new ConcurrentHashMap<URL, URL>();
public ModifiableURLClassLoader() {
super( new URL[] {}, new FilteringParentClassLoader() );
}
@Override
protected void addURL(URL url) {
if ( addedURLs.putIfAbsent( url, url ) == null ) {
super.addURL( url );
}
}
/**
* @param basePath
*/
public void addURL(String basePath) {
try {
addURL( new URL( basePath ) );
}
catch ( MalformedURLException e ) {
throw new RuntimeException( e );
}
}
public void addOutputDir(String outputDir) {
try {
addURL( new File( outputDir ).toURI().toURL() );
}
catch ( MalformedURLException e ) {
throw new RuntimeException( e );
}
}
private static final class FilteringParentClassLoader extends ClassLoader {
@Override
protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
if ( name.startsWith( ORG_MAPSTRUCT_AP_TEST ) ) {
return null;
}
return super.loadClass( name, resolve );
}
}
}