mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#44 Adding tests for referencing map mapping methods for mapping properties
This commit is contained in:
parent
ea436e061f
commit
f9343bdc3f
@ -36,7 +36,7 @@ import static org.fest.assertions.MapAssert.entry;
|
||||
*
|
||||
* @author Gunnar Morling
|
||||
*/
|
||||
@WithClasses({ SourceTargetMapper.class, CustomNumberMapper.class })
|
||||
@WithClasses({ SourceTargetMapper.class, CustomNumberMapper.class, Source.class, Target.class })
|
||||
@IssueKey("44")
|
||||
public class MapMappingTest extends MapperTestBase {
|
||||
|
||||
@ -50,7 +50,10 @@ public class MapMappingTest extends MapperTestBase {
|
||||
|
||||
assertThat( target ).isNotNull();
|
||||
assertThat( target ).hasSize( 2 );
|
||||
assertThat( target ).includes( entry( "42", "01.01.1980" ), entry( "121", "20.07.2013" ) );
|
||||
assertThat( target ).includes(
|
||||
entry( "42", "01.01.1980" ),
|
||||
entry( "121", "20.07.2013" )
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -68,4 +71,44 @@ public class MapMappingTest extends MapperTestBase {
|
||||
entry( 121L, new GregorianCalendar( 2013, 6, 20 ).getTime() )
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldInvokeMapMethodImplementationForMapTypedProperty() {
|
||||
Map<Long, Date> values = new HashMap<Long, Date>();
|
||||
values.put( 42L, new GregorianCalendar( 1980, 0, 1 ).getTime() );
|
||||
values.put( 121L, new GregorianCalendar( 2013, 6, 20 ).getTime() );
|
||||
|
||||
Source source = new Source();
|
||||
source.setValues( values );
|
||||
|
||||
Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source );
|
||||
|
||||
assertThat( target ).isNotNull();
|
||||
assertThat( target.getValues() ).isNotNull();
|
||||
assertThat( target.getValues() ).hasSize( 2 );
|
||||
assertThat( target.getValues() ).includes(
|
||||
entry( "42", "01.01.1980" ),
|
||||
entry( "121", "20.07.2013" )
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldInvokeReverseMapMethodImplementationForMapTypedProperty() {
|
||||
Map<String, String> values = new HashMap<String, String>();
|
||||
values.put( "42", "01.01.1980" );
|
||||
values.put( "121", "20.07.2013" );
|
||||
|
||||
Target target = new Target();
|
||||
target.setValues( values );
|
||||
|
||||
Source source = SourceTargetMapper.INSTANCE.targetToSource( target );
|
||||
|
||||
assertThat( source ).isNotNull();
|
||||
assertThat( source.getValues() ).isNotNull();
|
||||
assertThat( source.getValues() ).hasSize( 2 );
|
||||
assertThat( source.getValues() ).includes(
|
||||
entry( 42L, new GregorianCalendar( 1980, 0, 1 ).getTime() ),
|
||||
entry( 121L, new GregorianCalendar( 2013, 6, 20 ).getTime() )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,35 @@
|
||||
/**
|
||||
* Copyright 2012-2013 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.collection.map;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
public class Source {
|
||||
|
||||
private Map<Long, Date> values;
|
||||
|
||||
public Map<Long, Date> getValues() {
|
||||
return values;
|
||||
}
|
||||
|
||||
public void setValues(Map<Long, Date> values) {
|
||||
this.values = values;
|
||||
}
|
||||
}
|
@ -34,4 +34,8 @@ public interface SourceTargetMapper {
|
||||
Map<String, String> longDateMapToStringStringMap(Map<Long, Date> source);
|
||||
|
||||
Map<Long, Date> stringStringMapToLongDateMap(Map<String, String> source);
|
||||
|
||||
Target sourceToTarget(Source source);
|
||||
|
||||
Source targetToSource(Target target);
|
||||
}
|
||||
|
@ -0,0 +1,34 @@
|
||||
/**
|
||||
* Copyright 2012-2013 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.collection.map;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class Target {
|
||||
|
||||
private Map<String, String> values;
|
||||
|
||||
public Map<String, String> getValues() {
|
||||
return values;
|
||||
}
|
||||
|
||||
public void setValues(Map<String, String> values) {
|
||||
this.values = values;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user