package br.gov.al.saude.scs.core.domain;
import static br.gov.al.saude.scs.constantes.ContantesScs.MensagensContantes.MSG_OBRIGATORIO_INFORMAR_PARTICIPANTE;
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.interfaces.Contexto;
import br.gov.al.saude.framework.core.validador.Validador;
import br.gov.al.saude.scs.core.domain.relatorio.RelatorioService;
import br.gov.al.saude.scs.core.domain.relatorio.impl.RelatorioServiceImpl;
import br.gov.al.saude.scs.core.infrastructure.relatorio.GeradorRelatorio;
import br.gov.al.saude.scs.model.TurmaParticipante;
import br.gov.al.saude.scs.parametros.ParametrosRelatorioCapacitacaoPorParticipante;
import br.gov.al.saude.scs.parametros.ParametrosRelatorioCapacitacaoPorPeriodo;
import br.gov.al.saude.scs.parametros.ParametrosRelatorioDespesas;
import br.gov.al.saude.scs.parametros.ParametrosRelatorioParticipantePorTurma;
import br.gov.al.saude.scs.parametros.ParametrosRelatorioParticipantesFaltantes;
import br.gov.al.saude.test.unidade.AbstractUnitTest;
import br.gov.al.saude.test.util.CommandSemMensagem;
import br.gov.al.saude.test.util.VerificadorLancamentoException;
@RunWith
(JMock.
class)
public class RelatorioServiceImplTest
extends AbstractUnitTest
{
private RelatorioService relatorioService
;
private GeradorRelatorio geradorRelatorioMock
;
private Validador validadorMock
;
@Before
public void inicializarContexto
(){
validadorMock = getContexto
().
mock(Validador.
class);
geradorRelatorioMock = getContexto
().
mock(GeradorRelatorio.
class);
relatorioService =
new RelatorioServiceImpl
(getValidadorMock
(), getGeradorRelatorioMock
());
}
@Test
public void aoEmitirRelatorioCapacitacaoPorParticipanteDeveriaDelegarParaOhGerador
(){
getContexto
().
checking(new Expectations
(){{
ignoring
(getValidadorMock
()).
validar(with
(any
(ParametrosRelatorioCapacitacaoPorParticipante.
class)), with
(new Class<?>[]{Contexto.
class}));
oneOf
(getGeradorRelatorioMock
()).
emitirRelatorioCapacitacaoPorParticipante(with
(any
(ParametrosRelatorioCapacitacaoPorParticipante.
class)));
}});
getRelatorioService
().
emitirRelatorioCapacitacaoPorParticipante(new ParametrosRelatorioCapacitacaoPorParticipante
());
}
@Test
public void aoEmitirRelatorioCapacitacaoPorParticipanteDeveriaDelegarParaOhValidadorComContexto
(){
final ParametrosRelatorioCapacitacaoPorParticipante parametros =
new ParametrosRelatorioCapacitacaoPorParticipante
();
getContexto
().
checking(new Expectations
(){{
oneOf
(getValidadorMock
()).
validar(with
(same
(parametros
)), with
(new Class<?>[]{Contexto.
class}));
ignoring
(getGeradorRelatorioMock
()).
emitirRelatorioCapacitacaoPorParticipante(with
(same
(parametros
)));
}});
getRelatorioService
().
emitirRelatorioCapacitacaoPorParticipante(parametros
);
}
@Test
public void aoEmitirRelatorioParticipantePorTurmaDeveriaDelegarParaOhGerador
(){
getContexto
().
checking(new Expectations
(){{
ignoring
(getValidadorMock
()).
validar(with
(any
(ParametrosRelatorioCapacitacaoPorParticipante.
class)), with
(new Class<?>[]{Contexto.
class}));
oneOf
(getGeradorRelatorioMock
()).
emitirRelatorioParticipantePorTurma(with
(any
(ParametrosRelatorioParticipantePorTurma.
class)));
}});
getRelatorioService
().
emitirRelatorioParticipantePorTurma(new ParametrosRelatorioParticipantePorTurma
());
}
@Test
public void aoEmitirRelatorioParticipantePorTurmaDeveriaDelegarParaOhValidadorComContexto
(){
final ParametrosRelatorioParticipantePorTurma parametros =
new ParametrosRelatorioParticipantePorTurma
();
getContexto
().
checking(new Expectations
(){{
oneOf
(getValidadorMock
()).
validar(with
(same
(parametros
)), with
(new Class<?>[]{Contexto.
class}));
ignoring
(getGeradorRelatorioMock
()).
emitirRelatorioParticipantePorTurma(with
(same
(parametros
)));
}});
getRelatorioService
().
emitirRelatorioParticipantePorTurma(parametros
);
}
@Test
public void aoEmitirRelatorioParticipantesFaltantesDeveriaDelegarParaOhGerador
(){
getContexto
().
checking(new Expectations
(){{
ignoring
(getValidadorMock
()).
validar(with
(any
(ParametrosRelatorioParticipantesFaltantes.
class)), with
(new Class<?>[]{Contexto.
class}));
oneOf
(getGeradorRelatorioMock
()).
emitirRelatorioParticipantesFaltantes(with
(any
(ParametrosRelatorioParticipantesFaltantes.
class)));
}});
getRelatorioService
().
emitirRelatorioParticipantesFaltantes(new ParametrosRelatorioParticipantesFaltantes
());
}
@Test
public void aoEmitirRelatorioParticipantesFaltantesDeveriaDelegarParaOhValidadorComContexto
(){
final ParametrosRelatorioParticipantesFaltantes parametros =
new ParametrosRelatorioParticipantesFaltantes
();
getContexto
().
checking(new Expectations
(){{
oneOf
(getValidadorMock
()).
validar(with
(same
(parametros
)), with
(new Class<?>[]{Contexto.
class}));
ignoring
(getGeradorRelatorioMock
()).
emitirRelatorioParticipantesFaltantes(with
(same
(parametros
)));
}});
getRelatorioService
().
emitirRelatorioParticipantesFaltantes(parametros
);
}
@Test
public void aoEmitirRelatorioCapacitacaoPorPeriodoDeveriaDelegarParaOhGerador
(){
getContexto
().
checking(new Expectations
(){{
ignoring
(getValidadorMock
()).
validar(with
(any
(ParametrosRelatorioParticipantesFaltantes.
class)), with
(new Class<?>[]{Contexto.
class}));
oneOf
(getGeradorRelatorioMock
()).
emitirRelatorioCapacitacaoPorPeriodo(with
(any
(ParametrosRelatorioCapacitacaoPorPeriodo.
class)));
}});
getRelatorioService
().
emitirRelatorioCapacitacaoPorPeriodo(new ParametrosRelatorioCapacitacaoPorPeriodo
());
}
@Test
public void aoEmitirRelatorioCapacitacaoPorPeriodoDeveriaDelegarParaOhValidadorComContexto
(){
final ParametrosRelatorioCapacitacaoPorPeriodo parametros =
new ParametrosRelatorioCapacitacaoPorPeriodo
();
getContexto
().
checking(new Expectations
(){{
oneOf
(getValidadorMock
()).
validar(with
(same
(parametros
)), with
(new Class<?>[]{Contexto.
class}));
ignoring
(getGeradorRelatorioMock
()).
emitirRelatorioCapacitacaoPorPeriodo(with
(same
(parametros
)));
}});
getRelatorioService
().
emitirRelatorioCapacitacaoPorPeriodo(parametros
);
}
@Test
public void aoEmitirRelatorioDespesasDeveriaDelegarParaOhGerador
(){
getContexto
().
checking(new Expectations
(){{
ignoring
(getValidadorMock
()).
validar(with
(any
(ParametrosRelatorioDespesas.
class)), with
(new Class<?>[]{Contexto.
class}));
oneOf
(getGeradorRelatorioMock
()).
emitirRelatorioDespesas(with
(any
(ParametrosRelatorioDespesas.
class)));
}});
getRelatorioService
().
emitirRelatorioDespesas(new ParametrosRelatorioDespesas
());
}
@Test
public void aoEmitirRelatorioDespesasDeveriaDelegarParaOhValidadorComContexto
(){
final ParametrosRelatorioDespesas parametros =
new ParametrosRelatorioDespesas
();
getContexto
().
checking(new Expectations
(){{
oneOf
(getValidadorMock
()).
validar(with
(same
(parametros
)), with
(new Class<?>[]{Contexto.
class}));
ignoring
(getGeradorRelatorioMock
()).
emitirRelatorioDespesas(with
(same
(parametros
)));
}});
getRelatorioService
().
emitirRelatorioDespesas(parametros
);
}
@Test
public void aoEmitirCertificadoDeveriaDelegarParaOhGerador
(){
getContexto
().
checking(new Expectations
(){{
oneOf
(getGeradorRelatorioMock
()).
emitirCertificado(with
(any
(TurmaParticipante.
class)));
}});
getRelatorioService
().
emitirCertificado(new TurmaParticipante
());
}
@Test
public void aoEmitirCertificadoInformandoParticipanteNuloDeveriaLancarExcecao
(){
getContexto
().
checking(new Expectations
(){{
never
(getGeradorRelatorioMock
()).
emitirCertificado(with
(any
(TurmaParticipante.
class)));
}});
VerificadorLancamentoException.
verificarMensagemLancamentoExceptionSemRetornoMensagem(new CommandSemMensagem
() {
@
Override
public void execute
() throws Exception {
getRelatorioService
().
emitirCertificado(null);
}
}, MSG_OBRIGATORIO_INFORMAR_PARTICIPANTE
);
}
public Validador getValidadorMock
() {
return validadorMock
;
}
public RelatorioService getRelatorioService
() {
return relatorioService
;
}
public GeradorRelatorio getGeradorRelatorioMock
() {
return geradorRelatorioMock
;
}
}