Search in sources :

Example 1 with ImmutableInstantHolder

use of org.immutables.criteria.typemodel.ImmutableInstantHolder in project immutables by immutables.

the class JavaTimeTypeTest method instant.

@Test
void instant() {
    InstantHolderRepository repository = new InstantHolderRepository(backend);
    Instant value = Instant.now();
    ImmutableInstantHolder holder = TypeHolder.InstantHolder.generator().get().withValue(value).withOptional(value).withNullable(null);
    repository.insert(holder);
    BsonDocument doc = fetch();
    BsonDateTime expected = new BsonDateTime(value.toEpochMilli());
    check(doc.get("value")).is(expected);
    check(doc.get("optional")).is(expected);
    if (doc.containsKey("nullable")) {
        check(doc.get("nullable")).is(BsonNull.VALUE);
    }
}
Also used : BsonDocument(org.bson.BsonDocument) BsonDateTime(org.bson.BsonDateTime) Instant(java.time.Instant) ImmutableInstantHolder(org.immutables.criteria.typemodel.ImmutableInstantHolder) InstantHolderRepository(org.immutables.criteria.typemodel.InstantHolderRepository) Test(org.junit.jupiter.api.Test)

Aggregations

Instant (java.time.Instant)1 BsonDateTime (org.bson.BsonDateTime)1 BsonDocument (org.bson.BsonDocument)1 ImmutableInstantHolder (org.immutables.criteria.typemodel.ImmutableInstantHolder)1 InstantHolderRepository (org.immutables.criteria.typemodel.InstantHolderRepository)1 Test (org.junit.jupiter.api.Test)1