#2277 Add tests with fixtures with testing the generated source code

This commit is contained in:
Filip Hrisafov 2021-02-06 16:27:24 +01:00
parent c59ca79e7f
commit b643061b57
12 changed files with 311 additions and 0 deletions

View File

@ -0,0 +1,46 @@
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.ap.test.defaultcomponentmodel;
import org.junit.Rule;
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;
import org.mapstruct.ap.testutil.runner.GeneratedSource;
/**
* @author Filip Hrisafov
*/
@IssueKey("2277")
@RunWith(AnnotationProcessorTestRunner.class)
@WithClasses({
Source.class,
Target.class,
})
public class DefaultComponentModelMapperTest {
@Rule
public final GeneratedSource generatedSource = new GeneratedSource();
@Test
@WithClasses({
InstanceIterableMapper.class,
InstanceMapper.class,
NonInstanceIterableMapper.class,
NonInstanceMapper.class,
NonPublicIterableMapper.class,
NonPublicMapper.class,
})
public void shouldGenerateCorrectMapperInstantiation() {
generatedSource.addComparisonToFixtureFor(
InstanceIterableMapper.class,
NonInstanceIterableMapper.class,
NonPublicIterableMapper.class
);
}
}

View File

@ -0,0 +1,19 @@
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.ap.test.defaultcomponentmodel;
import java.util.List;
import org.mapstruct.Mapper;
/**
* @author Filip Hrisafov
*/
@Mapper(uses = InstanceMapper.class)
public interface InstanceIterableMapper {
List<Target> map(List<Source> list);
}

View File

@ -0,0 +1,20 @@
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.ap.test.defaultcomponentmodel;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
/**
* @author Filip Hrisafov
*/
@Mapper
public interface InstanceMapper {
InstanceMapper INSTANCE = Mappers.getMapper( InstanceMapper.class );
Target map(Source source);
}

View File

@ -0,0 +1,19 @@
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.ap.test.defaultcomponentmodel;
import java.util.List;
import org.mapstruct.Mapper;
/**
* @author Filip Hrisafov
*/
@Mapper(uses = NonInstanceMapper.class)
public interface NonInstanceIterableMapper {
List<Target> map(List<Source> list);
}

View File

@ -0,0 +1,20 @@
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.ap.test.defaultcomponentmodel;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
/**
* @author Filip Hrisafov
*/
@Mapper
public interface NonInstanceMapper {
NonInstanceMapper MAPPER = Mappers.getMapper( NonInstanceMapper.class );
Target map(Source source);
}

View File

@ -0,0 +1,19 @@
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.ap.test.defaultcomponentmodel;
import java.util.List;
import org.mapstruct.Mapper;
/**
* @author Filip Hrisafov
*/
@Mapper(uses = NonPublicMapper.class)
public interface NonPublicIterableMapper {
List<Target> map(List<Source> list);
}

View File

@ -0,0 +1,20 @@
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.ap.test.defaultcomponentmodel;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
/**
* @author Filip Hrisafov
*/
@Mapper
public abstract class NonPublicMapper {
static final NonPublicMapper INSTANCE = Mappers.getMapper( NonPublicMapper.class );
public abstract Target map(Source source);
}

View File

@ -0,0 +1,22 @@
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.ap.test.defaultcomponentmodel;
/**
* @author Filip Hrisafov
*/
public class Source {
private final String id;
public Source(String id) {
this.id = id;
}
public String getId() {
return id;
}
}

View File

@ -0,0 +1,22 @@
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.ap.test.defaultcomponentmodel;
/**
* @author Filip Hrisafov
*/
public class Target {
private final String id;
public Target(String id) {
this.id = id;
}
public String getId() {
return id;
}
}

View File

@ -0,0 +1,34 @@
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.ap.test.defaultcomponentmodel;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.processing.Generated;
@Generated(
value = "org.mapstruct.ap.MappingProcessor",
date = "2021-02-06T16:20:45+0100",
comments = "version: , compiler: javac, environment: Java 11.0.9.1 (AdoptOpenJDK)"
)
public class InstanceIterableMapperImpl implements InstanceIterableMapper {
private final InstanceMapper instanceMapper = InstanceMapper.INSTANCE;
@Override
public List<Target> map(List<Source> list) {
if ( list == null ) {
return null;
}
List<Target> list1 = new ArrayList<Target>( list.size() );
for ( Source source : list ) {
list1.add( instanceMapper.map( source ) );
}
return list1;
}
}

View File

@ -0,0 +1,35 @@
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.ap.test.defaultcomponentmodel;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.processing.Generated;
import org.mapstruct.factory.Mappers;
@Generated(
value = "org.mapstruct.ap.MappingProcessor",
date = "2021-02-06T16:20:45+0100",
comments = "version: , compiler: javac, environment: Java 11.0.9.1 (AdoptOpenJDK)"
)
public class NonInstanceIterableMapperImpl implements NonInstanceIterableMapper {
private final NonInstanceMapper nonInstanceMapper = Mappers.getMapper( NonInstanceMapper.class );
@Override
public List<Target> map(List<Source> list) {
if ( list == null ) {
return null;
}
List<Target> list1 = new ArrayList<Target>( list.size() );
for ( Source source : list ) {
list1.add( nonInstanceMapper.map( source ) );
}
return list1;
}
}

View File

@ -0,0 +1,35 @@
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.ap.test.defaultcomponentmodel;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.processing.Generated;
import org.mapstruct.factory.Mappers;
@Generated(
value = "org.mapstruct.ap.MappingProcessor",
date = "2021-02-06T16:20:45+0100",
comments = "version: , compiler: javac, environment: Java 11.0.9.1 (AdoptOpenJDK)"
)
public class NonPublicIterableMapperImpl implements NonPublicIterableMapper {
private final NonPublicMapper nonPublicMapper = Mappers.getMapper( NonPublicMapper.class );
@Override
public List<Target> map(List<Source> list) {
if ( list == null ) {
return null;
}
List<Target> list1 = new ArrayList<Target>( list.size() );
for ( Source source : list ) {
list1.add( nonPublicMapper.map( source ) );
}
return list1;
}
}