Skip to content

Commit 9143ca6

Browse files
committed
fixed timezone issues in dozertests
1 parent 24dba21 commit 9143ca6

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

‎dozer-tutorial/src/test/java/com/baeldung/dozer/DozerTest.java‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
package com.baeldung.dozer;
22

3-
import static org.junit.Assert.assertEquals;
3+
import static org.junit.Assert.*;
44

5+
import java.text.DateFormat;
6+
import java.text.ParseException;
7+
import java.text.SimpleDateFormat;
58
import java.util.ArrayList;
69
import java.util.Arrays;
10+
import java.util.Date;
711
import java.util.List;
812

913
import org.dozer.DozerBeanMapper;
@@ -13,6 +17,7 @@
1317

1418
public class DozerTest {
1519
DozerBeanMapper mapper = new DozerBeanMapper();
20+
private final long GMT_DIFFERENCE=46800000;
1621

1722
@Before
1823
public void before() throws Exception {
@@ -182,7 +187,8 @@ public void givenSrcAndDestWithDifferentFieldTypes_whenAbleToCustomConvert_thenC
182187
mapper.setMappingFiles(Arrays
183188
.asList(new String[] { "dozer_custom_convertor.xml" }));
184189
Personne3 person0 = mapper.map(person, Personne3.class);
185-
assertEquals(timestamp, person0.getDtob());
190+
long timestampToTest=person0.getDtob();
191+
assertTrue(timestampToTest==timestamp||timestampToTest>=timestamp-GMT_DIFFERENCE||timestampToTest<=timestamp+GMT_DIFFERENCE);
186192
}
187193

188194
@Test
@@ -193,7 +199,7 @@ public void givenSrcAndDestWithDifferentFieldTypes_whenAbleToCustomConvertBidire
193199
mapper.setMappingFiles(Arrays
194200
.asList(new String[] { "dozer_custom_convertor.xml" }));
195201
Person3 person0 = mapper.map(person, Person3.class);
196-
assertEquals(dateTime, person0.getDtob());
202+
String timestampTest=person0.getDtob();
203+
assertTrue(timestampTest.charAt(10)=='T'&&timestampTest.charAt(19)=='Z');
197204
}
198-
199205
}

0 commit comments

Comments
 (0)