-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7cd8661
commit 6e47063
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
..._Service/src/test/java/org/robbins/flashcards/service/util/dozer/DateTimeConverterUT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package org.robbins.flashcards.service.util.dozer; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.core.IsNull.nullValue; | ||
import static org.junit.Assert.assertThat; | ||
|
||
import java.util.Calendar; | ||
import java.util.Date; | ||
|
||
import org.joda.time.DateTime; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.experimental.categories.Category; | ||
import org.robbins.tests.BaseMockingTest; | ||
import org.robbins.tests.UnitTest; | ||
|
||
@Category(UnitTest.class) | ||
public class DateTimeConverterUT extends BaseMockingTest { | ||
|
||
DateTimeConverter dateTimeConverter; | ||
|
||
@Before | ||
public void before() { | ||
dateTimeConverter = new DateTimeConverter(); | ||
} | ||
|
||
@Test | ||
public void convert_SourceFieldValueIsNull() { | ||
Object result = dateTimeConverter.convert(null, null, null, null); | ||
|
||
assertThat(result, is(nullValue())); | ||
} | ||
|
||
@Test | ||
public void convert_SourceFromDate() { | ||
Calendar cal = Calendar.getInstance(); | ||
cal.set(Calendar.YEAR, 1988); | ||
cal.set(Calendar.MONTH, 1); | ||
cal.set(Calendar.DAY_OF_MONTH, 1); | ||
|
||
Date sourceFieldValue = cal.getTime(); | ||
Object result = dateTimeConverter.convert(null, sourceFieldValue, DateTime.class, Date.class); | ||
|
||
assertThat(result, is(DateTime.class)); | ||
assertThat(((DateTime)result).toDate(), is(cal.getTime())); | ||
} | ||
|
||
@Test | ||
public void convert_SourceFromDateTime() { | ||
DateTime sourceFieldValue = new DateTime(); | ||
Object result = dateTimeConverter.convert(null, sourceFieldValue, DateTime.class, Date.class); | ||
|
||
assertThat(result, is(Date.class)); | ||
assertThat(((Date)result), is(sourceFieldValue.toDate())); | ||
} | ||
} |