package org.tukia.worldcup;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import static org.testng.Assert.*;
public class ZonedDateTimeAdapterTest {
private static final String DATE_AS_STRING = "2014-06-13T16:00:00.000-03:00";
private ZonedDateTimeAdapter adapter;
@BeforeMethod
public void setUp() throws Exception {
adapter = new ZonedDateTimeAdapter();
}
@Test
public void unmarshalProducesCorrectLocalDateTimeObject() throws Exception {
final ZonedDateTime unmarshaled = adapter.unmarshal(DATE_AS_STRING);
assertEquals(unmarshaled.format(getDateTimeFormatter()), DATE_AS_STRING);
}
@Test
public void marshalProducesCorrectDateTimeString() throws Exception {
final String marshal = adapter.marshal(ZonedDateTime.parse(DATE_AS_STRING, getDateTimeFormatter()));
assertEquals(marshal, DATE_AS_STRING);
}
private DateTimeFormatter getDateTimeFormatter() {
return DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ");
}
}