### Question:
JDBMSpace extends TimerTask implements Space<K,V> { static void putLong (byte[] b, int off, long val) { b[off+7] = (byte) val; b[off+6] = (byte) (val >>> 8); b[off+5] = (byte) (val >>> 16); b[off+4] = (byte) (val >>> 24); b[off+3] = (byte) (val >>> 32); b[off+2] = (byte) (val >>> 40); b[off+1] = (byte) (val >>> 48); b[off] = (byte) (val >>> 56); } protected  JDBMSpace(String name, String filename); static JDBMSpace getSpace(); static JDBMSpace getSpace(String name); synchronized static JDBMSpace getSpace(String name, String filename); void setAutoCommit(boolean b); void commit(); void rollback(); void close(); void out(K key, V value); void out(K key, V value, long timeout); void push(K key, V value); void push(Object key, Object value, long timeout); synchronized V rdp(Object key); synchronized V inp(Object key); synchronized V in(Object key); synchronized V in(Object key, long timeout); synchronized V rd(Object key); synchronized V rd(Object key, long timeout); synchronized void nrd(Object key); synchronized V nrd(Object key, long timeout); long size(Object key); boolean existAny(Object[] keys); boolean existAny(Object[] keys, long timeout); synchronized void put(K key, V value, long timeout); synchronized void put(K key, V value); void run(); void gc(); String getKeys(); static final long GCDELAY; }### Answer:
@Test public void testPutLong() throws Throwable { byte[] b = new byte[66]; JDBMSpace.putLong(b, 0, 100L); assertEquals((byte) 100, b[7], "b[7]"); }
@Test public void testPutLongThrowsArrayIndexOutOfBoundsException() throws Throwable { byte[] b = "42".getBytes(); try { JDBMSpace.putLong(b, -6, 100L); fail("Expected ArrayIndexOutOfBoundsException to be thrown"); } catch (ArrayIndexOutOfBoundsException ex) { assertEquals((byte) 0, b[0], "b[0]"); if (isJavaVersionAtMost(JAVA_10)) { assertEquals("-1", ex.getMessage(), "ex.getMessage()"); } else { assertEquals("Index -1 out of bounds for length 2", ex.getMessage(), "ex.getMessage()"); } assertEquals(2, b.length, "b.length"); } }
@Test public void testPutLongThrowsArrayIndexOutOfBoundsException1() throws Throwable { byte[] b = new byte[3]; try { JDBMSpace.putLong(b, 100, 100L); fail("Expected ArrayIndexOutOfBoundsException to be thrown"); } catch (ArrayIndexOutOfBoundsException ex) { if (isJavaVersionAtMost(JAVA_10)) { assertEquals("107", ex.getMessage(), "ex.getMessage()"); } else { assertEquals("Index 107 out of bounds for length 3", ex.getMessage(), "ex.getMessage()"); } assertEquals(3, b.length, "b.length"); } }
@Test public void testPutLongThrowsNullPointerException() throws Throwable { try { JDBMSpace.putLong(null, 100, 100L); fail("Expected NullPointerException to be thrown"); } catch (NullPointerException ex) { if (isJavaVersionAtMost(JAVA_14)) { assertNull(ex.getMessage(), "ex.getMessage()"); } else { assertEquals("Cannot store to byte/boolean array because \"b\" is null", ex.getMessage(), "ex.getMessage()"); } } }