Package org.tukia.worldcup

Source Code of org.tukia.worldcup.ZonedDateTimeAdapterTest

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");
    }
}
TOP

Related Classes of org.tukia.worldcup.ZonedDateTimeAdapterTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.