### Question:
BitOutputStream extends NonBlockingBitOutputStream { @Override public void writeBit (final int aBit) throws IOException { m_aLock.lock (); try { super.writeBit (aBit); } finally { m_aLock.unlock (); } } BitOutputStream(@Nonnull final OutputStream aOS, @Nonnull final ByteOrder aByteOrder); @Override void writeBit(final int aBit); @Override void flush(); @Override void close();  }### Answer:
@Test public void testWriteBitLittleEndian () throws IOException { try (final NonBlockingByteArrayOutputStream aBAOS = new NonBlockingByteArrayOutputStream (); final BitOutputStream aBOS = new BitOutputStream (aBAOS, ByteOrder.LITTLE_ENDIAN)) { assertEquals (ByteOrder.LITTLE_ENDIAN, aBOS.getByteOrder ()); aBOS.writeBit (1); for (int i = 0; i < 7; ++i) aBOS.writeBit (0); assertTrue (aBAOS.size () > 0); final int aByte = aBAOS.toByteArray ()[0] & 0xff; assertEquals (128, aByte); } }
@Test public void testWriteBitBigEndian () throws IOException { try (final NonBlockingByteArrayOutputStream aBAOS = new NonBlockingByteArrayOutputStream (); final BitOutputStream aBOS = new BitOutputStream (aBAOS, ByteOrder.BIG_ENDIAN)) { assertEquals (ByteOrder.BIG_ENDIAN, aBOS.getByteOrder ()); for (int i = 0; i < 7; ++i) aBOS.writeBit (0); aBOS.writeBit (1); assertTrue (aBAOS.size () > 0); final int aByte = aBAOS.toByteArray ()[0] & 0xff; assertEquals (128, aByte); } }