### Question:
Flyweight { public static boolean bitSet(final AtomicBuffer buffer, final int offset, final int bitIndex) { return 0 != (buffer.getByte(offset) & (1 << bitIndex)); } Flyweight(final ByteOrder byteOrder); int offset(); int limit(); Flyweight wrap(final AtomicBuffer buffer, final int offset); static short uint8Get(final AtomicBuffer buffer, final int offset); static void uint8Put(final AtomicBuffer buffer, final int offset, final short value); static byte int8Get(final AtomicBuffer buffer, final int offset); static void int8Put(final AtomicBuffer buffer, final int offset, final byte value); static int uint16Get(final AtomicBuffer buffer, final int offset, final ByteOrder byteOrder); static void uint16Put(final AtomicBuffer buffer, final int offset, final int value,
                                 final ByteOrder byteOrder); static short int16Get(final AtomicBuffer buffer, final int offset, final ByteOrder byteOrder); static void int16Put(final AtomicBuffer buffer, final int offset, final short value,
                                final ByteOrder byteOrder); static long uint32Get(final AtomicBuffer buffer, final int offset, final ByteOrder byteOrder); static void uint32Put(final AtomicBuffer buffer, final int offset, final long value,
                                 final ByteOrder byteOrder); static int int32Get(final AtomicBuffer buffer, final int offset, final ByteOrder byteOrder); static void int32Put(final AtomicBuffer buffer, final int offset, final int value,
                                final ByteOrder byteOrder); static long int64Get(final AtomicBuffer buffer, final int offset, final ByteOrder byteOrder); static void int64Put(final AtomicBuffer buffer, final int offset, final long value,
                                final ByteOrder byteOrder); static boolean bitSet(final AtomicBuffer buffer, final int offset, final int bitIndex); static void bitSet(final AtomicBuffer buffer, final int offset, final int bitIndex, final boolean switchOn);  }### Answer:
@Test public void shouldTestBitInByte() { final byte bits = (byte)0b1000_0000; final int bufferIndex = 8; final int bitIndex = 7; aBuff.putByte(bufferIndex, bits); for (int i = 0; i < 8; i++) { boolean result = Flyweight.bitSet(aBuff, bufferIndex, i); if (bitIndex == i) { assertTrue(result); } else { assertFalse("bit set i = " + i, result); } } }
@Test public void shouldSetBitInByte() { final int bufferIndex = 8; short total = 0; for (int i = 0; i < 8; i++) { Flyweight.bitSet(aBuff, bufferIndex, i, true); total += (1 << i); assertThat(Byte.valueOf(aBuff.getByte(bufferIndex)), is(Byte.valueOf((byte)total))); } }