• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

wmixvideo / nfe / #6844

13 Oct 2025 01:26PM UTC coverage: 52.219% (+0.06%) from 52.162%
#6844

push

fincatto
Removido validacao de set de CPF e CNPJ.

0 of 5 new or added lines in 1 file covered. (0.0%)

1 existing line in 1 file now uncovered.

14543 of 27850 relevant lines covered (52.22%)

0.52 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

82.14
/src/main/java/com/fincatto/documentofiscal/nfe400/NotaFiscalChaveParser.java
1
package com.fincatto.documentofiscal.nfe400;
2

3
import com.fincatto.documentofiscal.DFModelo;
4
import com.fincatto.documentofiscal.DFUnidadeFederativa;
5
import com.fincatto.documentofiscal.nfe.NFTipoEmissao;
6
import com.fincatto.documentofiscal.utils.DFUtils;
7
import org.apache.commons.lang3.StringUtils;
8

9
import java.time.LocalDate;
10

11
public class NotaFiscalChaveParser {
12

13
    private final String chave;
14

15
    public NotaFiscalChaveParser(final String chave) {
1✔
16
        this.chave = StringUtils.stripToEmpty(chave).replaceAll("\\D", "");
1✔
17
        if (this.chave.length() != 44) {
1✔
18
            throw new IllegalArgumentException(String.format("A chave deve ter exatos 44 caracteres numericos: %s", chave));
1✔
19
        }
20
    }
1✔
21

22
    public String getChave() {
23
        return this.chave;
×
24
    }
25

26
    public DFUnidadeFederativa getNFUnidadeFederativa() {
27
        return DFUnidadeFederativa.valueOfCodigo(this.chave.substring(0, 2));
1✔
28
    }
29

30
    public LocalDate getDataEmissao() {
31
        return LocalDate.of(this.getDataEmissaoAno(), this.getDataEmissaoMes(), 1);
1✔
32
    }
33

34
    private int getDataEmissaoMes() {
35
        return Integer.parseInt(this.chave.substring(4, 6));
1✔
36
    }
37

38
    private int getDataEmissaoAno() {
39
        return 2000 + Integer.parseInt(this.chave.substring(2, 4));
1✔
40
    }
41

42
    public DFModelo getModelo() {
43
        return DFModelo.valueOfCodigo(this.chave.substring(20, 22));
×
44
    }
45

46
    public String getSerie() {
47
        return this.chave.substring(22, 25);
1✔
48
    }
49

50
    public String getNumero() {
51
        return this.chave.substring(25, 34);
1✔
52
    }
53

54
    public NFTipoEmissao getFormaEmissao() {
55
        return NFTipoEmissao.valueOfCodigo(this.chave.substring(34, 35));
1✔
56
    }
57

58
    public String getCodigoNumerico() {
59
        return this.chave.substring(35, 43);
1✔
60
    }
61

62
    public String getDV() {
63
        return this.chave.substring(43, 44);
1✔
64
    }
65

66
    public boolean isEmitidaContingenciaSCAN() {
67
        return this.getSerie().matches("9[0-9]{2}");
1✔
68
    }
69

70
    public boolean isEmitidaContingenciaSCVAN() {
71
        return this.chave.matches("\\d{34}6\\d{9}");
×
72
    }
73

74
    public boolean isEmitidaContingenciaSCVRS() {
75
        return this.chave.matches("\\d{34}7\\d{9}");
×
76
    }
77

78
    public String getFormatado() {
79
        return this.chave.replaceFirst("(\\d{4})(\\d{4})(\\d{4})(\\d{4})(\\d{4})(\\d{4})(\\d{4})(\\d{4})(\\d{4})(\\d{4})(\\d{4})", "$1 $2 $3 $4 $5 $6 $7 $8 $9 $10 $11");
1✔
80
    }
81

82
    /**
83
     * Indica se o emitente da chave eh pessoa fisica.
84
     * @return Se chave foi emitida por pessoa fisica.
85
     */
86
    public boolean isEmitentePessoaFisica() {
87
        return DFUtils.isCpfValido(this.chave.substring(9, 20)) && this.isSerieReservadaPessoaFisica();
1✔
88
    }
89

90
    /**
91
     * Indica se o emitente da chave eh pessoa juridica.
92
     * @return Se chave foi emitida por pessoa juridica.
93
     */
94
    public boolean isEmitentePessoaJuridica() {
95
        return DFUtils.isCnpjValido(this.chave.substring(6, 20)) && !this.isSerieReservadaPessoaFisica();
1✔
96
    }
97

98
    /**
99
     * Returna o CNPJ do emitente da chave.<br>
100
     * Se nao for um CNPJ valido, retorna nulo.
101
     *
102
     * @return CNPJ do emitente ou nulo.
103
     */
104
    public String getCnpjEmitente() {
105
        return isEmitentePessoaJuridica() ? this.chave.substring(6, 20) : null;
1✔
106
    }
107

108
    /**
109
     * Returna o CPF do emitente da chave.<br>
110
     * Se nao for um CPF valido, retorna nulo.
111
     *
112
     * @return CPF do emitente ou nulo.
113
     */
114
    public String getCpfEmitente() {
115
        return isEmitentePessoaFisica() ? this.chave.substring(9, 20) : null;
1✔
116
    }
117

118
    /**
119
     * Indica se a chave é de uma série destinada a pessoa física.<br>
120
     * De acordo com a documentação: "O CPF deverá constar na Chave de Acesso, precedido por zeros, completando 14 posições; Deverá utilizar a série reservada [920-969]"<br>
121
     * <a href="https://www.nfe.fazenda.gov.br/portal/exibirArquivo.aspx?conteudo=4m9xb5EYa/w=">...</a>
122
     *
123
     * @return se a serie é destinada a pessoa física.
124
     */
125
    public boolean isSerieReservadaPessoaFisica() {
126
        if (DFUtils.isNumerico(this.getSerie())) {
1✔
127
            final int serie = Integer.parseInt(this.getSerie());
1✔
128
            return serie >= 920 && serie <= 969;
1✔
129
        }
UNCOV
130
        return false;
×
131
    }
132
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc