-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementa teste com PanacheMock, da entidade Usuario
- Loading branch information
1 parent
3c794c0
commit bdad3a5
Showing
2 changed files
with
29 additions
and
0 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
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package br.com.dominio.usuario; | ||
|
||
import java.util.Optional; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mockito; | ||
|
||
import io.quarkus.hibernate.orm.panache.PanacheEntityBase; | ||
import io.quarkus.panache.mock.PanacheMock; | ||
import io.quarkus.test.junit.QuarkusTest; | ||
|
||
@QuarkusTest | ||
class UsuarioTest { | ||
|
||
@Test | ||
void findByIdOptional_tudoValido_retornoOk() { | ||
PanacheMock.mock(Usuario.class); | ||
Usuario usuarioCriado = new Usuario(); | ||
Optional<PanacheEntityBase> usuario = Optional.of(usuarioCriado); | ||
Mockito.when(Usuario.findByIdOptional(999)).thenReturn(usuario); | ||
Assertions.assertSame(usuarioCriado, Usuario.findByIdOptional(999).get()); | ||
} | ||
|
||
} |