Skip to content

Commit

Permalink
test: create custom repository save scenarios
Browse files Browse the repository at this point in the history
Signed-off-by: Otavio Santana <otaviopolianasantana@gmail.com>
  • Loading branch information
otaviojava committed Jun 1, 2024
1 parent d995ff0 commit 0d2a80a
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,45 @@ void shouldDeleteArrayEntity() {
Mockito.verifyNoMoreInteractions(template);
}

@Test
void shouldSaveEntity() {
Person person = Person.builder().withAge(26).withName("Ada").build();
Mockito.when(template.insert(person)).thenReturn(person);
Person result = people.save(person);

Mockito.verify(template).insert(person);
Mockito.verify(template).find(Person.class, 0L);
Assertions.assertThat(result).isEqualTo(person);
}

@Test
void shouldSaveListEntity() {
Person ada = Person.builder().withAge(26).withName("Ada").build();
var persons = List.of(ada);
Mockito.when(template.insert(persons)).thenReturn(persons);
Mockito.when(template.insert(ada)).thenReturn(ada);
List<Person> result = people.save(persons);

Mockito.verify(template).insert(ada);
Mockito.verify(template).find(Person.class, 0L);
Assertions.assertThat(result).isEqualTo(persons);
}

@Test
void shouldSaveArrayEntity() {
Person ada = Person.builder().withAge(26).withName("Ada").build();
var persons = new Person[]{ada};
Mockito.when(template.insert(Mockito.any())).thenReturn(List.of(ada));
Mockito.when(template.insert(ada)).thenReturn(ada);
Person[] result = people.save(persons);

Mockito.verify(template).insert(ada);
Mockito.verify(template).find(Person.class, 0L);
Assertions.assertThat(result).isEqualTo(persons);
}



@Test
void shouldExecuteObjectMethods(){
Assertions.assertThat(people.toString()).isNotNull();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import jakarta.data.repository.Insert;
import jakarta.data.repository.Param;
import jakarta.data.repository.Query;
import jakarta.data.repository.Save;
import jakarta.data.repository.Update;
import org.eclipse.jnosql.mapping.semistructured.entities.Person;

Expand Down Expand Up @@ -50,6 +51,15 @@ public interface People {
@Update
Person[] update(Person[] person);

@Save
List<Person> save(List<Person> people);

@Save
Person save(Person person);

@Save
Person[] save(Person[] person);


@Delete
void delete(List<Person> people);
Expand Down

0 comments on commit 0d2a80a

Please sign in to comment.