Data { public long getLongInteger() { int length = getByte(); if (pointer + length > data.length) { throw new IndexOutOfBoundsException("Not enough data"); } if (length == 0) { throw new RuntimeException("Length must not be zero"); } StringBuilder sb = new StringBuilder(); for (int i = 0; i < length; i++) { sb.append(getChar()); } return Long.parseLong(sb.toString()); } Data(byte[] data); int getUnsignedInt(); int getByte(); char getChar(); long getLongInteger(); String getString(); byte[] getBuffer(); String getPointer(); long getTime(); Hashtable getHashtable(); Hdata getHdata(); Info getInfo(); Infolist getInfolist(); Array getArray(); RelayObject getObject(); byte[] getByteArray(); boolean empty();  }
@Test public void testGetLongInteger() throws UnsupportedEncodingException { long testCases[] = new long[] {260L, 0L, -99999999L, 99999999L, 1234567890L, -0L, Long.MAX_VALUE, Long.MIN_VALUE}; for (int i=0; i<testCases.length; i++) { long o = testCases[i]; Data d = new Data(DataTest.constructWeechatLong(o)); long l = d.getLongInteger(); assertEquals(o, l); d = new Data(DataTest.constructWeechatLong(o)); l = d.getTime(); assertEquals(o,l); } }
@Test(expected = IndexOutOfBoundsException.class) public void testGetLongIntegerException1() { Data d = new Data(new byte[]{5}); d.getLongInteger(); }
@Test(expected = RuntimeException.class) public void testGetLongIntegerException2() { Data d = new Data(new byte[]{0}); d.getLongInteger(); }