Skip to content

Instantly share code, notes, and snippets.

@dilnei
Created August 13, 2016 14:15
Show Gist options
  • Save dilnei/7b935d89006d91cfc8baa5880b00e09f to your computer and use it in GitHub Desktop.
Save dilnei/7b935d89006d91cfc8baa5880b00e09f to your computer and use it in GitHub Desktop.
Exemplo de utilização dos testes unitarios.
package br.com.application.model.repository;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertThat;
import java.util.List;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import br.com.application.model.entity.Advogado;
public class AdvogadoRepositoryTest extends AbstractRepositoryTest {
private AdvogadoRepository repository;
private Advogado advogado1;
private Advogado advogado2;
private Advogado advogado3;
@Before
public void setup() {
repository = new AdvogadoRepository(em);
advogado1 = new Advogado(1L, "Joao", "OAB", "12345678987");
advogado1 = repository.salvar(advogado1);
em.refresh(advogado1);
advogado2 = new Advogado(2L, "Zeneida", "OAB", "12345678987");
advogado2 = repository.salvar(advogado2);
em.refresh(advogado1);
advogado3 = new Advogado(3L, "Pedro", "OAB", "12345678987");
advogado3 = repository.salvar(advogado3);
em.refresh(advogado1);
}
@Test
public void testBuscarListaAdvogados() {
List<Advogado> advogados = repository.buscarLista();
assertThat(advogados, contains(advogado3, advogado2, advogado1));
assertThat(advogados, not(contains(advogado1, advogado2, advogado3)));
}
@Test
public void testBuscarListaParaSelect() {
List<Advogado> advogados = repository.buscarListaParaSelect();
assertThat(advogados, contains(advogado1, advogado3, advogado2));
assertThat(advogados, not(contains(advogado1, advogado2, advogado3)));
}
@After
public void tearDown() {
repository.excluir(advogado1);
repository.excluir(advogado2);
repository.excluir(advogado3);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment