Skip to content

Commit

Permalink
test: create test scenarion to update
Browse files Browse the repository at this point in the history
Signed-off-by: Otavio Santana <otaviopolianasantana@gmail.com>
  • Loading branch information
otaviojava committed Dec 28, 2023
1 parent 113974e commit b9ca8ba
Showing 1 changed file with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,39 @@ void shouldUpdateArrayParameter() throws Throwable {
Assertions.assertThat(new Person[]{person}).isEqualTo(invoked);
}

@Test
void shouldUpdateArrayParameterBoolean() throws Throwable {
Method method = PersonRepository.class.getDeclaredMethod("arrayBoolean", Person[].class);
Person person = Person.builder().build();
Mockito.when(repository.updateAll(List.of(person))).thenReturn(1);
Object invoked = AnnotationOperation.UPDATE.invoke(new AnnotationOperation.Operation(method, new Object[]{new Person[]{person}},
repository));
Mockito.verify(repository).updateAll(List.of(person));
Assertions.assertThat(invoked).isEqualTo(true);
}

@Test
void shouldUpdateArrayParameterInt() throws Throwable {
Method method = PersonRepository.class.getDeclaredMethod("arrayInt", Person[].class);
Person person = Person.builder().build();
Mockito.when(repository.updateAll(List.of(person))).thenReturn(1);
Object invoked = AnnotationOperation.UPDATE.invoke(new AnnotationOperation.Operation(method, new Object[]{new Person[]{person}},
repository));
Mockito.verify(repository).updateAll(List.of(person));
Assertions.assertThat(invoked).isEqualTo(1);
}

@Test
void shouldUpdateArrayParameterVoid() throws Throwable {
Method method = PersonRepository.class.getDeclaredMethod("arrayVoid", Person[].class);
Person person = Person.builder().build();
Mockito.when(repository.updateAll(List.of(person))).thenReturn(1);
Object invoked = AnnotationOperation.UPDATE.invoke(new AnnotationOperation.Operation(method, new Object[]{new Person[]{person}},
repository));
Mockito.verify(repository).updateAll(List.of(person));
Assertions.assertThat(invoked).isEqualTo(Void.TYPE);
}


interface PersonRepository extends DataRepository<Person, Long>{

Expand Down

0 comments on commit b9ca8ba

Please sign in to comment.