Skip to content

Commit

Permalink
ajustado conversao de codigo para tipo veiculo (#1020)
Browse files Browse the repository at this point in the history
Co-authored-by: Giovane Boeing <giovane@brazilsistem.com.br>
  • Loading branch information
giovaneboeing and Giovane Boeing authored Jan 8, 2025
1 parent 96375da commit 430f211
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.fincatto.documentofiscal.nfe400.classes;

import org.apache.commons.lang3.StringUtils;

public enum NFNotaInfoTipoVeiculo {

CICLOMOTO("2", "Ciclomotor"),
Expand All @@ -26,8 +24,6 @@ public enum NFNotaInfoTipoVeiculo {
UTILITARIO("25","Utilit\u00e1rio"),
MOTOR_CASA("26","Motor Casa");



private final String codigo;
private final String descricao;

Expand All @@ -41,8 +37,13 @@ public String getCodigo() {
}

public static NFNotaInfoTipoVeiculo valueOfCodigo(final String codigo) {
if (codigo == null || codigo.isEmpty()) {
return null;
}

final int codigoAsInt = Integer.parseInt(codigo);
for (final NFNotaInfoTipoVeiculo tipoVeiculo : NFNotaInfoTipoVeiculo.values()) {
if (tipoVeiculo.getCodigo().equals(codigo)) {
if (Integer.parseInt(tipoVeiculo.getCodigo()) == codigoAsInt) {
return tipoVeiculo;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,45 @@ public void deveRepresentarOCodigoCorretamente() {
Assert.assertEquals("24", NFNotaInfoTipoVeiculo.CARGA_CAM.getCodigo());
Assert.assertEquals("25", NFNotaInfoTipoVeiculo.UTILITARIO.getCodigo());
Assert.assertEquals("26", NFNotaInfoTipoVeiculo.MOTOR_CASA.getCodigo());
}

@Test
public void deveConverterCodigoParaEnum() {
Assert.assertEquals(NFNotaInfoTipoVeiculo.CICLOMOTO, NFNotaInfoTipoVeiculo.valueOfCodigo("2"));
Assert.assertEquals(NFNotaInfoTipoVeiculo.CICLOMOTO, NFNotaInfoTipoVeiculo.valueOfCodigo("02"));
Assert.assertEquals(NFNotaInfoTipoVeiculo.MOTONETA, NFNotaInfoTipoVeiculo.valueOfCodigo("3"));
Assert.assertEquals(NFNotaInfoTipoVeiculo.MOTONETA, NFNotaInfoTipoVeiculo.valueOfCodigo("003"));
Assert.assertEquals(NFNotaInfoTipoVeiculo.MOTOCICLO, NFNotaInfoTipoVeiculo.valueOfCodigo("4"));
Assert.assertEquals(NFNotaInfoTipoVeiculo.MOTOCICLO, NFNotaInfoTipoVeiculo.valueOfCodigo("0004"));
Assert.assertEquals(NFNotaInfoTipoVeiculo.TRICICLO, NFNotaInfoTipoVeiculo.valueOfCodigo("5"));
Assert.assertEquals(NFNotaInfoTipoVeiculo.TRICICLO, NFNotaInfoTipoVeiculo.valueOfCodigo("05"));
Assert.assertEquals(NFNotaInfoTipoVeiculo.AUTOMOVEL, NFNotaInfoTipoVeiculo.valueOfCodigo("6"));
Assert.assertEquals(NFNotaInfoTipoVeiculo.AUTOMOVEL, NFNotaInfoTipoVeiculo.valueOfCodigo("06"));
Assert.assertEquals(NFNotaInfoTipoVeiculo.MICROONIBUS, NFNotaInfoTipoVeiculo.valueOfCodigo("7"));
Assert.assertEquals(NFNotaInfoTipoVeiculo.MICROONIBUS, NFNotaInfoTipoVeiculo.valueOfCodigo("07"));
Assert.assertEquals(NFNotaInfoTipoVeiculo.ONIBUS, NFNotaInfoTipoVeiculo.valueOfCodigo("8"));
Assert.assertEquals(NFNotaInfoTipoVeiculo.ONIBUS, NFNotaInfoTipoVeiculo.valueOfCodigo("08"));
Assert.assertEquals(NFNotaInfoTipoVeiculo.REBOQUE, NFNotaInfoTipoVeiculo.valueOfCodigo("10"));
Assert.assertEquals(NFNotaInfoTipoVeiculo.SEMIRREBOQUE, NFNotaInfoTipoVeiculo.valueOfCodigo("11"));
Assert.assertEquals(NFNotaInfoTipoVeiculo.CAMINHONETA, NFNotaInfoTipoVeiculo.valueOfCodigo("13"));
Assert.assertEquals(NFNotaInfoTipoVeiculo.CAMINHAO, NFNotaInfoTipoVeiculo.valueOfCodigo("14"));
Assert.assertEquals(NFNotaInfoTipoVeiculo.TRATOR, NFNotaInfoTipoVeiculo.valueOfCodigo("17"));
Assert.assertEquals(NFNotaInfoTipoVeiculo.TRATOR_RODAS, NFNotaInfoTipoVeiculo.valueOfCodigo("18"));
Assert.assertEquals(NFNotaInfoTipoVeiculo.TRATOR_ESTEIRAS, NFNotaInfoTipoVeiculo.valueOfCodigo("19"));
Assert.assertEquals(NFNotaInfoTipoVeiculo.TRATOR_MISTO, NFNotaInfoTipoVeiculo.valueOfCodigo("20"));
Assert.assertEquals(NFNotaInfoTipoVeiculo.QUADRICICLO, NFNotaInfoTipoVeiculo.valueOfCodigo("21"));
Assert.assertEquals(NFNotaInfoTipoVeiculo.ESP_ONIBUS, NFNotaInfoTipoVeiculo.valueOfCodigo("22"));
Assert.assertEquals(NFNotaInfoTipoVeiculo.MISTO_CAM, NFNotaInfoTipoVeiculo.valueOfCodigo("23"));
Assert.assertEquals(NFNotaInfoTipoVeiculo.CARGA_CAM, NFNotaInfoTipoVeiculo.valueOfCodigo("24"));
Assert.assertEquals(NFNotaInfoTipoVeiculo.UTILITARIO, NFNotaInfoTipoVeiculo.valueOfCodigo("25"));
Assert.assertEquals(NFNotaInfoTipoVeiculo.MOTOR_CASA, NFNotaInfoTipoVeiculo.valueOfCodigo("26"));
}




@Test
public void condigoInvalidoRetornaNulo() {
Assert.assertNull(NFNotaInfoTipoVeiculo.valueOfCodigo("27"));
Assert.assertNull(NFNotaInfoTipoVeiculo.valueOfCodigo("0"));
Assert.assertNull(NFNotaInfoTipoVeiculo.valueOfCodigo(""));
Assert.assertNull(NFNotaInfoTipoVeiculo.valueOfCodigo(null));
}
}

0 comments on commit 430f211

Please sign in to comment.