Skip to content

Commit

Permalink
test: create prepare
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 9ea9614 commit 45b2b70
Showing 1 changed file with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import jakarta.data.page.CursoredPage;
import jakarta.data.page.PageRequest;
import org.assertj.core.api.Assertions;
import org.eclipse.jnosql.communication.Condition;
import org.eclipse.jnosql.communication.TypeReference;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -430,6 +431,56 @@ void shouldReturnErrorSortSizeDifferentFromOrderSizeAfterKey() {
PageRequest.ofSize(10).afterKey("Ada", 20)));
}

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

long count = databaseManager.count(query);
Assertions.assertThat(count).isNotZero().isEqualTo(2L);
}

@Test
void shouldReturnZeroWhenCountIsEmpty(){
SelectQuery query = SelectQuery.select().from("person").build();
Mockito.when(databaseManager.select(query)).thenReturn(Stream.empty());
long count = databaseManager.count(query);
Assertions.assertThat(count).isZero();
}

@Test
void shouldExists(){
SelectQuery query = SelectQuery.select().from("person").build();
Mockito.when(databaseManager.select(query)).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());

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

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

Stream<CommunicationEntity> entities = databaseManager.query("select * from person");
Assertions.assertThat(entities).hasSize(2);
}

@Test
void shouldPrepare(){
var prepare = databaseManager.prepare("select * from person where name = @name");
Assertions.assertThat(prepare).isNotNull();
}


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

0 comments on commit 45b2b70

Please sign in to comment.