From 8edbad8659c07a0a8839de5e5223e842a9f44536 Mon Sep 17 00:00:00 2001 From: Enrique Zamudio Date: Mon, 25 Nov 2013 10:55:08 -0600 Subject: [PATCH] BCD tests --- src/test/java/j8583/TestBcd.java | 35 ++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/test/java/j8583/TestBcd.java diff --git a/src/test/java/j8583/TestBcd.java b/src/test/java/j8583/TestBcd.java new file mode 100644 index 0000000..a080ab0 --- /dev/null +++ b/src/test/java/j8583/TestBcd.java @@ -0,0 +1,35 @@ +package j8583; + +import com.solab.iso8583.util.Bcd; +import org.junit.Assert; +import org.junit.Test; + +/** + * BCD encoding tests. + * + * @author Enrique Zamudio + * Date: 25/11/13 10:43 + */ +public class TestBcd { + + @Test + public void testEncoding() { + byte[] buf = new byte[2]; + buf[0] = 1; buf[1]=1; + Bcd.encode("00", buf); + Assert.assertArrayEquals(new byte[]{0, 1}, buf); + Bcd.encode("79", buf); + Assert.assertArrayEquals(new byte[]{0x79, 1}, buf); + Bcd.encode("80", buf); + Assert.assertArrayEquals(new byte[]{(byte)0x80,1}, buf); + Bcd.encode("99", buf); + Assert.assertArrayEquals(new byte[]{(byte)0x99,1}, buf); + Bcd.encode("100", buf); + Assert.assertArrayEquals(new byte[]{1, 0}, buf); + Bcd.encode("779", buf); + Assert.assertArrayEquals(new byte[]{7, 0x79}, buf); + Bcd.encode("999", buf); + Assert.assertArrayEquals(new byte[]{9,(byte)0x99}, buf); + } + +}