Fix debugString for variable-length fields

This commit is contained in:
Enrique Zamudio
2013-06-25 12:37:41 -05:00
parent 6bdd26fadf
commit 61fded16d2
2 changed files with 11 additions and 1 deletions
@@ -453,7 +453,13 @@ public class IsoMessage {
for (int i = 2; i < 129; i++) {
IsoValue<?> v = fields[i];
if (v != null) {
sb.append(v);
String desc = v.toString();
if (v.getType() == IsoType.LLBIN || v.getType() == IsoType.LLVAR) {
sb.append(String.format("%02d", desc.length()));
} else if (v.getType() == IsoType.LLLBIN || v.getType() == IsoType.LLLVAR) {
sb.append(String.format("%03d", desc.length()));
}
sb.append(desc);
}
}
return sb.toString();
+4
View File
@@ -5,6 +5,7 @@ import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.text.ParseException;
import com.solab.iso8583.IsoType;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@@ -84,7 +85,10 @@ public class TestBinaries {
testParsed(bin2);
Assert.assertEquals(bin.getObjectValue(7).toString(), bin2.getObjectValue(7).toString());
//Test the debug string
ascii.setValue(60, "XXX", IsoType.LLVAR, 0);
bin.setValue(60, "XXX", IsoType.LLVAR, 0);
Assert.assertEquals("Debug strings differ", ascii.debugString(), bin.debugString());
Assert.assertTrue("LLVAR fields wrong", ascii.debugString().contains("03XXX"));
}
@Test