-
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.
- Loading branch information
1 parent
bdad3a5
commit 273b6e7
Showing
4 changed files
with
149 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,55 @@ | ||
package br.com.aplicacao.ordem; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mockito; | ||
|
||
import br.com.dominio.ordem.Ordem; | ||
import io.quarkus.test.junit.QuarkusTest; | ||
|
||
@QuarkusTest | ||
class OrdemDTOTest { | ||
|
||
@Test | ||
void construtorComParametros_tudoValido_retornoOk() { | ||
String tipo = "COMPRA"; | ||
|
||
Ordem ordem = Mockito.mock(Ordem.class); | ||
Mockito.when(ordem.getTipo()).thenReturn(tipo); | ||
OrdemDTO ordemDTO = new OrdemDTO(ordem); | ||
Assertions.assertSame(tipo, ordemDTO.getTipo()); | ||
} | ||
|
||
@Test | ||
void converteParaAEntidade_tudoValido_retornoOk() { | ||
Double preco = 3.50; | ||
|
||
OrdemDTO ordemDTO = new OrdemDTO(); | ||
ordemDTO.setPreco(preco); | ||
ordemDTO.setTipo("VENDA"); | ||
ordemDTO.setUserId(1L); | ||
|
||
Ordem ordem = ordemDTO.converteParaAEntidade(); | ||
Assertions.assertSame(preco, ordem.getPreco()); | ||
} | ||
|
||
@Test | ||
void converte_tudoValido_retornoOk() { | ||
String tipo = "COMPRA"; | ||
|
||
Ordem ordem1 = Mockito.mock(Ordem.class); | ||
Mockito.when(ordem1.getTipo()).thenReturn(tipo); | ||
Ordem ordem2 = Mockito.mock(Ordem.class); | ||
|
||
List<Ordem> listaDeOrdem = new ArrayList<Ordem>(); | ||
listaDeOrdem.add(ordem1); | ||
listaDeOrdem.add(ordem2); | ||
|
||
List<OrdemDTO> listaDeOrdemDTO = OrdemDTO.converte(listaDeOrdem); | ||
Assertions.assertSame(tipo, listaDeOrdemDTO.get(0).getTipo()); | ||
} | ||
|
||
} |
56 changes: 56 additions & 0 deletions
56
src/test/java/br/com/aplicacao/usuario/UsuarioDTOTest.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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package br.com.aplicacao.usuario; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mockito; | ||
|
||
import br.com.dominio.usuario.Usuario; | ||
import io.quarkus.test.junit.QuarkusTest; | ||
|
||
@QuarkusTest | ||
class UsuarioDTOTest { | ||
|
||
@Test | ||
void construtorComParametros_tudoValido_retornoOk() { | ||
String nome = "GUSTAVO"; | ||
|
||
Usuario usuario = Mockito.mock(Usuario.class); | ||
Mockito.when(usuario.getNome()).thenReturn(nome); | ||
UsuarioDTO usuarioDTO = new UsuarioDTO(usuario); | ||
Assertions.assertSame(nome, usuarioDTO.getNome()); | ||
} | ||
|
||
@Test | ||
void converteParaAEntidade_tudoValido_retornoOk() { | ||
String nome = "GUSTAVO"; | ||
|
||
UsuarioDTO usuarioDTO = new UsuarioDTO(); | ||
usuarioDTO.setNome(nome); | ||
usuarioDTO.setCpf("123"); | ||
usuarioDTO.setUsername("greche"); | ||
usuarioDTO.setPassword("1234"); | ||
|
||
Usuario usuario = usuarioDTO.converteParaAEntidade(); | ||
Assertions.assertSame(nome, usuario.getNome()); | ||
} | ||
|
||
@Test | ||
void converte_tudoValido_retornoOk() { | ||
String nome = "GUSTAVO"; | ||
|
||
Usuario usuario1 = Mockito.mock(Usuario.class); | ||
Mockito.when(usuario1.getNome()).thenReturn(nome); | ||
Usuario usuario2 = Mockito.mock(Usuario.class); | ||
|
||
List<Usuario> listaDeUsuario = new ArrayList<Usuario>(); | ||
listaDeUsuario.add(usuario1); | ||
listaDeUsuario.add(usuario2); | ||
|
||
List<UsuarioDTO> listaDeUsuarioDTO = UsuarioDTO.converte(listaDeUsuario); | ||
Assertions.assertSame(nome, listaDeUsuarioDTO.get(0).getNome()); | ||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
src/test/java/br/com/dominio/ordem/repositorio/OrdemRepositoryTest.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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package br.com.dominio.ordem.repositorio; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mockito; | ||
|
||
import br.com.dominio.ordem.Ordem; | ||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.quarkus.test.junit.mockito.InjectMock; | ||
|
||
@QuarkusTest | ||
class OrdemRepositoryTest { | ||
|
||
@InjectMock | ||
OrdemRepository ordemRepository; | ||
|
||
@Test | ||
void listAll_tudoValido_retornoOk() { | ||
Ordem ordem1 = new Ordem(); | ||
Ordem ordem2 = new Ordem(); | ||
List<Ordem> listaDeOrdens = new ArrayList<Ordem>(); | ||
|
||
listaDeOrdens.add(ordem1); | ||
listaDeOrdens.add(ordem2); | ||
|
||
Mockito.when(ordemRepository.listAll()).thenReturn(listaDeOrdens); | ||
|
||
Assertions.assertSame(ordem2, ordemRepository.listAll().get(1)); | ||
} | ||
|
||
} |