Skip to content

Commit

Permalink
Merge pull request #92 from wmixvideo/dev
Browse files Browse the repository at this point in the history
Limpeza de projeto e cobertura de testes
  • Loading branch information
jefperito committed Nov 16, 2015
2 parents a0e754d + de347c9 commit d6551e7
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 138 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.Date;
import java.util.GregorianCalendar;

import com.fincatto.nfe310.classes.NFTipoEmissao;
import com.fincatto.nfe310.classes.NFUnidadeFederativa;

public class NotaFiscalChaveParser {
Expand Down Expand Up @@ -43,8 +44,8 @@ public String getNumero() {
return this.chave.substring(25, 34);
}

public String getFormaEmissao() {
return this.chave.substring(34, 35);
public NFTipoEmissao getFormaEmissao() {
return NFTipoEmissao.valueOfCodigo(this.chave.substring(34, 35));
}

public String getCodigoNumerico() {
Expand Down
68 changes: 0 additions & 68 deletions src/main/java/com/fincatto/nfe310/validadores/xsd/ErroHandler.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,30 @@ public void naoDevePermitirQuantidadeItemEfetivamenteExportadoNulo() {
exportacaoIndireta.toString();
}

@Test
public void deveObterChaveAcessoNFeComoFoiSetado() {
final NFNotaInfoItemExportacaoIndireta exportacaoIndireta = new NFNotaInfoItemExportacaoIndireta();
final String chaveAcessoNFe = "99921995966146649003423495876439081543214139";
exportacaoIndireta.setChaveAcessoNFe(chaveAcessoNFe);
Assert.assertEquals(chaveAcessoNFe, exportacaoIndireta.getChaveAcessoNFe());
}

@Test
public void deveObterNumeroRegistroExportacaoComoFoiSetado() {
final NFNotaInfoItemExportacaoIndireta exportacaoIndireta = new NFNotaInfoItemExportacaoIndireta();
final BigInteger numeroRegistroExportacao = new BigInteger("999999999999");
exportacaoIndireta.setNumeroRegistroExportacao(numeroRegistroExportacao);
Assert.assertEquals(numeroRegistroExportacao, exportacaoIndireta.getNumeroRegistroExportacao());
}

@Test
public void deveObterQuantidadeItemEfetivamenteExportadoComoFoiSetado() {
final NFNotaInfoItemExportacaoIndireta exportacaoIndireta = new NFNotaInfoItemExportacaoIndireta();
final String quantidadeItemEfetivamenteExportado = "9999999999.9999";
exportacaoIndireta.setQuantidadeItemEfetivamenteExportado(new BigDecimal(quantidadeItemEfetivamenteExportado));
Assert.assertEquals(quantidadeItemEfetivamenteExportado, exportacaoIndireta.getQuantidadeItemEfetivamenteExportado());
}

@Test
public void deveGerarXMLDeAcordoComOPadraoEstabelecidoComVagao() {
final String xmlEsperado = "<NFNotaInfoItemExportacaoIndireta><nRE>999999999999</nRE><chNFe>99921995966146649003423495876439081543214139</chNFe><qExport>9999999999.9999</qExport></NFNotaInfoItemExportacaoIndireta>";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package com.fincatto.nfe310.parsers;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.junit.Assert;
import org.junit.Test;

import com.fincatto.nfe310.classes.NFTipoEmissao;
import com.fincatto.nfe310.classes.NFUnidadeFederativa;

public class NotaFiscalChaveParserTest {

@Test(expected = IllegalArgumentException.class)
public void naoDevePermitirChaveDeTamanhoInvalido() {
try {
new NotaFiscalChaveParser(null);
Assert.fail();
} catch (final IllegalArgumentException e) {

}
try {
new NotaFiscalChaveParser("1734119042676883974264088457913359614139959");
Assert.fail();
} catch (final IllegalArgumentException e) {
new NotaFiscalChaveParser("173411904267688397426408845791335961413995927");
Assert.fail();
}
}

@Test
public void deveObterUFDeChave() {
Assert.assertEquals(NFUnidadeFederativa.SC, new NotaFiscalChaveParser("42341190426768839742640884579133596141399591").getNFUnidadeFederativa());
}

@Test
public void deveObterDataDeEmissaoDaChave() throws ParseException {
final Date dataEsperada = new SimpleDateFormat("yyyy/MM").parse("2015/11");
Assert.assertEquals(dataEsperada, new NotaFiscalChaveParser("42151190426768839742640884579133596141399591").getDataEmissao());
}

@Test
public void deveObterCNPJEmitenteDaChave() {
Assert.assertEquals("03918609000132", new NotaFiscalChaveParser("42151103918609000132640884579133596141399591").getCnpjEmitente());
}

@Test
public void deveObterSerieDaChave() {
Assert.assertEquals("088", new NotaFiscalChaveParser("42151103918609000132640884579133596141399591").getSerie());
}

@Test
public void deveObterNumeroDaChave() {
Assert.assertEquals("457913359", new NotaFiscalChaveParser("42151103918609000132640884579133596141399591").getNumero());
}

@Test
public void deveObterFormaEmissaoDaChave() {
Assert.assertEquals(NFTipoEmissao.EMISSAO_NORMAL, new NotaFiscalChaveParser("42151103918609000132640884579133591141399591").getFormaEmissao());
}

@Test
public void deveObterCodigoNumericoDaChave() {
Assert.assertEquals("14139959", new NotaFiscalChaveParser("42151103918609000132640884579133591141399591").getCodigoNumerico());
}

@Test
public void deveObterDivisorDaChave() {
Assert.assertEquals("1", new NotaFiscalChaveParser("42151103918609000132640884579133591141399591").getDV());
}

@Test
public void naoDeveSerNotaEmitidaEmContigencia() {
Assert.assertFalse(new NotaFiscalChaveParser("42151103918609000132640884579133596141399591").isEmitidaContingenciaSCAN());
}

@Test
public void deveSerNotaEmitidaEmContigencia() {
Assert.assertTrue(new NotaFiscalChaveParser("42151103918609000132649884579133596141399591").isEmitidaContingenciaSCAN());
}

@Test
public void deveFormatarChave() {
Assert.assertEquals("4215 1103 9186 0900 0132 6408 8457 9133 5961 4139 9591", new NotaFiscalChaveParser("42151103918609000132640884579133596141399591").getFormatado());
}
}

0 comments on commit d6551e7

Please sign in to comment.