moved tests to proper packages
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
package com.solab.iso8583.util;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecoding() {
|
||||
byte[] buf = new byte[2];
|
||||
Assert.assertEquals(0, Bcd.decodeToLong(buf, 0, 1));
|
||||
Assert.assertEquals(0, Bcd.decodeToLong(buf, 0, 2));
|
||||
Assert.assertEquals(0, Bcd.decodeToLong(buf, 0, 3));
|
||||
Assert.assertEquals(0, Bcd.decodeToLong(buf, 0, 4));
|
||||
buf[0]=0x79;
|
||||
Assert.assertEquals(79, Bcd.decodeToLong(buf, 0, 2));
|
||||
buf[0]=(byte)0x80;
|
||||
Assert.assertEquals(80, Bcd.decodeToLong(buf, 0, 2));
|
||||
buf[0]=(byte)0x99;
|
||||
Assert.assertEquals(99, Bcd.decodeToLong(buf, 0, 2));
|
||||
buf[0]=1;
|
||||
Assert.assertEquals(100, Bcd.decodeToLong(buf,0,4));
|
||||
buf[1]=0x79;
|
||||
Assert.assertEquals(179, Bcd.decodeToLong(buf,0,4));
|
||||
buf[1]=(byte)0x99;
|
||||
Assert.assertEquals(199, Bcd.decodeToLong(buf,0,4));
|
||||
buf[0]=9;
|
||||
Assert.assertEquals(999, Bcd.decodeToLong(buf,0,4));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.solab.iso8583.util;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestHexCodec {
|
||||
|
||||
public void encodeDecode(String hex) {
|
||||
byte[] buf = HexCodec.hexDecode(hex);
|
||||
Assert.assertEquals((hex.length() / 2) + (hex.length() % 2), buf.length);
|
||||
String reenc = HexCodec.hexEncode(buf, 0, buf.length);
|
||||
if (reenc.startsWith("0") && !hex.startsWith("0")) {
|
||||
Assert.assertEquals(reenc.substring(1), hex);
|
||||
} else {
|
||||
Assert.assertEquals(hex, reenc);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCodec() {
|
||||
byte[] buf = HexCodec.hexDecode("A");
|
||||
Assert.assertEquals(0x0a, buf[0]);
|
||||
encodeDecode("A");
|
||||
encodeDecode("0123456789ABCDEF");
|
||||
buf = HexCodec.hexDecode("0123456789ABCDEF");
|
||||
Assert.assertEquals(1, buf[0]);
|
||||
Assert.assertEquals(0x23, buf[1]);
|
||||
Assert.assertEquals(0x45, buf[2]);
|
||||
Assert.assertEquals(0x67, buf[3]);
|
||||
Assert.assertEquals(0x89, (buf[4] & 0xff));
|
||||
Assert.assertEquals(0xab, (buf[5] & 0xff));
|
||||
Assert.assertEquals(0xcd, (buf[6] & 0xff));
|
||||
Assert.assertEquals(0xef, (buf[7] & 0xff));
|
||||
buf = HexCodec.hexDecode("ABC");
|
||||
Assert.assertEquals(0x0a, (buf[0] & 0xff));
|
||||
Assert.assertEquals(0xbc, (buf[1] & 0xff));
|
||||
encodeDecode("ABC");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPartial() {
|
||||
Assert.assertEquals("FF01", HexCodec.hexEncode(new byte[]{0, (byte)0xff, 1, 2, 3, 4},
|
||||
1, 2));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user