package br.gov.al.saude.scs.core.application;
import java.util.ArrayList;
import java.util.List;
import org.jmock.Expectations;
import org.jmock.integration.junit4.JMock;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import br.gov.al.saude.framework.core.generic.GenericFacade;
import br.gov.al.saude.framework.core.generic.GenericService;
import br.gov.al.saude.sca.model.usuario.view.UsuarioView;
import br.gov.al.saude.scg.model.view.PessoaFisicaView;
import br.gov.al.saude.scs.core.application.turma.TurmaFacade;
import br.gov.al.saude.scs.core.application.turma.impl.TurmaFacadeImpl;
import br.gov.al.saude.scs.core.domain.turma.TurmaService;
import br.gov.al.saude.scs.model.Capacitacao;
import br.gov.al.saude.scs.model.Turma;
import br.gov.al.saude.scs.model.TurmaParticipante;
import br.gov.al.saude.scs.model.dto.ConsultaTurmaDTO;
import br.gov.al.saude.scs.parametros.ParametrosConsultarDespesasTurma;
import br.gov.al.saude.scs.parametros.ParametrosConsultarTurma;
import br.gov.al.saude.test.unidade.generic.facade.FacadeImplTest;
@RunWith
(JMock.
class)
public class TurmaFacadeImplTest
extends FacadeImplTest
<Turma
> {
private TurmaFacade turmaFacade
;
private TurmaService turmaServiceMock
;
@Before
public void inicializarContexto
() {
super.
inicializarContexto();
turmaServiceMock = getContexto
().
mock(TurmaService.
class);
turmaFacade =
new TurmaFacadeImpl
(turmaServiceMock
);
}
@
Override
protected GenericFacade
<Turma
> getFacade
() {
return turmaFacade
;
}
@
Override
protected GenericService
<Turma
> getServiceMock
() {
return turmaServiceMock
;
}
@Test
public void aoConsultarTurmaDeveriaDelegarParaOhService
() throws Exception {
getContexto
().
checking(new Expectations
(){{
oneOf
(turmaServiceMock
).
consultarTurma(with
(any
(Integer.
class)), with
(any
(Integer.
class)), with
(any
(ConsultaTurmaDTO.
class)));
will
(returnValue
(with
(any
(List.
class))));
}});
turmaFacade.
consultarTurma(1,
5,
new ConsultaTurmaDTO
(new Capacitacao
(),
new Turma
(),
2013));
}
@Test
public void aoDetalharTurmaDeveriaDelegarParaOhService
() throws Exception {
getContexto
().
checking(new Expectations
(){{
oneOf
(turmaServiceMock
).
detalharTurma(with
(any
(Long.
class)));
will
(returnValue
(with
(any
(Turma.
class))));
}});
turmaFacade.
detalharTurma(1l
);
}
@Test
public void aoConsultarPessoaDeveriaDelegarParaOhService
() throws Exception {
getContexto
().
checking(new Expectations
(){{
oneOf
(turmaServiceMock
).
consultarPessoa(with
(any
(Long.
class)));
will
(returnValue
(with
(any
(PessoaFisicaView.
class))));
}});
turmaFacade.
consultarPessoa(1l
);
}
@Test
public void aoConsultarTurmaDtoDeveriaDelegarParaOhService
(){
getContexto
().
checking(new Expectations
(){{
oneOf
(turmaServiceMock
).
consultarTurmaDTO(with
(any
(ParametrosConsultarTurma.
class)));
}});
turmaFacade.
consultarTurmaDTO(new ParametrosConsultarTurma
());
}
@Test
public void aoObterQuantidadeRegistrosConsultarTurmaDtoDeveriaDelegarParaOhService
(){
getContexto
().
checking(new Expectations
(){{
oneOf
(turmaServiceMock
).
obterQuantidadeRegistrosConsultarTurmaDTO(with
(any
(ParametrosConsultarTurma.
class)));
}});
turmaFacade.
obterQuantidadeRegistrosConsultarTurmaDTO(new ParametrosConsultarTurma
());
}
@Test
public void aoObterQuantidadeDeRegistrosConsultarTurmaDeveriaDelegarParaOhService
(){
getContexto
().
checking(new Expectations
(){{
oneOf
(turmaServiceMock
).
obterQuantidadeDeRegistrosConsultarTurma(with
(any
(ConsultaTurmaDTO.
class)));
}});
turmaFacade.
obterQuantidadeDeRegistrosConsultarTurma(new ConsultaTurmaDTO
());
}
@Test
public void aoListarOrgaoDeveriaDelegarParaOhService
() throws Exception {
getContexto
().
checking(new Expectations
(){{
oneOf
(turmaServiceMock
).
listarOrgaos();
will
(returnValue
(with
(any
(List.
class))));
}});
turmaFacade.
listarOrgaos();
}
@Test
public void aoVerificarAlertasDoParticipanteDeveriaDelegarParaOhService
() throws Exception {
getContexto
().
checking(new Expectations
(){{
oneOf
(turmaServiceMock
).
verificarAlertasDoParticipante(with
(any
(Long.
class)));
will
(returnValue
(with
(any
(String.
class))));
}});
turmaFacade.
verificarAlertasDoParticipante(1l
);
}
@Test
public void aoVerificarRestricoesDoParticipanteDeveriaDelegarParaOhService
() throws Exception {
getContexto
().
checking(new Expectations
(){{
oneOf
(turmaServiceMock
).
verificarFaltasDoParticipante(with
(any
(UsuarioView.
class)), with
(any
(TurmaParticipante.
class)));
will
(returnValue
(with
(any
(String.
class))));
}});
turmaFacade.
verificarFaltasDoParticipante(new UsuarioView
(),
new TurmaParticipante
());
}
@Test
public void aoConsultarTurmaComParticipantesDeveriaDelegarParaOhService
() throws Exception {
getContexto
().
checking(new Expectations
(){{
oneOf
(turmaServiceMock
).
consultarTurmaComParticipantes(with
(any
(Long.
class)));
will
(returnValue
(with
(any
(Turma.
class))));
}});
turmaFacade.
consultarTurmaComParticipantes(1l
);
}
@Test
public void aoConsultarDespesasTurmaDeveriaDelegarParaOhService
() throws Exception {
getContexto
().
checking(new Expectations
(){{
oneOf
(turmaServiceMock
).
consultarDespesasTurma(with
(any
(ParametrosConsultarDespesasTurma.
class)));
}});
turmaFacade.
consultarDespesasTurma(new ParametrosConsultarDespesasTurma
());
}
@Test
public void aoConsultarIndicadorDeServidorDeveriaDelegarParaOhService
() throws Exception {
getContexto
().
checking(new Expectations
(){{
oneOf
(turmaServiceMock
).
consultarIndicadorDeServidor(with
(any
(PessoaFisicaView.
class)));
}});
turmaFacade.
consultarIndicadorDeServidor(new PessoaFisicaView
());
}
@Test
@
SuppressWarnings("unchecked")
public void aoVerificarAlertaDeRestricaoDoParticipanteDeveriaDelegarParaOhService
() throws Exception {
getContexto
().
checking(new Expectations
(){{
oneOf
(turmaServiceMock
).
verificarAlertaDeRestricaoDoParticipante(with
(any
(TurmaParticipante.
class)), with
(any
(List.
class)));
}});
turmaFacade.
verificarAlertaDeRestricaoDoParticipante(new TurmaParticipante
(),
new ArrayList<TurmaParticipante
>());
}
}