package org.ethereum.db;

import org.junit.Before;
import org.junit.Test;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;

/**
 * @author Mikhail Kalinin
 * @since 07.07.2015
 */
public class HashStoreTest {

    private List<byte[]> hashes = new ArrayList<>();

    @Before
    public void setup() {
        Random rnd = new Random(System.currentTimeMillis());
        for(int i = 0; i < 100; i++) {
            byte[] hash = new byte[32];
            rnd.nextBytes(hash);
            hashes.add(hash);
        }
    }

    @Test
    public void test() throws InstantiationException, IllegalAccessException {
        BigInteger bi = new BigInteger(32, new Random());
        String testDb = "test_db_" + bi;

        HashStore hashStore = new HashStore.Builder()
                .withName(testDb)
                .build();

        for(byte[] hash : hashes) {
            hashStore.add(hash);
        }
        assertArrayEquals(hashes.get(0), hashStore.peek());
        for(byte[] hash : hashes) {
            assertArrayEquals(hash, hashStore.poll());
        }
        assertEquals(true, hashStore.isEmpty());
        assertNull(hashStore.peek());
        assertNull(hashStore.poll());

        hashStore.close();
    }
}

@@ -19,16 +19,96 @@
 um.db;%0A%0A
+import org.ethereum.config.SystemProperties;%0Aimport org.ethereum.util.FileUtil;%0A
 import o
@@ -983,124 +983,147 @@
 bi;%0A
-%0A        HashStore hashStore = new HashStore.Builder()%0A                .withName(testDb)%0A                .build();%0A%0A
+        SystemProperties.CONFIG.setDataBaseDir(testDb);%0A%0A        HashStore hashStore = new HashStore.Builder().build();%0A%0A        try %7B%0A    
     
@@ -1158,32 +1158,36 @@
 ) %7B%0A            
+  
+  
 hashStore.add(ha
@@ -1195,34 +1195,40 @@
 h);%0A        
-%7D%0A
+    %7D%0A  
         
 assertArrayE
@@ -1207,32 +1207,34 @@
     %7D%0A          
+  
 assertArrayEqual
@@ -1269,32 +1269,36 @@
 eek());%0A        
+    
 for(byte%5B%5D hash 
@@ -1313,32 +1313,36 @@
 ) %7B%0A            
+ 
+   
 assertArrayEqual
@@ -1364,24 +1364,28 @@
 re.poll());%0A
+    
         %7D%0A  
@@ -1386,24 +1386,28 @@
   %7D%0A        
+    
 assertEquals
@@ -1435,32 +1435,36 @@
 pty());%0A        
+   
+ 
 assertNull(hashS
@@ -1469,32 +1469,36 @@
 hStore.peek());%0A
+    
         assertNu
@@ -1519,17 +1519,40 @@
 oll());%0A
-%0A
+        %7D finally %7B%0A    
         
@@ -1570,16 +1570,72 @@
 lose();%0A
+            FileUtil.recursiveDelete(testDb);%0A        %7D%0A
     %7D%0A%7D%0A

Add a clean up of test data for HashStoreTest