Search in sources :

Example 96 with ProcessorTest

use of org.mapstruct.ap.testutil.ProcessorTest in project mapstruct by mapstruct.

the class LocalDateToXMLGregorianCalendarConversionTest method shouldNullCheckOnBuiltinAndConversion.

@ProcessorTest
public void shouldNullCheckOnBuiltinAndConversion() {
    Target target = SourceTargetMapper.INSTANCE.toTarget(new Source());
    assertThat(target).isNotNull();
    assertThat(target.getDate()).isNull();
    Source source = SourceTargetMapper.INSTANCE.toSource(new Target());
    assertThat(source).isNotNull();
    assertThat(source.getDate()).isNull();
}
Also used : Target(org.mapstruct.ap.test.conversion.java8time.localdatetoxmlgregoriancalendarconversion.Target) Source(org.mapstruct.ap.test.conversion.java8time.localdatetoxmlgregoriancalendarconversion.Source) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 97 with ProcessorTest

use of org.mapstruct.ap.testutil.ProcessorTest in project mapstruct by mapstruct.

the class LocalDateToXMLGregorianCalendarConversionTest method shouldMapCorrectlyOnBuiltinAndConversion.

@ProcessorTest
public void shouldMapCorrectlyOnBuiltinAndConversion() throws Exception {
    XMLGregorianCalendar calendarDate = DatatypeFactory.newInstance().newXMLGregorianCalendarDate(2007, 11, 14, DatatypeConstants.FIELD_UNDEFINED);
    LocalDate localDate = LocalDate.of(2007, 11, 14);
    Source s1 = new Source();
    s1.setDate(calendarDate);
    Target target = SourceTargetMapper.INSTANCE.toTarget(s1);
    assertThat(target).isNotNull();
    assertThat(target.getDate()).isEqualTo(localDate);
    Target t1 = new Target();
    t1.setDate(localDate);
    Source source = SourceTargetMapper.INSTANCE.toSource(t1);
    assertThat(source).isNotNull();
    assertThat(source.getDate()).isEqualTo(calendarDate);
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) Target(org.mapstruct.ap.test.conversion.java8time.localdatetoxmlgregoriancalendarconversion.Target) LocalDate(java.time.LocalDate) Source(org.mapstruct.ap.test.conversion.java8time.localdatetoxmlgregoriancalendarconversion.Source) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 98 with ProcessorTest

use of org.mapstruct.ap.testutil.ProcessorTest in project mapstruct by mapstruct.

the class DateConversionTest method shouldApplyDateToSqlConversion.

@IssueKey("858")
@ProcessorTest
public void shouldApplyDateToSqlConversion() {
    GregorianCalendar time = new GregorianCalendar(2016, Calendar.AUGUST, 24, 20, 30, 30);
    GregorianCalendar sqlDate = new GregorianCalendar(2016, Calendar.AUGUST, 23, 21, 35, 35);
    GregorianCalendar timestamp = new GregorianCalendar(2016, Calendar.AUGUST, 22, 21, 35, 35);
    Source source = new Source();
    source.setTime(time.getTime());
    source.setSqlDate(sqlDate.getTime());
    source.setTimestamp(timestamp.getTime());
    Target target = SourceTargetMapper.INSTANCE.sourceToTarget(source);
    Time expectedTime = new Time(time.getTime().getTime());
    java.sql.Date expectedSqlDate = new java.sql.Date(sqlDate.getTime().getTime());
    Timestamp expectedTimestamp = new Timestamp(timestamp.getTime().getTime());
    assertThat(target.getTime()).isEqualTo(expectedTime);
    assertThat(target.getSqlDate()).isEqualTo(expectedSqlDate);
    assertThat(target.getTimestamp()).isEqualTo(expectedTimestamp);
}
Also used : GregorianCalendar(java.util.GregorianCalendar) Time(java.sql.Time) Timestamp(java.sql.Timestamp) Date(java.util.Date) IssueKey(org.mapstruct.ap.testutil.IssueKey) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 99 with ProcessorTest

use of org.mapstruct.ap.testutil.ProcessorTest in project mapstruct by mapstruct.

the class DateConversionTest method shouldApplySqlToDateConversion.

@IssueKey("858")
@ProcessorTest
public void shouldApplySqlToDateConversion() {
    Target target = new Target();
    GregorianCalendar time = new GregorianCalendar(2016, Calendar.AUGUST, 24, 20, 30, 30);
    GregorianCalendar sqlDate = new GregorianCalendar(2016, Calendar.AUGUST, 23, 21, 35, 35);
    GregorianCalendar timestamp = new GregorianCalendar(2016, Calendar.AUGUST, 22, 21, 35, 35);
    target.setTime(new Time(time.getTime().getTime()));
    target.setSqlDate(new java.sql.Date(sqlDate.getTime().getTime()));
    target.setTimestamp(new Timestamp(timestamp.getTime().getTime()));
    Source source = SourceTargetMapper.INSTANCE.targetToSource(target);
    assertThat(source).isNotNull();
    assertThat(source.getTime()).isEqualTo(target.getTime());
    assertThat(source.getSqlDate()).isEqualTo(target.getSqlDate());
    assertThat(source.getTimestamp()).isEqualTo(target.getTimestamp());
}
Also used : GregorianCalendar(java.util.GregorianCalendar) Time(java.sql.Time) Timestamp(java.sql.Timestamp) IssueKey(org.mapstruct.ap.testutil.IssueKey) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 100 with ProcessorTest

use of org.mapstruct.ap.testutil.ProcessorTest in project mapstruct by mapstruct.

the class DateConversionTest method shouldApplyStringConversionForReverseArrayArrayMethod.

@ProcessorTest
public void shouldApplyStringConversionForReverseArrayArrayMethod() {
    Date[] dates = new Date[] { new GregorianCalendar(2013, Calendar.JULY, 6).getTime(), new GregorianCalendar(2013, Calendar.FEBRUARY, 14).getTime(), new GregorianCalendar(2013, Calendar.APRIL, 11).getTime() };
    String[] stringDates = SourceTargetMapper.INSTANCE.dateArrayToStringArray(dates);
    assertThat(stringDates).isNotNull();
    assertThat(stringDates).isEqualTo(new String[] { "06.07.2013", "14.02.2013", "11.04.2013" });
}
Also used : GregorianCalendar(java.util.GregorianCalendar) Date(java.util.Date) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Aggregations

ProcessorTest (org.mapstruct.ap.testutil.ProcessorTest)314 WithClasses (org.mapstruct.ap.testutil.WithClasses)118 GeneratedSource (org.mapstruct.ap.testutil.runner.GeneratedSource)51 IssueKey (org.mapstruct.ap.testutil.IssueKey)39 XmlGregorianCalendarBean (org.mapstruct.ap.test.builtin.jodatime.bean.XmlGregorianCalendarBean)24 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)22 Date (java.util.Date)16 LocalDateTimeBean (org.mapstruct.ap.test.builtin.jodatime.bean.LocalDateTimeBean)16 Calendar (java.util.Calendar)13 LocalDateTime (org.joda.time.LocalDateTime)13 CarDto (org.mapstruct.ap.test.complex._target.CarDto)13 Car (org.mapstruct.ap.test.complex.source.Car)13 PersonDto (org.mapstruct.ap.test.constructor.PersonDto)13 GregorianCalendar (java.util.GregorianCalendar)12 XmlGregorianCalendarProperty (org.mapstruct.ap.test.builtin.bean.XmlGregorianCalendarProperty)12 Song (org.mapstruct.ap.test.nestedsourceproperties.source.Song)12 BigDecimal (java.math.BigDecimal)11 ChartEntry (org.mapstruct.ap.test.nestedsourceproperties._target.ChartEntry)11 DriverAndCarDto (org.mapstruct.ap.test.nullvaluemapping._target.DriverAndCarDto)11 DateTime (org.joda.time.DateTime)10