Skip to content

Commit f0b60cf

Browse files
committed
test: add tests for the count method with bson query filter
Signed-off-by: Maximillian Arruda <[email protected]>
1 parent 9f9658b commit f0b60cf

File tree

1 file changed

+34
-5
lines changed

1 file changed

+34
-5
lines changed

jnosql-mongodb/src/test/java/org/eclipse/jnosql/databases/mongodb/communication/MongoDBSpecificFeaturesTest.java

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import java.util.stream.Collectors;
3838
import java.util.stream.Stream;
3939

40+
import static com.mongodb.client.model.Filters.and;
4041
import static com.mongodb.client.model.Filters.eq;
4142
import static org.assertj.core.api.Assertions.assertThat;
4243
import static org.eclipse.jnosql.communication.driver.IntegrationTest.NAMED;
@@ -60,14 +61,14 @@ public void beforeEach() {
6061
}
6162

6263
@Test
63-
public void shouldReturnErrorOnSelectWhenThereIsNullParameter(){
64+
public void shouldReturnErrorOnSelectWhenThereIsNullParameter() {
6465
Assertions.assertThrows(NullPointerException.class,
6566
() -> entityManager.select(null, null));
6667
Assertions.assertThrows(NullPointerException.class,
6768
() -> entityManager.select(COLLECTION_NAME, null));
6869

6970
Assertions.assertThrows(NullPointerException.class,
70-
() -> entityManager.select(null, eq("name", "Poliana")));
71+
() -> entityManager.select(null, eq("name", "Poliana")));
7172
}
7273

7374
@Test
@@ -81,14 +82,14 @@ public void shouldFindDocument() {
8182
}
8283

8384
@Test
84-
public void shouldReturnErrorOnDeleteWhenThereIsNullParameter(){
85+
public void shouldReturnErrorOnDeleteWhenThereIsNullParameter() {
8586
Assertions.assertThrows(NullPointerException.class,
8687
() -> entityManager.delete(null, null));
8788
Assertions.assertThrows(NullPointerException.class,
8889
() -> entityManager.delete(COLLECTION_NAME, null));
8990

9091
Assertions.assertThrows(NullPointerException.class,
91-
() -> entityManager.delete(null, eq("name", "Poliana")));
92+
() -> entityManager.delete(null, eq("name", "Poliana")));
9293
}
9394

9495
@Test
@@ -105,7 +106,7 @@ public void shouldDelete() {
105106
}
106107

107108
@Test
108-
public void shouldReturnErrorOnAggregateWhenThereIsNullParameter(){
109+
public void shouldReturnErrorOnAggregateWhenThereIsNullParameter() {
109110
Assertions.assertThrows(NullPointerException.class,
110111
() -> entityManager.aggregate(null, null));
111112
Assertions.assertThrows(NullPointerException.class,
@@ -146,4 +147,32 @@ private DocumentEntity getEntity() {
146147
return entity;
147148
}
148149

150+
@Test
151+
public void shouldCountWithFilter() {
152+
153+
entityManager.insert(getEntity());
154+
var filter = eq("name", "Poliana");
155+
Assertions.assertEquals(1L, entityManager.count(COLLECTION_NAME, filter));
156+
157+
var filter2 = and(filter,eq("city", "Salvador"));
158+
Assertions.assertEquals(1L, entityManager.count(COLLECTION_NAME, filter2));
159+
160+
var filter3 = and(filter,eq("city", "São Paulo"));
161+
Assertions.assertEquals(0L, entityManager.count(COLLECTION_NAME, filter3));
162+
163+
}
164+
165+
@Test
166+
public void shouldReturnErrorOnCountWithInvalidFilter() {
167+
168+
Assertions.assertThrows(NullPointerException.class,
169+
() -> entityManager.count(null, null));
170+
Assertions.assertThrows(NullPointerException.class,
171+
() -> entityManager.count(COLLECTION_NAME, null));
172+
Assertions.assertThrows(NullPointerException.class,
173+
() -> entityManager.count(null, eq("name","Poliana")));
174+
175+
}
176+
177+
149178
}

0 commit comments

Comments
 (0)