Search in sources :

Example 1 with LocalDateHolderRepository

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

the class JavaTimeTypeTest method localDate.

@Test
void localDate() {
    LocalDateHolderRepository repository = new LocalDateHolderRepository(backend);
    LocalDate value = LocalDate.now();
    ImmutableLocalDateHolder holder = TypeHolder.LocalDateHolder.generator().get().withValue(value).withOptional(value).withNullable(null);
    repository.insert(holder);
    BsonDocument doc = fetch();
    BsonDateTime expected = new BsonDateTime(value.atStartOfDay(ZoneOffset.UTC).toInstant().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) ImmutableLocalDateHolder(org.immutables.criteria.typemodel.ImmutableLocalDateHolder) LocalDate(java.time.LocalDate) LocalDateHolderRepository(org.immutables.criteria.typemodel.LocalDateHolderRepository) Test(org.junit.jupiter.api.Test)

Aggregations

LocalDate (java.time.LocalDate)1 BsonDateTime (org.bson.BsonDateTime)1 BsonDocument (org.bson.BsonDocument)1 ImmutableLocalDateHolder (org.immutables.criteria.typemodel.ImmutableLocalDateHolder)1 LocalDateHolderRepository (org.immutables.criteria.typemodel.LocalDateHolderRepository)1 Test (org.junit.jupiter.api.Test)1