Skip to content

Commit c70a97e

Browse files
committed
Additional tests
1 parent f61fe2f commit c70a97e

File tree

4 files changed

+61
-3
lines changed

4 files changed

+61
-3
lines changed

remoting/rico-remoting-common/src/main/java/dev/rico/internal/remoting/RemotingConstants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ public interface RemotingConstants {
3333

3434
String INTERNAL_ATTRIBUTES_BEAN_NAME = "@@@ HIGHLANDER_BEAN @@@";
3535

36-
String REMOTING_DATE_FORMAT_PATTERN = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
36+
String REMOTING_DATE_FORMAT_PATTERN = "yyyy-MM-dd'T'HH:mm:ss.SSSXXX";
3737

3838
}

remoting/rico-remoting-common/src/test/java/dev/rico/internal/remoting/converters/LocalDateConverterTest.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.testng.Assert;
2222
import org.testng.annotations.Test;
2323

24+
import java.text.ParseException;
2425
import java.time.LocalDate;
2526
import java.time.LocalDateTime;
2627
import java.time.LocalTime;
@@ -66,6 +67,7 @@ public void testSameTimeZone() throws ValueConverterException {
6667

6768
//when
6869
final Object rawObject = converter.convertToRemoting(time);
70+
System.out.println(rawObject);
6971
final Object reConverted = converter.convertFromRemoting(rawObject);
7072

7173
//then
@@ -107,4 +109,32 @@ public void testDifferentTimeZone() throws ValueConverterException {
107109
}
108110
}
109111

112+
@Test
113+
public void testRawSameTimeZone() throws ValueConverterException, ParseException {
114+
final TimeZone defaultZone = TimeZone.getDefault();
115+
try {
116+
117+
//given
118+
final LocalDateConverterFactory localDateFactory = new LocalDateConverterFactory();
119+
final Converter localDateConverter = localDateFactory.getConverterForType(LocalDate.class);
120+
final ZonedDateTimeConverterFactory zonedDateTimeFactory = new ZonedDateTimeConverterFactory();
121+
final Converter zonedDateTimeConverter = zonedDateTimeFactory.getConverterForType(LocalDate.class);
122+
final String rawObject = "2019-01-30T11:25:07.341+03:00";
123+
final ZonedDateTime zonedDateTime = (ZonedDateTime) zonedDateTimeConverter.convertFromRemoting(rawObject);
124+
final LocalDate fromZonedTime = LocalDate.from(zonedDateTime);
125+
126+
//when
127+
final Object reconvertedLocalDate = localDateConverter.convertFromRemoting(rawObject);
128+
129+
//then
130+
Assert.assertNotNull(reconvertedLocalDate);
131+
Assert.assertTrue(LocalDate.class.isAssignableFrom(reconvertedLocalDate.getClass()));
132+
final LocalDate reconvertedTime = (LocalDate) reconvertedLocalDate;
133+
Assert.assertEquals(reconvertedTime, fromZonedTime);
134+
135+
} finally {
136+
TimeZone.setDefault(defaultZone);
137+
}
138+
}
139+
110140
}

remoting/rico-remoting-common/src/test/java/dev/rico/internal/remoting/converters/LocalDateTimeConverterTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public void testSameTimeZone() throws ValueConverterException {
7676
Assert.assertEquals(reconvertedTime, time);
7777
}
7878

79-
@Test(enabled = false)
79+
@Test
8080
public void testDifferentTimeZone() throws ValueConverterException {
8181
final TimeZone defaultZone = TimeZone.getDefault();
8282
try {

remoting/rico-remoting-common/src/test/java/dev/rico/internal/remoting/converters/ZonedDateTimeConverterTest.java

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,13 @@
2121
import org.testng.Assert;
2222
import org.testng.annotations.Test;
2323

24+
import java.text.ParseException;
25+
import java.time.LocalDate;
2426
import java.time.LocalDateTime;
2527
import java.time.ZoneId;
2628
import java.time.ZonedDateTime;
2729
import java.util.Objects;
30+
import java.util.TimeZone;
2831

2932
public class ZonedDateTimeConverterTest {
3033

@@ -71,7 +74,7 @@ public void testSameTimeZone() throws ValueConverterException {
7174
Assert.assertEquals(reconvertedTime, time);
7275
}
7376

74-
@Test(enabled = false)
77+
@Test
7578
public void testDifferentTimeZone() throws ValueConverterException {
7679
//given
7780
final ZonedDateTimeConverterFactory factory = new ZonedDateTimeConverterFactory();
@@ -86,6 +89,7 @@ public void testDifferentTimeZone() throws ValueConverterException {
8689

8790
//when
8891
final Object rawObject = converter.convertToRemoting(time);
92+
System.out.println(rawObject);
8993
final Object reConverted = converter.convertFromRemoting(rawObject);
9094

9195
//then
@@ -96,4 +100,28 @@ public void testDifferentTimeZone() throws ValueConverterException {
96100
Assert.assertEquals(reconvertedTime, time);
97101
}
98102

103+
@Test
104+
public void testRawSameTimeZone() throws ValueConverterException, ParseException {
105+
final TimeZone defaultZone = TimeZone.getDefault();
106+
try {
107+
108+
//given
109+
final ZonedDateTimeConverterFactory zonedDateTimeFactory = new ZonedDateTimeConverterFactory();
110+
final Converter zonedDateTimeConverter = zonedDateTimeFactory.getConverterForType(LocalDate.class);
111+
final String rawObject = "2019-01-30T11:25:07.341+08:00";
112+
113+
//when
114+
final Object reconverted = zonedDateTimeConverter.convertFromRemoting(rawObject);
115+
116+
//then
117+
Assert.assertNotNull(reconverted);
118+
Assert.assertTrue(ZonedDateTime.class.isAssignableFrom(reconverted.getClass()));
119+
final ZonedDateTime reconvertedTime = (ZonedDateTime) reconverted;
120+
Assert.assertEquals(ZoneId.of("Australia/Sydney"), reconvertedTime.getZone());
121+
122+
} finally {
123+
TimeZone.setDefault(defaultZone);
124+
}
125+
}
126+
99127
}

0 commit comments

Comments
 (0)