/* * Short Tests */ @Test public void testGetAndSetShort() throws Exception { WrappedByteBuffer buf = new WrappedByteBuffer(); buf.putShort((short) 0); buf.putShort((short) 1); buf.putShort((short) 32767); buf.putShort((short) -32768); buf.flip(); assertEquals(buf.position(), 0); assertEquals(buf.limit(), 8); assertEquals((short) 0, buf.getShort()); assertEquals((short) 1, buf.getShort()); assertEquals((short) 32767, buf.getShort()); assertEquals((short) -32768, buf.getShort()); assertEquals(buf.position(), 8); buf.putShortAt(0, (short) 121); buf.putShortAt(2, (short) 1000); assertEquals((short) 121, buf.getShortAt(0)); assertEquals((short) 1000, buf.getShortAt(2)); assertEquals((int) buf.position(), 8); }
@Test public void testGetAndSetShorts() throws Exception { // tests reallocation of buffer automatically. WrappedByteBuffer buf = WrappedByteBuffer.allocate(2); buf.putShort((short) 1); buf.putShort((short) 2); buf.putShort((short) 3); buf.putShort((short) 4); buf.putShort((short) 5); buf.flip(); assertEquals((short) 1, buf.getShort()); assertEquals((short) 1, buf.getShortAt(0)); assertEquals((short) 2, buf.getShortAt(2)); assertEquals((short) 3, buf.getShortAt(4)); assertEquals((short) 2, buf.getShort()); assertEquals((short) 3, buf.getShort()); assertEquals((short) 4, buf.getShort()); assertEquals((short) 5, buf.getShort()); }
@Test public void testGetAndSetVarious() throws Exception { // tests reallocation of buffer automatically. WrappedByteBuffer buf = WrappedByteBuffer.allocate(2); buf.put((byte) 1); buf.putShort((short) 2); buf.putInt(3); buf.putLong((long) 4); String test = "this"; buf.putString(test, Charset.defaultCharset()); buf.put((byte) 0); buf.putPrefixedString(1, "abcde", Charset.defaultCharset()); buf.flip(); assertEquals((byte) 1, buf.get()); assertEquals((short) 2, buf.getShort()); assertEquals(3, buf.getInt()); assertEquals((long) 4, buf.getLong()); assertEquals(test, buf.getString(Charset.defaultCharset())); assertEquals("abcde", buf.getPrefixedString(1, Charset.defaultCharset())); }
@Test(expected = BufferUnderflowException.class) public void testGetAndSetGetShortException3() { WrappedByteBuffer buf = WrappedByteBuffer.allocate(0); buf.getShort(); }