Created
October 29, 2013 00:23
-
-
Save mbilokonsky/7207199 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void test_int_to_long_stuff() { | |
int x = 10; | |
int y = 20; | |
ByteBuffer buffer = ByteBuffer.allocate(8); | |
buffer.putInt(x).putInt(y); | |
Assert.assertFalse(buffer.hasRemaining()); // confirm I used all 8 bytes | |
buffer.position(0); | |
Assert.assertTrue(buffer.hasRemaining()); | |
long xy = buffer.getLong(); | |
Assert.assertFalse(buffer.hasRemaining()); // again, confirm I used all 8 bytes | |
buffer.position(0); | |
Assert.assertTrue(buffer.hasRemaining()); | |
buffer.putLong(xy); | |
Assert.assertFalse(buffer.hasRemaining()); // again, confirm I used all 8 bytes... | |
buffer.position(0); | |
int x2 = buffer.getInt(); | |
int y2 = buffer.getInt(); | |
Assert.assertFalse(buffer.hasRemaining()); | |
Assert.assertEquals(x, x2); | |
Assert.assertEquals(y, y2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment