mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
Introducing @WithClasses annotation for specification of classes under test
This commit is contained in:
parent
5eb9de89ec
commit
dc72351e70
@ -19,26 +19,17 @@ import java.util.ArrayList;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.mapstruct.ap.testutil.IssueKey;
|
import org.mapstruct.ap.testutil.IssueKey;
|
||||||
import org.mapstruct.ap.testutil.MapperTestBase;
|
import org.mapstruct.ap.testutil.MapperTestBase;
|
||||||
|
import org.mapstruct.ap.testutil.WithClasses;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import static org.fest.assertions.Assertions.assertThat;
|
import static org.fest.assertions.Assertions.assertThat;
|
||||||
|
|
||||||
|
@WithClasses({ Source.class, Target.class, Colour.class, SourceTargetMapper.class })
|
||||||
public class CollectionMappingTest extends MapperTestBase {
|
public class CollectionMappingTest extends MapperTestBase {
|
||||||
|
|
||||||
@Override
|
|
||||||
protected List<Class<?>> getTestClasses() {
|
|
||||||
return Arrays.<Class<?>>asList(
|
|
||||||
Source.class,
|
|
||||||
Target.class,
|
|
||||||
Colour.class,
|
|
||||||
SourceTargetMapper.class
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@IssueKey("6")
|
@IssueKey("6")
|
||||||
public void shouldMapNullList() {
|
public void shouldMapNullList() {
|
||||||
|
@ -17,26 +17,23 @@ package org.mapstruct.ap.test.collection.defaultimplementation;
|
|||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.mapstruct.ap.testutil.IssueKey;
|
import org.mapstruct.ap.testutil.IssueKey;
|
||||||
import org.mapstruct.ap.testutil.MapperTestBase;
|
import org.mapstruct.ap.testutil.MapperTestBase;
|
||||||
|
import org.mapstruct.ap.testutil.WithClasses;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import static org.fest.assertions.Assertions.assertThat;
|
import static org.fest.assertions.Assertions.assertThat;
|
||||||
|
|
||||||
|
@WithClasses({
|
||||||
|
Source.class,
|
||||||
|
SourceFoo.class,
|
||||||
|
Target.class,
|
||||||
|
TargetFoo.class,
|
||||||
|
SourceTargetMapper.class
|
||||||
|
})
|
||||||
public class DefaultCollectionImplementationTest extends MapperTestBase {
|
public class DefaultCollectionImplementationTest extends MapperTestBase {
|
||||||
|
|
||||||
@Override
|
|
||||||
protected List<Class<?>> getTestClasses() {
|
|
||||||
return Arrays.<Class<?>>asList(
|
|
||||||
Source.class,
|
|
||||||
SourceFoo.class,
|
|
||||||
Target.class,
|
|
||||||
TargetFoo.class,
|
|
||||||
SourceTargetMapper.class
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@IssueKey("6")
|
@IssueKey("6")
|
||||||
|
@ -21,25 +21,22 @@ import java.util.GregorianCalendar;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.mapstruct.ap.testutil.MapperTestBase;
|
import org.mapstruct.ap.testutil.MapperTestBase;
|
||||||
|
import org.mapstruct.ap.testutil.WithClasses;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import static org.fest.assertions.Assertions.assertThat;
|
import static org.fest.assertions.Assertions.assertThat;
|
||||||
|
|
||||||
|
@WithClasses({
|
||||||
|
Car.class,
|
||||||
|
CarDto.class,
|
||||||
|
Person.class,
|
||||||
|
PersonDto.class,
|
||||||
|
CarMapper.class,
|
||||||
|
Category.class,
|
||||||
|
DateMapper.class
|
||||||
|
})
|
||||||
public class CarMapperTest extends MapperTestBase {
|
public class CarMapperTest extends MapperTestBase {
|
||||||
|
|
||||||
@Override
|
|
||||||
protected List<Class<?>> getTestClasses() {
|
|
||||||
return Arrays.<Class<?>>asList(
|
|
||||||
Car.class,
|
|
||||||
CarDto.class,
|
|
||||||
Person.class,
|
|
||||||
PersonDto.class,
|
|
||||||
CarMapper.class,
|
|
||||||
Category.class,
|
|
||||||
DateMapper.class
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldProvideMapperInstance() throws Exception {
|
public void shouldProvideMapperInstance() throws Exception {
|
||||||
assertThat( CarMapper.INSTANCE ).isNotNull();
|
assertThat( CarMapper.INSTANCE ).isNotNull();
|
||||||
|
@ -15,25 +15,15 @@
|
|||||||
*/
|
*/
|
||||||
package org.mapstruct.ap.test.conversion;
|
package org.mapstruct.ap.test.conversion;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.mapstruct.ap.testutil.MapperTestBase;
|
import org.mapstruct.ap.testutil.MapperTestBase;
|
||||||
|
import org.mapstruct.ap.testutil.WithClasses;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import static org.fest.assertions.Assertions.assertThat;
|
import static org.fest.assertions.Assertions.assertThat;
|
||||||
|
|
||||||
|
@WithClasses({ Source.class, Target.class, SourceTargetMapper.class })
|
||||||
public class ConversionTest extends MapperTestBase {
|
public class ConversionTest extends MapperTestBase {
|
||||||
|
|
||||||
@Override
|
|
||||||
protected List<Class<?>> getTestClasses() {
|
|
||||||
return Arrays.<Class<?>>asList(
|
|
||||||
Source.class,
|
|
||||||
Target.class,
|
|
||||||
SourceTargetMapper.class
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldApplyConversions() {
|
public void shouldApplyConversions() {
|
||||||
Source source = new Source();
|
Source source = new Source();
|
||||||
|
@ -101,7 +101,10 @@ public abstract class MapperTestBase {
|
|||||||
*
|
*
|
||||||
* @return A list containing the classes to be compiled for this test
|
* @return A list containing the classes to be compiled for this test
|
||||||
*/
|
*/
|
||||||
protected abstract List<Class<?>> getTestClasses();
|
private List<Class<?>> getTestClasses() {
|
||||||
|
WithClasses withClasses = this.getClass().getAnnotation( WithClasses.class );
|
||||||
|
return withClasses != null ? Arrays.asList( withClasses.value() ) : Collections.<Class<?>>emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
private List<File> getSourceFiles(List<Class<?>> classes) {
|
private List<File> getSourceFiles(List<Class<?>> classes) {
|
||||||
List<File> sourceFiles = new ArrayList<File>( classes.size() );
|
List<File> sourceFiles = new ArrayList<File>( classes.size() );
|
||||||
|
@ -0,0 +1,27 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2012-2013 Gunnar Morling (http://www.gunnarmorling.de/)
|
||||||
|
*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Gunnar Morling
|
||||||
|
*/
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
public @interface WithClasses {
|
||||||
|
Class<?>[] value();
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user