Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
public class LocalDateTimeISO8601XmlAdapter extends XmlAdapter<String, LocalDateTime> {

private static final DateTimeFormatter formatter = new DateTimeFormatterBuilder().appendPattern("yyyy-MM-dd'T'HH:mm:ss")
.optionalStart().appendFraction(ChronoField.MILLI_OF_SECOND, 0, 3, true).optionalEnd()
.optionalStart().appendFraction(ChronoField.NANO_OF_SECOND, 0, 9, true).optionalEnd()
.optionalStart().appendPattern("XXXXX")
.optionalEnd()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
public class LocalTimeISO8601XmlAdapter extends XmlAdapter<String, LocalTime> {

private static final DateTimeFormatter formatter = new DateTimeFormatterBuilder().appendPattern("HH:mm:ss")
.optionalStart().appendFraction(ChronoField.MILLI_OF_SECOND, 0, 3, true).optionalEnd()
.optionalStart().appendFraction(ChronoField.NANO_OF_SECOND, 0, 9, true).optionalEnd()
.optionalStart().appendPattern("XXXXX")
.optionalEnd()

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package org.rutebanken.util;

import org.junit.jupiter.api.Test;

import java.time.LocalDateTime;

import static org.junit.jupiter.api.Assertions.*;

class LocalDateTimeISO8601XmlAdapterTest {

private final LocalDateTimeISO8601XmlAdapter adapter = new LocalDateTimeISO8601XmlAdapter();

@Test
void testUnmarshalBasicDateTime() {
LocalDateTime result = adapter.unmarshal("2026-08-31T00:00:00");
assertEquals(LocalDateTime.of(2026, 8, 31, 0, 0, 0), result);
}

@Test
void testUnmarshalDateTimeWithMilliseconds() {
LocalDateTime result = adapter.unmarshal("2026-05-03T23:30:09.398");
assertEquals(LocalDateTime.of(2026, 5, 3, 23, 30, 9, 398_000_000), result);
}

@Test
void testUnmarshalDateTimeWithOffset() {
LocalDateTime result = adapter.unmarshal("2026-05-03T23:30:09+02:00");
assertEquals(LocalDateTime.of(2026, 5, 3, 23, 30, 9), result);
}

@Test
void testUnmarshalDateTimeWithMicroseconds() {
LocalDateTime result = adapter.unmarshal("2026-05-03T23:30:09.398629");
assertEquals(LocalDateTime.of(2026, 5, 3, 23, 30, 9, 398_629_000), result);
}

@Test
void testUnmarshalDateTimeWithMicrosecondsAndOffset() {
LocalDateTime result = adapter.unmarshal("2026-05-03T23:30:09.398629+02:00");
assertEquals(LocalDateTime.of(2026, 5, 3, 23, 30, 9, 398_629_000), result);
}

@Test
void testUnmarshalDateTimeWithNanoseconds() {
LocalDateTime result = adapter.unmarshal("2026-05-03T23:30:09.123456789+02:00");
assertEquals(LocalDateTime.of(2026, 5, 3, 23, 30, 9, 123_456_789), result);
}

@Test
void testMarshalBasicDateTime() {
String result = adapter.marshal(LocalDateTime.of(2026, 8, 31, 0, 0, 0));
assertEquals("2026-08-31T00:00:00", result);
}

@Test
void testMarshalDateTimeWithMilliseconds() {
String result = adapter.marshal(LocalDateTime.of(2026, 5, 3, 23, 30, 9, 398_000_000));
assertEquals("2026-05-03T23:30:09.398", result);
}

@Test
void testMarshalDateTimeWithMicroseconds() {
String result = adapter.marshal(LocalDateTime.of(2026, 5, 3, 23, 30, 9, 398_629_000));
assertEquals("2026-05-03T23:30:09.398629", result);
}

@Test
void testMarshalNull() {
assertNull(adapter.marshal(null));
}

@Test
void testRoundTripWithMicroseconds() {
LocalDateTime original = LocalDateTime.of(2026, 5, 3, 23, 30, 9, 398_629_000);
assertEquals(original, adapter.unmarshal(adapter.marshal(original)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,24 @@ public void testUnmarshalTimeWithMillisecondsAndOffset() {
assertEquals(LocalTime.of(14, 30, 0, 456_000_000), result);
}

@Test
public void testUnmarshalTimeWithMicroseconds() {
LocalTime result = adapter.unmarshal("07:55:00.398629");
assertEquals(LocalTime.of(7, 55, 0, 398_629_000), result);
}

@Test
public void testUnmarshalTimeWithMicrosecondsAndOffset() {
LocalTime result = adapter.unmarshal("07:55:00.398629+02:00");
assertEquals(LocalTime.of(7, 55, 0, 398_629_000), result);
}

@Test
public void testUnmarshalTimeWithNanoseconds() {
LocalTime result = adapter.unmarshal("07:55:00.123456789+02:00");
assertEquals(LocalTime.of(7, 55, 0, 123_456_789), result);
}

@Test
public void testUnmarshalMidnight() {
LocalTime result = adapter.unmarshal("00:00:00");
Expand Down Expand Up @@ -66,6 +84,12 @@ public void testMarshalTimeWithNanoseconds() {
assertEquals("14:30:00.123", result);
}

@Test
public void testMarshalTimeWithMicroseconds() {
String result = adapter.marshal(LocalTime.of(7, 55, 0, 398_629_000));
assertEquals("07:55:00.398629", result);
}

@Test
public void testMarshalMidnight() {
String result = adapter.marshal(LocalTime.MIDNIGHT);
Expand All @@ -92,6 +116,12 @@ public void testRoundTrip() {
assertEquals(original, unmarshalled);
}

@Test
public void testRoundTripWithMicroseconds() {
LocalTime original = LocalTime.of(7, 55, 0, 398_629_000);
assertEquals(original, adapter.unmarshal(adapter.marshal(original)));
}

@Test
public void testCaching() {
String timeString = "10:20:30";
Expand Down
Loading