### Question:
SunManagementHeapAllocation extends HeapAllocation { @Override public long allocatedBytes( long threadId ) { if ( !threadMXBean.isThreadAllocatedMemorySupported() ) { return -1; } if ( !threadMXBean.isThreadAllocatedMemoryEnabled() ) { threadMXBean.setThreadAllocatedMemoryEnabled( true ); } return threadMXBean.getThreadAllocatedBytes( threadId ); } private  SunManagementHeapAllocation( ThreadMXBean threadMXBean ); @Override long allocatedBytes( long threadId );  }### Answer:
@Test void shouldMeasureAllocation() { long allocatedBytes = HEAP_ALLOCATION.allocatedBytes( currentThread() ); List<Object> objects = new ArrayList<>(); for ( int i = 0; i < 17; i++ ) { objects.add( new Object() ); } assertThat( allocatedBytes, Matchers.lessThan( HEAP_ALLOCATION.allocatedBytes( currentThread() ) ) ); assertEquals( 17, objects.size() ); }