### Question:
VByte { public static long decode(InputStream in) throws IOException { long out = 0; int shift=0; long readbyte = in.read(); if(readbyte==-1) throw new EOFException(); while( (readbyte & 0x80)==0) { if(shift>=50) { throw new IllegalArgumentException(); } out |= (readbyte & 127) << shift; readbyte = in.read(); if(readbyte==-1) throw new EOFException(); shift+=7; } out |= (readbyte & 127) << shift; return out; } private  VByte(); static void encode(OutputStream out, long value); static long decode(InputStream in); static long decode(ByteBuffer in); static int encode(byte[] data, int offset, int value); static int decode(byte[] data, int offset, Mutable<Long> value); static void show(byte[] data, int len);  }### Answer:
@Test(expected=IllegalArgumentException.class) public void testMoreCharactersThanNeeded() throws IOException { byte [] arr = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; long val = VByte.decode(new ByteArrayInputStream(arr)); System.out.println("VAL: "+val); fail("Exception not thrown"); }
@Test(expected=EOFException.class) public void testEOF() throws IOException { byte [] arr = { 0, 0 }; long val = VByte.decode(new ByteArrayInputStream(arr)); System.out.println("VAL: "+val); fail("Exception not thrown"); }