Skip to content

Commit

Permalink
test: create database manager scenario
Browse files Browse the repository at this point in the history
Signed-off-by: Otavio Santana <otaviopolianasantana@gmail.com>
  • Loading branch information
otaviojava committed Mar 30, 2024
1 parent 45b2b70 commit 7c68f1f
Showing 1 changed file with 32 additions and 3 deletions.
Expand Up @@ -11,6 +11,7 @@

package org.eclipse.jnosql.communication.semistructured;

import jakarta.data.exceptions.NonUniqueResultException;
import jakarta.data.page.CursoredPage;
import jakarta.data.page.PageRequest;
import org.assertj.core.api.Assertions;
Expand Down Expand Up @@ -451,16 +452,16 @@ void shouldReturnZeroWhenCountIsEmpty(){
@Test
void shouldExists(){
SelectQuery query = SelectQuery.select().from("person").build();
Mockito.when(databaseManager.select(query)).thenReturn(stream());
Mockito.when(databaseManager.select(Mockito.any())).thenReturn(stream());

boolean exists = databaseManager.exists(query);
Assertions.assertThat(exists).isTrue();
}

@Test
void shouldNotExists(){
SelectQuery query = SelectQuery.select().from("person").build();
Mockito.when(databaseManager.select(query)).thenReturn(Stream.empty());
var query = SelectQuery.select().from("person").build();
Mockito.when(databaseManager.select(Mockito.any())).thenReturn(Stream.empty());

boolean exists = databaseManager.exists(query);
Assertions.assertThat(exists).isFalse();
Expand All @@ -481,6 +482,34 @@ void shouldPrepare(){
Assertions.assertThat(prepare).isNotNull();
}

@Test
void shouldReturnErrorSingleResult(){
SelectQuery query = SelectQuery.select().from("person").build();
Mockito.when(databaseManager.select(query)).thenReturn(stream());

Assertions.assertThatThrownBy(() -> databaseManager.singleResult(query))
.isInstanceOf(NonUniqueResultException.class);

}

@Test
void shouldSingleResult(){
SelectQuery query = SelectQuery.select().from("person").build();
Mockito.when(databaseManager.select(query)).thenReturn(Stream.of(CommunicationEntity.of("name")));

var entity = databaseManager.singleResult(query);
Assertions.assertThat(entity).isPresent();
}

@Test
void shouldReturnEmptyAtSingleResult(){
SelectQuery query = SelectQuery.select().from("person").build();
Mockito.when(databaseManager.select(query)).thenReturn(Stream.empty());

var entity = databaseManager.singleResult(query);
Assertions.assertThat(entity).isEmpty();
}


private Stream<CommunicationEntity> stream() {
var entity = CommunicationEntity.of("name");
Expand Down

0 comments on commit 7c68f1f

Please sign in to comment.