mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#198 adding unit test for type conversion
This commit is contained in:
parent
51e33cb343
commit
f58b26b519
@ -18,6 +18,7 @@
|
||||
*/
|
||||
package org.mapstruct.ap.test.exceptions;
|
||||
|
||||
import java.text.ParseException;
|
||||
import org.mapstruct.ap.test.exceptions.imports.TestException1;
|
||||
import org.mapstruct.ap.test.exceptions.imports.TestExceptionBase;
|
||||
import java.util.ArrayList;
|
||||
@ -48,7 +49,7 @@ public class ExceptionTest {
|
||||
|
||||
@Test( expected = RuntimeException.class )
|
||||
@IssueKey( "198" )
|
||||
public void shouldThrowRuntimeInBeanMapping() throws TestException2 {
|
||||
public void shouldThrowRuntimeInBeanMapping() throws TestException2, ParseException {
|
||||
Source source = new Source();
|
||||
source.setSize( 1 );
|
||||
SourceTargetMapper sourceTargetMapper = SourceTargetMapper.INSTANCE;
|
||||
@ -57,13 +58,22 @@ public class ExceptionTest {
|
||||
|
||||
@Test( expected = TestException2.class )
|
||||
@IssueKey( "198" )
|
||||
public void shouldThrowTestException2InBeanMapping() throws TestException2 {
|
||||
public void shouldThrowTestException2InBeanMapping() throws TestException2, ParseException {
|
||||
Source source = new Source();
|
||||
source.setSize( 2 );
|
||||
SourceTargetMapper sourceTargetMapper = SourceTargetMapper.INSTANCE;
|
||||
sourceTargetMapper.sourceToTarget( source );
|
||||
}
|
||||
|
||||
@Test( expected = ParseException.class )
|
||||
@IssueKey( "198" )
|
||||
public void shouldThrowTestParseExceptionInBeanMappingDueToTypeConverion() throws TestException2, ParseException {
|
||||
Source source = new Source();
|
||||
source.setDate( "nonsense" );
|
||||
SourceTargetMapper sourceTargetMapper = SourceTargetMapper.INSTANCE;
|
||||
sourceTargetMapper.sourceToTarget( source );
|
||||
}
|
||||
|
||||
@Test( expected = RuntimeException.class )
|
||||
@IssueKey( "198" )
|
||||
public void shouldThrowRuntimeInIterableMapping() throws TestException2 {
|
||||
|
@ -25,6 +25,7 @@ package org.mapstruct.ap.test.exceptions;
|
||||
public class Source {
|
||||
|
||||
private int size;
|
||||
private String date;
|
||||
|
||||
public int getSize() {
|
||||
return size;
|
||||
@ -33,4 +34,13 @@ public class Source {
|
||||
public void setSize( int size ) {
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
public String getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
public void setDate( String date ) {
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
package org.mapstruct.ap.test.exceptions;
|
||||
|
||||
|
||||
import java.text.ParseException;
|
||||
import org.mapstruct.ap.test.exceptions.imports.TestExceptionBase;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -36,7 +37,7 @@ public interface SourceTargetMapper {
|
||||
|
||||
SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class );
|
||||
|
||||
Target sourceToTarget(Source source) throws TestException2;
|
||||
Target sourceToTarget(Source source) throws TestException2, ParseException;
|
||||
|
||||
List<Long> integerListToLongList(List<Integer> sizes) throws TestException2;
|
||||
|
||||
|
@ -18,6 +18,8 @@
|
||||
*/
|
||||
package org.mapstruct.ap.test.exceptions;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sjaak Derksen
|
||||
@ -25,6 +27,7 @@ package org.mapstruct.ap.test.exceptions;
|
||||
public class Target {
|
||||
|
||||
private Long size;
|
||||
private Date date;
|
||||
|
||||
public Long getSize() {
|
||||
return size;
|
||||
@ -34,4 +37,12 @@ public class Target {
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
public Date getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
public void setDate( Date date ) {
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user