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

wmixvideo / nfe / #7148

04 Dec 2025 02:00PM UTC coverage: 52.281% (+25.3%) from 26.996%
#7148

push

web-flow
Ajuste conforme CTe_Nota_Tecnica_2025_001_RTC_v1.10 (#1126)

* Merge from master

* Revert "Merge from master"

This reverts commit e2ed141c3.

* Revert "Revert "Merge from master""

This reverts commit 05781623b.

* Adição do campo indDoacao e grupo de informações de estorno de crédito. Exclusão do grupo de informações do crédito presumido por não se aplicar aos cClassTrib associados ao CTe. Conforme CTe_Nota_Tecnica_2025_001_RTC_v1.10.

103 of 276 new or added lines in 17 files covered. (37.32%)

2968 existing lines in 404 files now uncovered.

14761 of 28234 relevant lines covered (52.28%)

0.52 hits per line

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

88.0
/src/main/java/com/fincatto/documentofiscal/mdfe3/classes/parsers/MDFChaveParser.java
1
package com.fincatto.documentofiscal.mdfe3.classes.parsers;
2

3
import com.fincatto.documentofiscal.DFModelo;
4
import com.fincatto.documentofiscal.DFUnidadeFederativa;
5
import com.fincatto.documentofiscal.mdfe3.classes.def.MDFTipoEmissao;
6
import com.fincatto.documentofiscal.utils.DFUtils;
7
import org.apache.commons.lang3.StringUtils;
8

9
import java.time.LocalDate;
10

11
/**
12
 * Classe responsavel por fazer o parse da chave do MDFe.
13
 */
14
public class MDFChaveParser {
15

16
    private final String chave;
17

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

25
    public String getChave() {
UNCOV
26
        return chave;
×
27
    }
28

29
    public DFUnidadeFederativa getNFUnidadeFederativa() {
30
        return DFUnidadeFederativa.valueOfCodigo(this.chave.substring(0, 2));
1✔
31
    }
32

33
    public LocalDate getDataEmissao() {
34
        return LocalDate.of(this.getDataEmissaoAno(), this.getDataEmissaoMes(), 1);
1✔
35
    }
36

37
    private int getDataEmissaoMes() {
38
        return Integer.parseInt(this.chave.substring(4, 6));
1✔
39
    }
40

41
    private int getDataEmissaoAno() {
42
        return 2000 + Integer.parseInt(this.chave.substring(2, 4));
1✔
43
    }
44

45
    /**
46
     * Returna o CNPJ do emitente da chave.<br>
47
     * Se nao for um CNPJ valido, retorna nulo.
48
     *
49
     * @return CNPJ do emitente ou nulo.
50
     */
51
    public String getCnpjEmitente() {
52
        return isEmitentePessoaJuridica() ? this.chave.substring(6, 20) : null;
1✔
53
    }
54

55
    /**
56
     * Returna o CPF do emitente da chave.<br>
57
     * Se nao for um CPF valido, retorna nulo.
58
     *
59
     * @return CPF do emitente ou nulo.
60
     */
61
    public String getCpfEmitente() {
62
        return isEmitentePessoaFisica() ? this.chave.substring(9, 20) : null;
1✔
63
    }
64

65
    public DFModelo getModelo() {
66
        return DFModelo.valueOfCodigo(this.chave.substring(20, 22));
1✔
67
    }
68

69
    public String getSerie() {
70
        return this.chave.substring(22, 25);
1✔
71
    }
72

73
    public String getNumero() {
UNCOV
74
        return this.chave.substring(25, 34);
×
75
    }
76

77
    public MDFTipoEmissao getFormaEmissao() {
78
        return MDFTipoEmissao.valueOfCodigo(this.chave.substring(34, 35));
1✔
79
    }
80

81
    public String getCodigoNumerico() {
82
        return this.chave.substring(35, 43);
1✔
83
    }
84

85
    public String getDV() {
86
        return this.chave.substring(43, 44);
1✔
87
    }
88

89
    public String getFormatado() {
90
        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✔
91
    }
92

93
    /**
94
     * Indica se o emitente da chave eh pessoa fisica.
95
     *
96
     * @return Se chave foi emitida por pessoa fisica.
97
     */
98
    public boolean isEmitentePessoaFisica() {
99
        return DFUtils.isCpfValido(this.chave.substring(9, 20)) && this.isSerieReservadaPessoaFisica();
1✔
100
    }
101

102
    /**
103
     * Indica se o emitente da chave eh pessoa juridica.
104
     *
105
     * @return Se chave foi emitida por pessoa juridica.
106
     */
107
    public boolean isEmitentePessoaJuridica() {
108
        return DFUtils.isCnpjValido(this.chave.substring(6, 20)) && !this.isSerieReservadaPessoaFisica();
1✔
109
    }
110

111
    /**
112
     * Indica se a chave é de uma série destinada a pessoa física.<br>
113
     * De acordo com a documentação: "Será reservada uma faixa do campo Série do MDF-e (920-969), como forma de identificação da Emitente pessoa física (CPF);"<br>
114
     * <a href="http://sped.rfb.gov.br/estatico/8A/16CC5375F0AC1A0B7666221FC2116325133C01/MOC_MDFe_VisaoGeral_v3.00a.pdf">...</a>
115
     *
116
     * @return se a serie é destinada a pessoa física.
117
     */
118
    public boolean isSerieReservadaPessoaFisica() {
119
        if (DFUtils.isNumerico(this.getSerie())) {
1✔
120
            final int serie = Integer.parseInt(this.getSerie());
1✔
121
            return serie >= 920 && serie <= 969;
1✔
122
        }
UNCOV
123
        return false;
×
124
    }
125
}
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