/*
 * Copyright (c) eHealth
 */
package be.ehealth.technicalconnector.adapter;

import org.junit.Assert;
import org.junit.Test;

import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;


/**
 * Unit test for {@link XmlTimeAdapter}
 *
 * @author Olivier Chapuis (eh077))
 */
public class XmlTimeAdapterTest {

    @Test
    public void testParseTimeWithMilliseconds() throws Exception {
        Instant instant = new XmlTimeAdapter().unmarshal("15:15:57.270+02:00");
        ZonedDateTime parsedTime = instant.atZone(ZoneId.of("+02:00"));
        Assert.assertEquals(15, parsedTime.getHour());
        Assert.assertEquals(47757270L, instant.toEpochMilli());
        Assert.assertEquals(15, parsedTime.getMinute());
        Assert.assertEquals(57, parsedTime.getSecond());
        Assert.assertEquals(270, parsedTime.getNano()/ 1_000_000);

    }

    @Test
    public void testParseTimeWithMilliseconds2() throws Exception {
        Instant instant = new XmlTimeAdapter().unmarshal("15:15:57.2757953248+02:00");
        ZonedDateTime parsedTime = instant.atZone(ZoneId.of("+02:00"));
        Assert.assertEquals(15, parsedTime.getHour());
        Assert.assertEquals(47757275L, instant.toEpochMilli());
        Assert.assertEquals(15, parsedTime.getMinute());
        Assert.assertEquals(57, parsedTime.getSecond());
        Assert.assertEquals(275, parsedTime.getNano()/ 1_000_000);

    }

    @Test
    public void testPrintTimeNull() throws Exception {
        Assert.assertNull(new XmlTimeAdapter().marshal(null));
    }
}
