Added tests for serializing cells containing dates and numbers

This commit is contained in:
Owen Stephens 2019-04-04 23:00:56 +01:00
parent 318bb54185
commit 81a82499b5

View File

@ -26,6 +26,10 @@
******************************************************************************/ ******************************************************************************/
package com.google.refine.tests.model; package com.google.refine.tests.model;
import java.time.format.DateTimeFormatter;
import java.time.LocalDateTime;
import java.time.OffsetDateTime;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@ -109,4 +113,52 @@ public class CellTests {
Cell c = Cell.loadStreaming(json, pool); Cell c = Cell.loadStreaming(json, pool);
TestUtils.isSerializedTo(c, json); TestUtils.isSerializedTo(c, json);
} }
@Test
public void serializeDatewithOffset() throws Exception {
OffsetDateTime dateTimeValue = OffsetDateTime.parse("2017-05-12T05:45:00+01:00", DateTimeFormatter.ISO_OFFSET_DATE_TIME);
Cell c = new Cell(dateTimeValue, null);
String json = "{\"v\":\"2017-05-12T04:45:00Z\",\"t\":\"date\"}";
TestUtils.isSerializedTo(c, json);
}
@Test
public void serializeLocalDate() throws Exception {
LocalDateTime dateTimeValue = LocalDateTime.of(2017,5,12,0,0,0);
Cell c = new Cell(dateTimeValue, null);
String json = "{\"v\":\"2017-05-12T00:00:00Z\",\"t\":\"date\"}";
TestUtils.isSerializedTo(c, json);
}
@Test
public void serializeDoubleNan() throws Exception {
double dn = Double.NaN;
Cell c = new Cell(dn, null);
String json = "{\"v\":\"NaN\"}";
TestUtils.isSerializedTo(c, json);
}
@Test
public void serializeFloatNan() throws Exception {
Float fn = Float.NaN;
Cell c = new Cell(fn, null);
String json = "{\"v\":\"NaN\"}";
TestUtils.isSerializedTo(c, json);
}
@Test
public void serializeDoubleInfinity() throws Exception {
double di = Double.POSITIVE_INFINITY;
Cell c = new Cell(di, null);
String json = "{\"v\":\"Infinity\"}";
TestUtils.isSerializedTo(c, json);
}
@Test
public void serializeFloatInfinity() throws Exception {
Float fi = Float.POSITIVE_INFINITY;
Cell c = new Cell(fi, null);
String json = "{\"v\":\"Infinity\"}";
TestUtils.isSerializedTo(c, json);
}
} }