Skip to content

Commit 169d6a7

Browse files
committed
feat: enhance count tests in CouchbaseDocumentManager
Refactored count tests to use assertSoftly for better readability and added additional assertions to verify count behavior with null values and specific queries. Signed-off-by: Maximillian Arruda <[email protected]> (cherry picked from commit d6889ea) Signed-off-by: Maximillian Arruda <[email protected]>
1 parent bcb9e0c commit 169d6a7

File tree

1 file changed

+29
-11
lines changed

1 file changed

+29
-11
lines changed

jnosql-couchbase/src/test/java/org/eclipse/jnosql/databases/couchbase/communication/CouchbaseDocumentManagerTest.java

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import com.couchbase.client.core.error.DocumentNotFoundException;
1818
import com.couchbase.client.java.json.JsonObject;
1919
import org.assertj.core.api.Assertions;
20-
import org.assertj.core.api.SoftAssertions;
2120
import org.eclipse.jnosql.communication.Settings;
2221
import org.eclipse.jnosql.communication.TypeReference;
2322
import org.eclipse.jnosql.communication.keyvalue.BucketManager;
@@ -44,6 +43,7 @@
4443

4544
import static java.util.Arrays.asList;
4645
import static org.assertj.core.api.Assertions.assertThat;
46+
import static org.assertj.core.api.SoftAssertions.assertSoftly;
4747
import static org.awaitility.Awaitility.await;
4848
import static org.eclipse.jnosql.communication.driver.IntegrationTest.MATCHES;
4949
import static org.eclipse.jnosql.communication.driver.IntegrationTest.NAMED;
@@ -206,11 +206,29 @@ void shouldRetrieveListDocumentList() {
206206
}
207207

208208
@Test
209-
void shouldCount() {
210-
CommunicationEntity entity = getEntity();
211-
entityManager.insert(entity);
212-
long counted = entityManager.count(COLLECTION_PERSON_NAME);
213-
assertTrue(counted > 0);
209+
void shouldCount() {
210+
CommunicationEntity entity = entityManager.insert(createSubdocumentList());
211+
Element key = entity.find("_id").get();
212+
var query = select().from(COLLECTION_APP_NAME).where(key.name()).eq(key.get()).build();
213+
214+
assertSoftly(softly -> {
215+
softly.assertThat(entityManager.count(entity.name()))
216+
.as("must return more than zero for person collection")
217+
.isEqualTo(1L);
218+
219+
softly.assertThat(entityManager.count(query))
220+
.isEqualTo(1L);
221+
222+
softly.assertThatThrownBy(()->
223+
entityManager.count((String) null))
224+
.isInstanceOf(NullPointerException.class);
225+
226+
softly.assertThatThrownBy(()->
227+
entityManager.count((SelectQuery) null))
228+
.isInstanceOf(NullPointerException.class);
229+
230+
});
231+
214232
}
215233

216234
@Test
@@ -222,7 +240,7 @@ void shouldFindContains() {
222240
"lia")), COLLECTION_PERSON_NAME, Collections.emptyList());
223241

224242
var result = entityManager.select(query).toList();
225-
SoftAssertions.assertSoftly(softly -> {
243+
assertSoftly(softly -> {
226244
softly.assertThat(result).hasSize(1);
227245
softly.assertThat(result.get(0).find("name").orElseThrow().get(String.class)).isEqualTo("Poliana");
228246
});
@@ -237,7 +255,7 @@ void shouldStartsWith() {
237255
"Pol")), COLLECTION_PERSON_NAME, Collections.emptyList());
238256

239257
var result = entityManager.select(query).toList();
240-
SoftAssertions.assertSoftly(softly -> {
258+
assertSoftly(softly -> {
241259
softly.assertThat(result).hasSize(1);
242260
softly.assertThat(result.get(0).find("name").orElseThrow().get(String.class)).isEqualTo("Poliana");
243261
});
@@ -252,7 +270,7 @@ void shouldEndsWith() {
252270
"ana")), COLLECTION_PERSON_NAME, Collections.emptyList());
253271

254272
var result = entityManager.select(query).toList();
255-
SoftAssertions.assertSoftly(softly -> {
273+
assertSoftly(softly -> {
256274
softly.assertThat(result).hasSize(1);
257275
softly.assertThat(result.get(0).find("name").orElseThrow().get(String.class)).isEqualTo("Poliana");
258276
});
@@ -322,7 +340,7 @@ void shouldInsertNull() {
322340
entity.add(Element.of("name", null));
323341
CommunicationEntity documentEntity = entityManager.insert(entity);
324342
Optional<Element> name = documentEntity.find("name");
325-
SoftAssertions.assertSoftly(soft -> {
343+
assertSoftly(soft -> {
326344
soft.assertThat(name).isPresent();
327345
soft.assertThat(name).get().extracting(Element::name).isEqualTo("name");
328346
soft.assertThat(name).get().extracting(Element::get).isNull();
@@ -335,7 +353,7 @@ void shouldUpdateNull(){
335353
entity.add(Element.of("name", null));
336354
var documentEntity = entityManager.update(entity);
337355
Optional<Element> name = documentEntity.find("name");
338-
SoftAssertions.assertSoftly(soft -> {
356+
assertSoftly(soft -> {
339357
soft.assertThat(name).isPresent();
340358
soft.assertThat(name).get().extracting(Element::name).isEqualTo("name");
341359
soft.assertThat(name).get().extracting(Element::get).isNull();

0 commit comments

Comments
 (0)