Add extract of the unit tests for generics and @TargetType support to an integration test

This commit is contained in:
Andreas Gudian 2014-11-12 21:24:59 +01:00 committed by Gunnar Morling
parent dfe7e8012b
commit 760be8f4f8
8 changed files with 246 additions and 2 deletions

View File

@ -0,0 +1,27 @@
/**
* 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.itest.simple;
/**
* @author Andreas Gudian
*
*/
public class BaseType {
}

View File

@ -0,0 +1,57 @@
/**
* 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.itest.simple;
import java.util.Map;
import org.mapstruct.TargetType;
/**
* @author Andreas Gudian
*
*/
public class ReferencedCustomMapper {
public long incrementingIntToLong(int source) {
return source + 1;
}
@SuppressWarnings( "unchecked" )
public <T extends BaseType> T convert(String string, @TargetType Class<T> clazz) {
if ( clazz == SomeType.class ) {
return (T) new SomeType( string );
}
else if ( clazz == SomeOtherType.class ) {
return (T) new SomeOtherType( string );
}
return null;
}
public String toString(BaseType baseType) {
return String.valueOf( baseType );
}
/**
* This method should not be chosen for the mapping, as our types are never within the bounds of
* {@code T extends Map<?,?>}
*/
public <T extends Map<?, ?>> T unused(String string, @TargetType Class<T> clazz) {
throw new RuntimeException( "should never be called" );
}
}

View File

@ -0,0 +1,70 @@
/**
* 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.itest.simple;
/**
* @author Andreas Gudian
*
*/
public class SomeOtherType extends BaseType {
private String value;
public SomeOtherType(String value) {
this.value = value;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ( ( value == null ) ? 0 : value.hashCode() );
return result;
}
@Override
public boolean equals(Object obj) {
if ( this == obj ) {
return true;
}
if ( obj == null ) {
return false;
}
if ( getClass() != obj.getClass() ) {
return false;
}
SomeOtherType other = (SomeOtherType) obj;
if ( value == null ) {
if ( other.value != null ) {
return false;
}
}
else if ( !value.equals( other.value ) ) {
return false;
}
return true;
}
}

View File

@ -0,0 +1,70 @@
/**
* 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.itest.simple;
/**
* @author Andreas Gudian
*
*/
public class SomeType extends BaseType {
private String value;
public SomeType(String value) {
this.value = value;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ( ( value == null ) ? 0 : value.hashCode() );
return result;
}
@Override
public boolean equals(Object obj) {
if ( this == obj ) {
return true;
}
if ( obj == null ) {
return false;
}
if ( getClass() != obj.getClass() ) {
return false;
}
SomeType other = (SomeType) obj;
if ( value == null ) {
if ( other.value != null ) {
return false;
}
}
else if ( !value.equals( other.value ) ) {
return false;
}
return true;
}
}

View File

@ -25,6 +25,7 @@ public class Source {
private int qax;
private Long baz;
private int zip;
private String someType;
public int getFoo() {
return foo;
@ -65,4 +66,12 @@ public class Source {
public void setZip(int zip) {
this.zip = zip;
}
public String getSomeType() {
return someType;
}
public void setSomeType(String someType) {
this.someType = someType;
}
}

View File

@ -23,7 +23,7 @@ import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;
@Mapper
@Mapper( uses = ReferencedCustomMapper.class )
public abstract class SourceTargetAbstractMapper {
public static SourceTargetAbstractMapper INSTANCE = Mappers.getMapper( SourceTargetAbstractMapper.class );

View File

@ -24,7 +24,7 @@ import org.mapstruct.Mappings;
import org.mapstruct.InheritInverseConfiguration;
import org.mapstruct.factory.Mappers;
@Mapper
@Mapper(uses = ReferencedCustomMapper.class)
public interface SourceTargetMapper {
SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class );

View File

@ -18,6 +18,8 @@
*/
package org.mapstruct.itest.simple;
import org.mapstruct.itest.simple.SomeType;
public class Target {
private Long foo;
@ -25,6 +27,7 @@ public class Target {
private Long baz;
private int qax;
private String zip;
private SomeType someType;
public Long getFoo() {
return foo;
@ -65,4 +68,12 @@ public class Target {
public void setZip(String zip) {
this.zip = zip;
}
public SomeType getSomeType() {
return someType;
}
public void setSomeType(SomeType someType) {
this.someType = someType;
}
}