mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
Add extract of the unit tests for generics and @TargetType support to an integration test
This commit is contained in:
parent
dfe7e8012b
commit
760be8f4f8
@ -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 {
|
||||
|
||||
}
|
@ -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" );
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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 );
|
||||
|
@ -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 );
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user