Package nz.net.ultraq.jaxb.tests.adapters

Source Code of nz.net.ultraq.jaxb.tests.adapters.XMLLocalDateAdapterTest

package nz.net.ultraq.jaxb.tests.adapters;

import nz.net.ultraq.jaxb.adapters.XMLLocalDateAdapter;

import org.joda.time.LocalDate;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

/**
* Tests for the Joda LocalDate / XML Date adapter.
*
* @author <a href="mailto:david@davidkarlsen.com">David J. M. Karlsen<a>
*/
public class XMLLocalDateAdapterTest
{
    private XMLLocalDateAdapter xmlLocalDateAdapter;
   
    @Before
    public void before() {
        this.xmlLocalDateAdapter = new XMLLocalDateAdapter();
    }
   
    @Test
    public void testMarshalDate() {
        LocalDate localDate = new LocalDate().withYear( 2013 ).withMonthOfYear( 8 ).withDayOfMonth( 21 );
        String marshalledValue = xmlLocalDateAdapter.marshal( localDate );
        Assert.assertEquals( "2013-08-21", marshalledValue );
    }
   
    @Test
    public void testMarshalNull() {
        String marshalledValue = xmlLocalDateAdapter.marshal( null );
        Assert.assertNull( marshalledValue );
    }
   
    @Test
    public void testUnmarshalNull() {
        LocalDate unmarshalledValue = xmlLocalDateAdapter.unmarshal( null );
        Assert.assertNull( unmarshalledValue );
    }
   
    @Test
    public void testUnmarshalNoTz() {
        String dateString = "2013-08-21";
        LocalDate localDate = xmlLocalDateAdapter.unmarshal( dateString );
        LocalDate expectedDate = new LocalDate().withYear( 2013 ).withMonthOfYear( 8 ).withDayOfMonth( 21 );
        Assert.assertEquals( expectedDate, localDate );
    }
   
    @Test
    public void testUnmarshalWithZone() {
        String dateString = "2013-08-21+06:00";
        LocalDate localDate = xmlLocalDateAdapter.unmarshal( dateString );
        LocalDate expectedDate = new LocalDate().withYear( 2013 ).withMonthOfYear( 8 ).withDayOfMonth( 21 );
        Assert.assertEquals( expectedDate, localDate );
    }
   
    @Test
    public void testUnmarshalUTC() {
        String dateString = "2013-08-21Z";
        LocalDate localDate = xmlLocalDateAdapter.unmarshal( dateString );
        LocalDate expectedDate = new LocalDate().withYear( 2013 ).withMonthOfYear( 8 ).withDayOfMonth( 21 );
        Assert.assertEquals( expectedDate, localDate );
    }
}
TOP

Related Classes of nz.net.ultraq.jaxb.tests.adapters.XMLLocalDateAdapterTest

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.