@Override public void encodeLength(int length, byte[] b) { for (int i = getPackedLength() - 1; i >= 0; i--) { int twoDigits = length % 100; length /= 100; b[i] = (byte)((twoDigits / 10 << 4) + twoDigits % 10); } }
public void testReversability() throws Exception { int len = 3; byte[] b = new byte[1]; BcdPrefixer.LL.encodeLength(len, b); assertEquals(len, BcdPrefixer.LL.decodeLength(b, 0)); } }
@Test public void testConstructor() throws Throwable { BcdPrefixer bcdPrefixer = new BcdPrefixer(100); assertEquals("bcdPrefixer.getPackedLength()", 50, bcdPrefixer.getPackedLength()); }
@Test public void testDecodeLength() throws Throwable { byte[] b = new byte[1]; int result = new BcdPrefixer(0).decodeLength(b, 100); assertEquals("result", 0, result); }
public void testEncode() throws Exception { byte[] b = new byte[1]; BcdPrefixer.LL.encodeLength(21, b); TestUtils.assertEquals(new byte[]{0x21}, b); }
@Test public void testEncodeLength1() throws Throwable { byte[] b = new byte[1]; new BcdPrefixer(0).encodeLength(100, b); assertEquals("b.length", 1, b.length); }
public void testDecode() throws Exception { byte[] b = new byte[]{0x25}; assertEquals(25, BcdPrefixer.LL.decodeLength(b, 0)); }
@Test public void testGetPackedLength1() throws Throwable { int result = new BcdPrefixer(100).getPackedLength(); assertEquals("result", 50, result); } }
@Test public void testDecodeLengthThrowsNullPointerException() throws Throwable { try { new BcdPrefixer(100).decodeLength(null, 100); fail("Expected NullPointerException to be thrown"); } catch (NullPointerException ex) { assertNull("ex.getMessage()", ex.getMessage()); } }
public void testEncodeLLL() throws Exception { byte[] b = new byte[2]; BcdPrefixer.LLL.encodeLength(321, b); TestUtils.assertEquals(new byte[]{0x03, 0x21}, b); }
public void testDecode19() throws Exception { byte[] b = new byte[]{0x19}; assertEquals(19, BcdPrefixer.LL.decodeLength(b, 0)); }
@Test public void testGetPackedLength() throws Throwable { int result = new BcdPrefixer(0).getPackedLength(); assertEquals("result", 0, result); }
@Test public void testDecodeLengthThrowsArrayIndexOutOfBoundsException() throws Throwable { byte[] b = new byte[1]; try { new BcdPrefixer(100).decodeLength(b, 0); fail("Expected ArrayIndexOutOfBoundsException to be thrown"); } catch (ArrayIndexOutOfBoundsException ex) { assertEquals("ex.getMessage()", "1", ex.getMessage()); } }
@Test(expected = NullPointerException.class) public void testEncodeLengthThrowsNullPointerException() throws Throwable { BcdPrefixer.L.encodeLength(100, null); }
public void testDecode99() throws Exception { byte[] b = new byte[]{(byte)0x99}; assertEquals(99, BcdPrefixer.LL.decodeLength(b, 0)); }
public void testEncodeShortLength() throws Exception { byte[] b = new byte[1]; BcdPrefixer.LL.encodeLength(3, b); TestUtils.assertEquals(new byte[]{0x03}, b); }
@Test public void testDecodeLength1() throws Throwable { byte[] bytes = new byte[1]; bytes[0] = (byte) 37; int result = BcdPrefixer.LL.decodeLength(bytes, 0); assertEquals("result", 25, result); }
public void testEncodeLLLShortLength() throws Exception { byte[] b = new byte[2]; BcdPrefixer.LLL.encodeLength(3, b); TestUtils.assertEquals(new byte[]{0x00, 0x03}, b); }
public void testEncode99() throws Exception { byte[] b = new byte[1]; BcdPrefixer.LL.encodeLength(99, b); TestUtils.assertEquals(new byte[]{(byte)0x99}, b); }
@Test public void testEncodeLength() throws Throwable { byte[] bytes = new byte[2]; BcdPrefixer.LLL.encodeLength(100, bytes); assertEquals("bytes[0]", (byte) 1, bytes[0]); }