use of java.time.Instant in project dropwizard by dropwizard.
the class OffsetDateTimeMapperTest method mapColumnByName.
@Test
public void mapColumnByName() throws Exception {
final Instant now = OffsetDateTime.now().toInstant();
when(resultSet.getTimestamp("name")).thenReturn(Timestamp.from(now));
OffsetDateTime actual = new OffsetDateTimeMapper().mapColumn(resultSet, "name", null);
assertThat(actual).isEqualTo(OffsetDateTime.ofInstant(now, ZoneId.systemDefault()));
}
use of java.time.Instant in project dropwizard by dropwizard.
the class GuavaOptionalInstantTest method testPresent.
@Test
public void testPresent() {
final Instant startDate = Instant.now();
final Instant endDate = startDate.plus(1L, ChronoUnit.DAYS);
dao.insert(1, Optional.of("John Hughes"), startDate, Optional.of(endDate), Optional.absent());
assertThat(dao.findEndDateById(1).get()).isEqualTo(endDate);
}
use of java.time.Instant in project vert.x by eclipse.
the class JsonArrayTest method testGetValue.
@Test
public void testGetValue() {
jsonArray.add(123);
assertEquals(123, jsonArray.getValue(0));
jsonArray.add(123l);
assertEquals(123l, jsonArray.getValue(1));
jsonArray.add(123f);
assertEquals(123f, jsonArray.getValue(2));
jsonArray.add(123d);
assertEquals(123d, jsonArray.getValue(3));
jsonArray.add(false);
assertEquals(false, jsonArray.getValue(4));
jsonArray.add(true);
assertEquals(true, jsonArray.getValue(5));
jsonArray.add("bar");
assertEquals("bar", jsonArray.getValue(6));
JsonObject obj = new JsonObject().put("blah", "wibble");
jsonArray.add(obj);
assertEquals(obj, jsonArray.getValue(7));
JsonArray arr = new JsonArray().add("blah").add("wibble");
jsonArray.add(arr);
assertEquals(arr, jsonArray.getValue(8));
byte[] bytes = TestUtils.randomByteArray(100);
jsonArray.add(bytes);
assertTrue(TestUtils.byteArraysEqual(bytes, Base64.getDecoder().decode((String) jsonArray.getValue(9))));
Instant now = Instant.now();
jsonArray.add(now);
assertEquals(now, jsonArray.getInstant(10));
jsonArray.addNull();
assertNull(jsonArray.getValue(11));
try {
jsonArray.getValue(-1);
fail();
} catch (IndexOutOfBoundsException e) {
// OK
}
try {
jsonArray.getValue(12);
fail();
} catch (IndexOutOfBoundsException e) {
// OK
}
// JsonObject with inner Map
List<Object> list = new ArrayList<>();
Map<String, Object> innerMap = new HashMap<>();
innerMap.put("blah", "wibble");
list.add(innerMap);
jsonArray = new JsonArray(list);
obj = (JsonObject) jsonArray.getValue(0);
assertEquals("wibble", obj.getString("blah"));
// JsonObject with inner List
list = new ArrayList<>();
List<Object> innerList = new ArrayList<>();
innerList.add("blah");
list.add(innerList);
jsonArray = new JsonArray(list);
arr = (JsonArray) jsonArray.getValue(0);
assertEquals("blah", arr.getString(0));
}
use of java.time.Instant in project vert.x by eclipse.
the class JsonObjectTest method testDecode.
@Test
public void testDecode() throws Exception {
byte[] bytes = TestUtils.randomByteArray(10);
String strBytes = Base64.getEncoder().encodeToString(bytes);
Instant now = Instant.now();
String strInstant = ISO_INSTANT.format(now);
String json = "{\"mystr\":\"foo\",\"myint\":123,\"mylong\":1234,\"myfloat\":1.23,\"mydouble\":2.34,\"" + "myboolean\":true,\"mybinary\":\"" + strBytes + "\",\"myinstant\":\"" + strInstant + "\",\"mynull\":null,\"myobj\":{\"foo\":\"bar\"},\"myarr\":[\"foo\",123]}";
JsonObject obj = new JsonObject(json);
assertEquals(json, obj.encode());
assertEquals("foo", obj.getString("mystr"));
assertEquals(Integer.valueOf(123), obj.getInteger("myint"));
assertEquals(Long.valueOf(1234), obj.getLong("mylong"));
assertEquals(Float.valueOf(1.23f), obj.getFloat("myfloat"));
assertEquals(Double.valueOf(2.34d), obj.getDouble("mydouble"));
assertTrue(obj.getBoolean("myboolean"));
assertTrue(TestUtils.byteArraysEqual(bytes, obj.getBinary("mybinary")));
assertEquals(now, obj.getInstant("myinstant"));
assertTrue(obj.containsKey("mynull"));
JsonObject nestedObj = obj.getJsonObject("myobj");
assertEquals("bar", nestedObj.getString("foo"));
JsonArray nestedArr = obj.getJsonArray("myarr");
assertEquals("foo", nestedArr.getString(0));
assertEquals(Integer.valueOf(123), Integer.valueOf(nestedArr.getInteger(1)));
}
use of java.time.Instant in project vert.x by eclipse.
the class JsonObjectTest method testPutInstant.
@Test
public void testPutInstant() {
Instant bin1 = Instant.now();
Instant bin2 = bin1.plus(1, ChronoUnit.DAYS);
Instant bin3 = bin1.plus(1, ChronoUnit.MINUTES);
assertSame(jsonObject, jsonObject.put("foo", bin1));
assertEquals(bin1, jsonObject.getInstant("foo"));
jsonObject.put("quux", bin2);
assertEquals(bin2, jsonObject.getInstant("quux"));
assertEquals(bin1, jsonObject.getInstant("foo"));
jsonObject.put("foo", bin3);
assertEquals(bin3, jsonObject.getInstant("foo"));
jsonObject.put("foo", (Instant) null);
assertTrue(jsonObject.containsKey("foo"));
try {
jsonObject.put(null, bin1);
fail();
} catch (NullPointerException e) {
// OK
}
}
Aggregations