Skip to content

Commit ff0d845

Browse files
committed
feat: add count tests for entity manager
Implemented tests for counting entities by collection name and by SelectQuery, ensuring correct behavior and exception handling for null inputs. Signed-off-by: Maximillian Arruda <[email protected]>
1 parent 8e423d5 commit ff0d845

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

jnosql-tinkerpop/src/test/java/org/eclipse/jnosql/databases/tinkerpop/communication/DefaultTinkerpopGraphDatabaseManagerTest.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,52 @@ void shouldFindAllByFields() {
461461
});
462462
}
463463

464+
@Test
465+
void shouldCountByCollectionName() {
466+
467+
List<CommunicationEntity> entitiesWithValues = getEntitiesWithValues();
468+
469+
entityManager.insert(entitiesWithValues);
470+
471+
SelectQuery query = select().from(COLLECTION_NAME)
472+
.where("age").gt(22)
473+
.and("type").eq("V")
474+
.orderBy("age").asc()
475+
.build();
476+
477+
478+
SoftAssertions.assertSoftly(softly -> {
479+
softly.assertThat(entityManager.count(COLLECTION_NAME))
480+
.isEqualTo(entitiesWithValues.size());
481+
softly.assertThatThrownBy(()-> entityManager.count((String)null))
482+
.as("should throw exception when collection name is null")
483+
.isInstanceOf(NullPointerException.class);
484+
});
485+
}
486+
487+
@Test
488+
void shouldCountBySelectQuery() {
489+
490+
List<CommunicationEntity> entitiesWithValues = getEntitiesWithValues();
491+
492+
entityManager.insert(entitiesWithValues);
493+
494+
var query = select().from(COLLECTION_NAME)
495+
.where("age").gt(22)
496+
.and("type").eq("V")
497+
.orderBy("age").asc()
498+
.build();
499+
500+
501+
SoftAssertions.assertSoftly(softly -> {
502+
softly.assertThat(entityManager.count(query))
503+
.isEqualTo(2);
504+
softly.assertThatThrownBy(()-> entityManager.count((SelectQuery) null))
505+
.as("should throw exception when select query is null")
506+
.isInstanceOf(NullPointerException.class);
507+
});
508+
}
509+
464510
@Test
465511
void shouldCreateEdge() {
466512
var person1 = entityManager.insert(getEntity());

0 commit comments

Comments
 (0)