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

wmixvideo / nfe / #9463

23 Jul 2025 01:31AM UTC coverage: 51.794% (+0.8%) from 50.977%
#9463

push

web-flow
Merge e37a5245a into cb8c6ab74

122 of 122 new or added lines in 1 file covered. (100.0%)

1090 existing lines in 75 files now uncovered.

14360 of 27725 relevant lines covered (51.79%)

0.52 hits per line

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

0.0
/src/main/java/com/fincatto/documentofiscal/mdfe3/utils/MDFGeraChave.java
1
package com.fincatto.documentofiscal.mdfe3.utils;
2

3
import com.fincatto.documentofiscal.mdfe3.classes.nota.MDFInfoIdentificacao;
4
import com.fincatto.documentofiscal.mdfe3.classes.nota.MDFe;
5
import org.apache.commons.lang3.StringUtils;
6

7
import java.time.format.DateTimeFormatter;
8
import java.util.Random;
9

10
public class MDFGeraChave {
11

12
    private final MDFe mdfe;
13

UNCOV
14
    public MDFGeraChave(MDFe nota) {
×
UNCOV
15
        this.mdfe = nota;
×
UNCOV
16
    }
×
17

18
    public String geraCodigoRandomico() {
UNCOV
19
        final Random random = new Random(this.mdfe.getInfo().getIdentificacao().getDataEmissao().toInstant().toEpochMilli());
×
UNCOV
20
        return StringUtils.leftPad(String.valueOf(random.nextInt(100000000)), 8, "0");
×
21
    }
22

23
    public String getChaveAcesso() {
24
        return String.format("%s%s", this.geraChaveAcessoSemDV(), this.getDV());
×
25
    }
26

27
    public Integer getDV() {
UNCOV
28
        final char[] valores = this.geraChaveAcessoSemDV().toCharArray();
×
UNCOV
29
        final int[] valoresInt = {2, 3, 4, 5, 6, 7, 8, 9};
×
UNCOV
30
        int indice = 0;
×
UNCOV
31
        int soma = 0;
×
32
        int valorTemp;
33
        int multTemp;
UNCOV
34
        for (int i = valores.length; i > 0; i--) {
×
UNCOV
35
            if (indice >= valoresInt.length) {
×
UNCOV
36
                indice = 0;
×
37
            }
38

UNCOV
39
            valorTemp = Integer.parseInt(String.valueOf(valores[i - 1]));
×
UNCOV
40
            multTemp = valoresInt[indice++];
×
UNCOV
41
            soma += valorTemp * multTemp;
×
42
        }
UNCOV
43
        final int dv = 11 - (soma % 11);
×
UNCOV
44
        return ((dv == 11) || (dv == 10)) ? 0 : dv;
×
45
    }
46

47
    private String geraChaveAcessoSemDV() {
UNCOV
48
        if (StringUtils.isBlank(this.mdfe.getInfo().getIdentificacao().getCodigoNumerico())) {
×
UNCOV
49
            throw new IllegalStateException("Codigo numerico deve estar presente para gerar a chave de acesso");
×
50
        }
UNCOV
51
        return StringUtils.leftPad(this.mdfe.getInfo().getIdentificacao().getCodigoUF().getCodigoIbge(), 2, "0") + StringUtils.leftPad(DateTimeFormatter.ofPattern("yyMM").format(this.mdfe.getInfo().getIdentificacao().getDataEmissao()), 4, "0") + StringUtils.leftPad(this.mdfe.getInfo().getEmitente().getCpfj(), 14, "0") + StringUtils.leftPad(MDFInfoIdentificacao.MOD.getCodigo(), 2, "0") + StringUtils.leftPad(this.mdfe.getInfo().getIdentificacao().getSerie() + "", 3, "0") + StringUtils.leftPad(this.mdfe.getInfo().getIdentificacao().getNumero() + "", 9, "0") + StringUtils.leftPad(this.mdfe.getInfo().getIdentificacao().getTipoEmissao().getCodigo(), 1, "0") + StringUtils.leftPad(this.mdfe.getInfo().getIdentificacao().getCodigoNumerico(), 8, "0");
×
52
    }
53
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc