-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create implementation to annotation operation
Signed-off-by: Otavio Santana <otaviopolianasantana@gmail.com>
- Loading branch information
1 parent
717b419
commit 0811d09
Showing
2 changed files
with
152 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 80 additions & 1 deletion
81
...ing-core/src/test/java/org/eclipse/jnosql/mapping/core/query/AnnotationOperationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,83 @@ | ||
/* | ||
* Copyright (c) 2023 Contributors to the Eclipse Foundation | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* and Apache License v2.0 which accompanies this distribution. | ||
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html | ||
* and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php. | ||
* | ||
* You may elect to redistribute this code under either of these licenses. | ||
* | ||
* Contributors: | ||
* | ||
* Otavio Santana | ||
*/ | ||
package org.eclipse.jnosql.mapping.core.query; | ||
|
||
import jakarta.data.repository.DataRepository; | ||
import org.assertj.core.api.Assertions; | ||
import org.eclipse.jnosql.mapping.core.entities.Person; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import java.lang.reflect.Method; | ||
import java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class AnnotationOperationTest { | ||
|
||
|
||
@Mock | ||
private AbstractRepository<Person, Long> repository; | ||
|
||
|
||
@Test | ||
void shouldInsertSingleParameter() throws Throwable { | ||
Method method = PersonRepository.class.getDeclaredMethod("same", Person.class); | ||
Person person = Person.builder().build(); | ||
Mockito.when(repository.insert(person)).thenReturn(person); | ||
Object invoked = AnnotationOperation.INSERT.invoke(new AnnotationOperation.Operation(method, new Object[]{person}, repository)); | ||
Mockito.verify(repository).insert(person); | ||
Assertions.assertThat(person).isEqualTo(invoked); | ||
} | ||
|
||
@Test | ||
void shouldInsertIterableParameter() throws Throwable { | ||
Method method = PersonRepository.class.getDeclaredMethod("iterable", List.class); | ||
Person person = Person.builder().build(); | ||
Mockito.when(repository.insertAll(List.of(person))).thenReturn(List.of(person)); | ||
Object invoked = AnnotationOperation.INSERT.invoke(new AnnotationOperation.Operation(method, new Object[]{List.of(person)}, repository)); | ||
Mockito.verify(repository).insertAll(List.of(person)); | ||
Assertions.assertThat(List.of(person)).isEqualTo(invoked); | ||
} | ||
|
||
|
||
@Test | ||
void shouldInsertArrayParameter() throws Throwable { | ||
Method method = PersonRepository.class.getDeclaredMethod("array", Person[].class); | ||
Person person = Person.builder().build(); | ||
Mockito.when(repository.insertAll(List.of(person))).thenReturn(List.of(person)); | ||
Object invoked = AnnotationOperation.INSERT.invoke(new AnnotationOperation.Operation(method, new Object[]{new Person[]{person}}, | ||
repository)); | ||
Mockito.verify(repository).insertAll(List.of(person)); | ||
Assertions.assertThat(List.of(person)).isEqualTo(invoked); | ||
} | ||
|
||
|
||
|
||
|
||
interface PersonRepository extends DataRepository<Person, Long>{ | ||
|
||
void methodVoid(Person person); | ||
|
||
Person same(Person person); | ||
|
||
Person[] array(Person[] people); | ||
|
||
List<Person> iterable(List<Person> people); | ||
} | ||
} |