### Question:
NameIndex implements Storable<NameIndex> { public long put(String name) { if (name == null || name.isEmpty()) { return 0; } if (name.equals(lastName)) { return lastIndex; } byte[] bytes = getBytes(name); long oldPointer = bytePointer; names.ensureCapacity(bytePointer + 1 + bytes.length); byte[] sizeBytes = new byte[]{ (byte) bytes.length }; names.setBytes(bytePointer, sizeBytes, sizeBytes.length); bytePointer++; names.setBytes(bytePointer, bytes, bytes.length); bytePointer += bytes.length; lastName = name; lastIndex = oldPointer; return oldPointer; } NameIndex(Directory dir); @Override NameIndex create(long initBytes); @Override boolean loadExisting(); long put(String name); String get(long pointer); @Override void flush(); @Override void close(); @Override boolean isClosed(); void setSegmentSize(int segments); @Override long getCapacity(); void copyTo(NameIndex nameIndex);  }### Answer:
@Test public void testPut() { NameIndex index = new NameIndex(new RAMDirectory()).create(1000); long result = index.put("Something Streetä"); assertEquals("Something Streetä", index.get(result)); long existing = index.put("Something Streetä"); assertEquals(result, existing); result = index.put("testing"); assertEquals("testing", index.get(result)); assertEquals(0, index.put("")); assertEquals(0, index.put(null)); assertEquals("", index.get(0)); index.close(); }