package com.dubravsky.arcache;

import org.junit.Test;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;

public class ArcacheTest {

    private static final String ANY_STRING = "LoremIpsum";
    private static final byte[] NULL_BYTE_ARRAY = null;

    private static String fillStringWith(int size, int value) {
        StringBuilder result = new StringBuilder();
        for (int i = 0; i < size; i++) {
            result.append(String.valueOf(value));
        }
        return result.toString();
    }

    @Test
    public void shouldPutAndGetString() {
        Arcache arcache = Arcache.createDefault();

        String key = "key_01";
        arcache.put(key, ANY_STRING);

        assertThat(arcache.get(key), is(ANY_STRING));
    }

    @Test(expected = NullPointerException.class)
    public void shouldThrowNpeIfNullKeyIsProvided() {
        Arcache arcache = Arcache.createDefault();

        arcache.put(null, ANY_STRING);
    }

    @Test
    public void shouldRemoveOldestItemIfLimitIsExceeded() {
        String stringFilledWithZeros = fillStringWith(50, 0);
        String stringFilledWithOnes = fillStringWith(50, 1);
        String stringFilledWithTwos = fillStringWith(50, 2);

        Arcache arcache = Arcache.builder()
                .limitSize(100)
                .build();

        arcache.put("key_01", stringFilledWithZeros);
        arcache.put("key_02", stringFilledWithOnes);
        arcache.put("key_03", stringFilledWithTwos); // it tries to insert element with size 50 but
        // the cache contains two elements with total size of 100. hence, the oldes element (key_01) should be removed

        assertThat(arcache.get("key_01"), is(NULL_BYTE_ARRAY));
        assertThat(arcache.get("key_02"), is(stringFilledWithOnes));
        assertThat(arcache.get("key_03"), is(stringFilledWithTwos));
    }

}
@@ -25,16 +25,41 @@
 cache;%0A%0A
+import org.junit.Before;%0A
 import o
@@ -311,16 +311,53 @@
  null;%0A%0A
+    private Arcache defaultArcache;%0A%0A
     priv
@@ -603,36 +603,38 @@
 ();%0A    %7D%0A%0A    @
-Test
+Before
 %0A    public void
@@ -638,32 +638,14 @@
 oid 
-shouldPutAndGetString
+init
 ()
- 
 %7B%0A  
@@ -646,33 +646,32 @@
 ()%7B%0A        
-Arcache a
+defaultA
 rcache = Arc
@@ -684,32 +684,90 @@
 reateDefault();%0A
+    %7D%0A%0A    @Test%0A    public void shouldPutAndGetString() %7B
 %0A        String 
@@ -782,33 +782,40 @@
 ey_01%22;%0A        
-a
+defaultA
 rcache.put(key, 
@@ -839,33 +839,40 @@
      assertThat(
-a
+defaultA
 rcache.get(key),
@@ -1011,61 +1011,16 @@
     
-Arcache arcache = Arcache.createDefault();%0A%0A        a
+defaultA
 rcac

add init method for ArcacheTest class