Skip to content

Commit

Permalink
Merge pull request #31 from fincatto/dev
Browse files Browse the repository at this point in the history
Melhorado o lancamento de excecoes na validacao numerica
  • Loading branch information
jefperito committed Apr 2, 2015
2 parents 18cca5d + afdfd3e commit 13a9be6
Show file tree
Hide file tree
Showing 54 changed files with 219 additions and 238 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static String tamanho4Com2CasasDecimais(final BigDecimal valor) {

private static String parse(BigDecimal valor, final String formato, final int tamanho, final int posicaoPontoFlutuante) {
if (valor.toPlainString().length() > tamanho || StringUtils.split(valor.toPlainString(), ".")[0].length() > (tamanho - (posicaoPontoFlutuante + 1)) || valor.scale() > posicaoPontoFlutuante) {
throw new IllegalStateException("Valor extrapolou o tamanho de casas");
throw new NumberFormatException("Valor extrapolou o tamanho de casas");
}
valor = valor.round(new MathContext(valor.precision(), RoundingMode.UNNECESSARY));
return new DecimalFormat(formato, DecimalFormatSymbols.getInstance(Locale.US)).format(valor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ public class BigIntegerValidador {

public static void tamanho12(final BigInteger valor) {
if (valor.compareTo(new BigInteger("999999999999")) > 0) {
throw new IllegalStateException("Tamanho maior que 12");
throw new NumberFormatException("Tamanho maior que 12");
}
}

public static void tamanho11(final BigInteger valor) {
if (valor.compareTo(new BigInteger("99999999999")) > 0) {
throw new IllegalStateException("Tamanho maior que 11");
throw new NumberFormatException("Tamanho maior que 11");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ public static void exatamente2(final Integer valor) {

private static void limite(final Integer valor, final int maximo) {
if (valor > maximo) {
throw new IllegalStateException("Valor extrapolou o tamanho do campo");
throw new NumberFormatException("Valor extrapolou o tamanho do campo");
}
}

private static void intervalo(final Integer valor, final int minimo, final int maximo) {
if (valor < minimo || valor > maximo) {
throw new IllegalStateException(MessageFormat.format("Valor tem tamanho fora do intervalo de [{0}-{1}]", minimo, maximo));
throw new NumberFormatException(MessageFormat.format("Valor tem tamanho fora do intervalo de [{0}-{1}]", minimo, maximo));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ public void naoDevePermitirCNPJInvalido() {
dados.setCnpj("1234567890123");
}

@Test(expected = IllegalStateException.class)
@Test(expected = NumberFormatException.class)
public void naoDevePermitirAnoDiferenteDeDuasCasas() {
final NFEventoCancelamentoDados dados = new NFEventoCancelamentoDados();
try {
dados.setAno(9);
} catch (final IllegalStateException e) {
} catch (final NumberFormatException e) {
dados.setAno(100);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import com.fincatto.nfe310.FabricaDeObjetosFake;
import com.fincatto.nfe310.classes.NFUnidadeFederativa;
import com.fincatto.nfe310.classes.nota.NFInfoModelo1Por1AReferenciada;

public class NFInfoModelo1Por1AReferenciadaTest {

Expand All @@ -32,7 +31,7 @@ public void naoDevePermitirNumeroDocumentoFiscalComTamanhoInvalido() {
new NFInfoModelo1Por1AReferenciada().setNumeroDocumentoFiscal("1000000000");
}

@Test(expected = IllegalStateException.class)
@Test(expected = NumberFormatException.class)
public void naoDevePermitirSerieComTamanhoInvalido() {
new NFInfoModelo1Por1AReferenciada().setSerie(1000);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import org.junit.Test;

import com.fincatto.nfe310.classes.NFUnidadeFederativa;
import com.fincatto.nfe310.classes.nota.NFInfoProdutorRuralReferenciada;

public class NFInfoProdutorRuralReferenciadaTest {

Expand All @@ -26,12 +25,12 @@ public void naoDevePermitirCPFComTamanhoInvalido() {
}
}

@Test(expected = IllegalStateException.class)
@Test(expected = NumberFormatException.class)
public void naoDevePermitirSerieDocumentoFiscalComTamanhoInvalido() {
new NFInfoProdutorRuralReferenciada().setSerieDocumentoFiscal(1000);
}

@Test(expected = IllegalStateException.class)
@Test(expected = NumberFormatException.class)
public void naoDevePermitirNumeroDocumentoFiscalComTamanhoInvalido() {
new NFInfoProdutorRuralReferenciada().setNumeroDocumentoFiscal(1000000);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public void naoDevePermitirValorIPINulo() {
new NFInformacaoImpostoDevolvido().toString();
}

@Test(expected = IllegalStateException.class)
@Test(expected = NumberFormatException.class)
public void naoDevePermitirValorIPIInvalido() {
final NFInformacaoImpostoDevolvido informacaoImpostoDevolvido = new NFInformacaoImpostoDevolvido();
informacaoImpostoDevolvido.setValorIPIDevolvido(new BigDecimal("10000000000000.00"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void naoDevePermitirReparticaoFiscalEmitenteComTamanhoInvalido() {
}
}

@Test(expected = IllegalStateException.class)
@Test(expected = NumberFormatException.class)
public void naoDevePermitirValorTotalConstanteDocumentoArrecadacaoReceitaComTamanhoInvalido() {
new NFNotaInfoAvulsa().setValorTotalConstanteDocumentoArrecadacaoReceita(new BigDecimal("10000000000000"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,81 +6,80 @@
import org.junit.Test;

import com.fincatto.nfe310.FabricaDeObjetosFake;
import com.fincatto.nfe310.classes.nota.NFNotaInfoICMSTotal;

public class NFNotaInfoICMSTotalTest {

@Test(expected = IllegalStateException.class)
@Test(expected = NumberFormatException.class)
public void naoDevePermitirValorTotalTributosInvalido() {
new NFNotaInfoICMSTotal().setValorTotalTributos(new BigDecimal("1000000000000000"));
}

@Test(expected = IllegalStateException.class)
@Test(expected = NumberFormatException.class)
public void naoDevePermitirValorTotalSeguroInvalidoMonetario() {
new NFNotaInfoICMSTotal().setValorTotalSeguro(new BigDecimal("1000000000000000"));
}

@Test(expected = IllegalStateException.class)
@Test(expected = NumberFormatException.class)
public void naoDevePermitirValorTotalNFeInvalidoMonetario() {
new NFNotaInfoICMSTotal().setValorTotalNFe(new BigDecimal("1000000000000000"));
}

@Test(expected = IllegalStateException.class)
@Test(expected = NumberFormatException.class)
public void naoDevePermitirValorTotalIPIInvalidoMonetario() {
new NFNotaInfoICMSTotal().setValorTotalIPI(new BigDecimal("1000000000000000"));
}

@Test(expected = IllegalStateException.class)
@Test(expected = NumberFormatException.class)
public void naoDevePermitirValorTotalIIInvalidoMonetario() {
new NFNotaInfoICMSTotal().setValorTotalII(new BigDecimal("1000000000000000"));
}

@Test(expected = IllegalStateException.class)
@Test(expected = NumberFormatException.class)
public void naoDevePermitirValorTotalICMSSTInvalidoMonetario() {
new NFNotaInfoICMSTotal().setValorTotalICMSST(new BigDecimal("1000000000000000"));
}

@Test(expected = IllegalStateException.class)
@Test(expected = NumberFormatException.class)
public void naoDevePermitirValorTotalICMSInvalidoMonetario() {
new NFNotaInfoICMSTotal().setValorTotalICMS(new BigDecimal("1000000000000000"));
}

@Test(expected = IllegalStateException.class)
@Test(expected = NumberFormatException.class)
public void naoDevePermitirValorTotalFreteInvalidoMonetario() {
new NFNotaInfoICMSTotal().setValorTotalFrete(new BigDecimal("1000000000000000"));
}

@Test(expected = IllegalStateException.class)
@Test(expected = NumberFormatException.class)
public void naoDevePermitirValorTotalDosProdutosServicosInvalidoMonetario() {
new NFNotaInfoICMSTotal().setValorTotalDosProdutosServicos(new BigDecimal("1000000000000000"));
}

@Test(expected = IllegalStateException.class)
@Test(expected = NumberFormatException.class)
public void naoDevePermitirValorTotalDescontoInvalidoMonetario() {
new NFNotaInfoICMSTotal().setValorTotalDesconto(new BigDecimal("1000000000000000"));
}

@Test(expected = IllegalStateException.class)
@Test(expected = NumberFormatException.class)
public void naoDevePermitirValorPISInvalidoMonetario() {
new NFNotaInfoICMSTotal().setValorPIS(new BigDecimal("1000000000000000"));
}

@Test(expected = IllegalStateException.class)
@Test(expected = NumberFormatException.class)
public void naoDevePermitirValorCOFINSInvalidoMonetario() {
new NFNotaInfoICMSTotal().setValorCOFINS(new BigDecimal("1000000000000000"));
}

@Test(expected = IllegalStateException.class)
@Test(expected = NumberFormatException.class)
public void naoDevePermitirValorInvalidoMonetario() {
new NFNotaInfoICMSTotal().setValor(new BigDecimal("1000000000000000"));
}

@Test(expected = IllegalStateException.class)
@Test(expected = NumberFormatException.class)
public void naoDevePermitirOutrasDespesasAcessoriasInvalidoMonetario() {
new NFNotaInfoICMSTotal().setOutrasDespesasAcessorias(new BigDecimal("1000000000000000"));
}

@Test(expected = IllegalStateException.class)
@Test(expected = NumberFormatException.class)
public void naoDevePermitirBaseCalculoICMSInvalidoMonetario() {
new NFNotaInfoICMSTotal().setBaseCalculoICMS(new BigDecimal("1000000000000000"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,30 @@
import org.junit.Test;

import com.fincatto.nfe310.FabricaDeObjetosFake;
import com.fincatto.nfe310.classes.nota.NFNotaInfoISSQNTotal;
import com.fincatto.nfe310.classes.nota.NFNotaInfoRegimeEspecialTributacao;

public class NFNotaInfoISSQNTotalTest {

@Test(expected = IllegalStateException.class)
@Test(expected = NumberFormatException.class)
public void naoDevePermitirValorTotalServicosSobNaoIncidenciaNaoTributadosICMSComValorInvalido() {
new NFNotaInfoISSQNTotal().setValorTotalServicosSobNaoIncidenciaNaoTributadosICMS(new BigDecimal("1000000000000000"));
}

@Test(expected = IllegalStateException.class)
@Test(expected = NumberFormatException.class)
public void naoDevePermitirValorTotalISSComValorInvalido() {
new NFNotaInfoISSQNTotal().setValorTotalISS(new BigDecimal("1000000000000000"));
}

@Test(expected = IllegalStateException.class)
@Test(expected = NumberFormatException.class)
public void naoDevePermitirValorPISsobreServicosInvalido() {
new NFNotaInfoISSQNTotal().setValorPISsobreServicos(new BigDecimal("1000000000000000"));
}

@Test(expected = IllegalStateException.class)
@Test(expected = NumberFormatException.class)
public void naoDevePermitirValorCOFINSsobreServicosInvalido() {
new NFNotaInfoISSQNTotal().setValorCOFINSsobreServicos(new BigDecimal("1000000000000000"));
}

@Test(expected = IllegalStateException.class)
@Test(expected = NumberFormatException.class)
public void naoDevePermitirCalculoINSSComValorInvalido() {
new NFNotaInfoISSQNTotal().setValorTotalISS(new BigDecimal("1000000000000000"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@
import com.fincatto.nfe310.classes.NFTipoEmissao;
import com.fincatto.nfe310.classes.NFTipoImpressao;
import com.fincatto.nfe310.classes.NFUnidadeFederativa;
import com.fincatto.nfe310.classes.nota.NFIdentificadorLocalDestinoOperacao;
import com.fincatto.nfe310.classes.nota.NFIndicadorPresencaComprador;
import com.fincatto.nfe310.classes.nota.NFInfoReferenciada;
import com.fincatto.nfe310.classes.nota.NFNotaInfoIdentificacao;
import com.fincatto.nfe310.classes.nota.NFOperacaoConsumidorFinal;

public class NFNotaInfoIdentificacaoTest {

Expand Down Expand Up @@ -89,7 +84,7 @@ public void naoDevePermitirModeloComTamanhoInvalido() {
}
}

@Test(expected = IllegalStateException.class)
@Test(expected = NumberFormatException.class)
public void naoDevePermitirDigitoVerificadorComTamanhoInvalido() {
new NFNotaInfoIdentificacao().setDigitoVerificador(10);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
import org.junit.Test;

import com.fincatto.nfe310.FabricaDeObjetosFake;
import com.fincatto.nfe310.classes.nota.NFNotaInfoItemDetalheExportacao;

public class NFNotaInfoItemDetalheExportacaoTest {

@Test(expected = IllegalStateException.class)
@Test(expected = NumberFormatException.class)
public void naoDevePermitirNumeroAtoConcessorioDrawbackComTamanhoInvalido() {
new NFNotaInfoItemDetalheExportacao().setNumeroAtoConcessorioDrawback(new BigInteger("100000000000"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@

public class NFNotaInfoItemExportacaoIndiretaTest {

@Test(expected = IllegalStateException.class)
@Test(expected = NumberFormatException.class)
public void naoDevePermitirNumeroRegistroExportacaoComTamanhoInvalido() {
new NFNotaInfoItemExportacaoIndireta().setNumeroRegistroExportacao(new BigInteger("1000000000000"));
}

@Test(expected = IllegalStateException.class)
@Test(expected = NumberFormatException.class)
public void naoDevePermitirQuantidadeIemEfetivamenteExportadoComTamanhoInvalido() {
new NFNotaInfoItemExportacaoIndireta().setQuantidadeItemEfetivamenteExportado(new BigDecimal("100000000000"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@

public class NFNotaInfoItemImpostoCOFINSAliquotaTest {

@Test(expected = IllegalStateException.class)
@Test(expected = NumberFormatException.class)
public void naoDevePermitirValorTamanhoInvalido() {
new NFNotaInfoItemImpostoCOFINSAliquota().setValor(new BigDecimal("10000000000000"));
}

@Test(expected = IllegalStateException.class)
@Test(expected = NumberFormatException.class)
public void naoDevePermitirValorBaseCaluloTamanhoInvalido() {
new NFNotaInfoItemImpostoCOFINSAliquota().setValorBaseCalulo(new BigDecimal("10000000000000"));
}

@Test(expected = IllegalStateException.class)
@Test(expected = NumberFormatException.class)
public void naoDevePermitirPercentualAliquotaTamanhoInvalido() {
new NFNotaInfoItemImpostoCOFINSAliquota().setPercentualAliquota(new BigDecimal("1000"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,27 @@

public class NFNotaInfoItemImpostoCOFINSOutrasOperacoesTest {

@Test(expected = IllegalStateException.class)
@Test(expected = NumberFormatException.class)
public void naoDevePermitirPercentualCOFINSComTamanhoInvalido() {
new NFNotaInfoItemImpostoCOFINSOutrasOperacoes().setPercentualCOFINS(new BigDecimal("999999"));
}

@Test(expected = IllegalStateException.class)
@Test(expected = NumberFormatException.class)
public void naoDevePermitirValorBaseCalculoComTamanhoInvalido() {
new NFNotaInfoItemImpostoCOFINSOutrasOperacoes().setValorBaseCalculo(new BigDecimal("99999999999999"));
}

@Test(expected = IllegalStateException.class)
@Test(expected = NumberFormatException.class)
public void naoDevePermitirQuantidadeVendidaComTamanhoInvalido() {
new NFNotaInfoItemImpostoCOFINSOutrasOperacoes().setQuantidadeVendida(new BigDecimal("9999999999999"));
}

@Test(expected = IllegalStateException.class)
@Test(expected = NumberFormatException.class)
public void naoDevePermitirValorCOFINSComTamanhoInvalido() {
new NFNotaInfoItemImpostoCOFINSOutrasOperacoes().setValorCOFINS(new BigDecimal("99999999999999"));
}

@Test(expected = IllegalStateException.class)
@Test(expected = NumberFormatException.class)
public void naoDevePermitirValorAliquotaComTamanhoInvalido() {
new NFNotaInfoItemImpostoCOFINSOutrasOperacoes().setValorAliquota(new BigDecimal("999999999999"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,27 @@

public class NFNotaInfoItemImpostoCOFINSSTTest {

@Test(expected = IllegalStateException.class)
@Test(expected = NumberFormatException.class)
public void naoDevePermitirValorCOFINSForaoDoLimite() {
new NFNotaInfoItemImpostoCOFINSST().setValorCOFINS(new BigDecimal("99999999999999999"));
}

@Test(expected = IllegalStateException.class)
@Test(expected = NumberFormatException.class)
public void naoDevePermitirValorAliquotaCOFINSForaoDoLimite() {
new NFNotaInfoItemImpostoCOFINSST().setValorAliquotaCOFINS(new BigDecimal("99999999999999999"));
}

@Test(expected = IllegalStateException.class)
@Test(expected = NumberFormatException.class)
public void naoDevePermitirQuantidadeVendidaForaDoLimite() {
new NFNotaInfoItemImpostoCOFINSST().setQuantidadeVendida(new BigDecimal("999999999999999999"));
}

@Test(expected = IllegalStateException.class)
@Test(expected = NumberFormatException.class)
public void naoDevePermitirValorPercentualAliquotaCOFINSForaDoLimite() {
new NFNotaInfoItemImpostoCOFINSST().setPercentualAliquota(new BigDecimal("1000.01"));
}

@Test(expected = IllegalStateException.class)
@Test(expected = NumberFormatException.class)
public void naoDevePermitirValorBaseCalculoForaDoLimite() {
new NFNotaInfoItemImpostoCOFINSST().setValorBaseCalculo(new BigDecimal("99999999999999999"));
}
Expand Down
Loading

0 comments on commit 13a9be6

Please sign in to comment.