#306 Extracting separate test for reproducing this issue

This commit is contained in:
Gunnar Morling 2014-10-09 23:43:25 +02:00
parent 3342990387
commit 3e411e085e
6 changed files with 157 additions and 21 deletions

View File

@ -0,0 +1,41 @@
/**
* 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.test.bugs._306;
import java.util.Set;
import org.mapstruct.Mapper;
import org.mapstruct.TargetType;
import org.mapstruct.factory.Mappers;
@Mapper
public abstract class Issue306Mapper {
public static final Issue306Mapper INSTANCE = Mappers.getMapper( Issue306Mapper.class );
public abstract Source targetToSource(Target target);
protected void dummy1( Set<String> arg ) {
throw new RuntimeException();
}
protected Set<Long> dummy2( Object object, @TargetType Class<?> clazz ) {
throw new RuntimeException();
}
}

View File

@ -0,0 +1,40 @@
/**
* 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.test.bugs._306;
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;
/**
* Reproducer for https://github.com/mapstruct/mapstruct/issues/306.
*
* @author Sjaak Derksen
*/
@IssueKey( "306" )
@RunWith(AnnotationProcessorTestRunner.class)
public class Issue306Test {
@Test
@WithClasses( { Issue306Mapper.class, Source.class, Target.class } )
public void shouldForgeNewIterableMappingMethod() {
}
}

View File

@ -0,0 +1,35 @@
/**
* 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.test.bugs._306;
import java.util.Set;
public class Source {
private Set<String> fooSet;
public Set<String> getFooSet() {
return fooSet;
}
public void setFooSet(Set<String> fooSet) {
this.fooSet = fooSet;
}
}

View File

@ -0,0 +1,34 @@
/**
* 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.test.bugs._306;
import java.util.Set;
public class Target {
private Set<Long> fooSet;
public Set<Long> getFooSet() {
return fooSet;
}
public void setFooSet(Set<Long> fooSet) {
this.fooSet = fooSet;
}
}

View File

@ -18,27 +18,14 @@
*/
package org.mapstruct.ap.test.collection.forged;
import java.util.Set;
import org.mapstruct.Mapper;
import org.mapstruct.TargetType;
import org.mapstruct.factory.Mappers;
@Mapper
public abstract class CollectionMapper {
public interface CollectionMapper {
public static final CollectionMapper INSTANCE = Mappers.getMapper( CollectionMapper.class );
CollectionMapper INSTANCE = Mappers.getMapper( CollectionMapper.class );
public abstract Target sourceToTarget(Source source);
public abstract Source targetToSource(Target target);
// this method is added to reproduce issue 306
protected void dummy1( Set<String> arg ) {
throw new RuntimeException();
}
// this method is added to reproduce issue 306
protected Set<Long> dummy2( Object object, @TargetType Class clazz ) {
throw new RuntimeException();
}
Target sourceToTarget(Source source);
Source targetToSource(Target target);
}

View File

@ -34,11 +34,10 @@ import org.mapstruct.ap.util.Collections;
*
* @author Sjaak Derksen
*/
@IssueKey("4, 306")
@IssueKey( "4" )
@RunWith(AnnotationProcessorTestRunner.class)
public class CollectionMappingTest {
@Test
@WithClasses({ CollectionMapper.class, Source.class, Target.class })
public void shouldForgeNewIterableMappingMethod() {
@ -59,13 +58,13 @@ public class CollectionMappingTest {
@WithClasses({ CollectionMapper.class, Source.class, Target.class })
public void shouldForgeNewMapMappingMethod() {
Map sourceMap = ImmutableMap.<String, Long>builder().put( "rabbit", 1L ).build();
Map<String, Long> sourceMap = ImmutableMap.<String, Long>builder().put( "rabbit", 1L ).build();
Source source = new Source();
source.setBarMap( sourceMap );
Target target = CollectionMapper.INSTANCE.sourceToTarget( source );
assertThat( target ).isNotNull();
Map targetMap = ImmutableMap.<String, String>builder().put( "rabbit", "1" ).build();
Map<String, String> targetMap = ImmutableMap.<String, String>builder().put( "rabbit", "1" ).build();
assertThat( target.getBarMap() ).isEqualTo( targetMap );
Source source2 = CollectionMapper.INSTANCE.targetToSource( target );