Sha256: d5916ef3acf7a7b75277b1c19fe81f5404013feb3bfefcb0a417f2b0e9009eff

Contents?: true

Size: 1.56 KB

Versions: 2

Compression:

Stored size: 1.56 KB

Contents

package org.embulk.filter.typecast.cast;

import org.embulk.EmbulkTestRuntime;
import org.embulk.spi.DataException;
import org.embulk.spi.time.Timestamp;
import org.embulk.spi.time.TimestampFormatter;
import org.joda.time.DateTimeZone;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class TestTimestampCast
{
    @Rule
    public EmbulkTestRuntime runtime = new EmbulkTestRuntime();
    public Timestamp timestamp;

    @Before
    public void createResource()
    {
        timestamp = Timestamp.ofEpochSecond(1463084053, 500000000);
    }

    @Test(expected = DataException.class)
    public void asBoolean()
    {
        TimestampCast.asBoolean(timestamp);
    }

    @Test
    public void asLong()
    {
        assertEquals(timestamp.getEpochSecond(), TimestampCast.asLong(timestamp));
    }

    @Test
    public void asDouble()
    {
        double unixtimestamp = timestamp.getEpochSecond() + timestamp.getNano() / 1000000000.0;
        assertEquals(unixtimestamp, TimestampCast.asDouble(timestamp), 0.0);
    }

    @Test
    public void asString()
    {
        TimestampFormatter formatter = new TimestampFormatter("%Y-%m-%d %H:%M:%S.%6N", DateTimeZone.UTC);
        assertEquals("2016-05-12 20:14:13.500000", TimestampCast.asString(timestamp, formatter));
    }

    @Test(expected = DataException.class)
    public void asJson()
    {
        TimestampCast.asJson(timestamp);
    }

    @Test
    public void asTimestamp()
    {
        assertEquals(timestamp, TimestampCast.asTimestamp(timestamp));
    }
}

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
embulk-filter-typecast-0.2.2 src/test/java/org/embulk/filter/typecast/cast/TestTimestampCast.java
embulk-filter-typecast-0.2.1 src/test/java/org/embulk/filter/typecast/cast/TestTimestampCast.java