package com.janosgyerik.utils.counter;

import com.janosgyerik.utils.counter.api.Counter;
import org.junit.Test;

import java.util.Arrays;

import static org.assertj.core.api.Assertions.assertThat;

public class CounterTest {

    @Test
    public void test_add_one() {
        Counter<String> counter = Counters.counter();
        assertThat(counter.counts()).isEmpty();

        counter.add("hello");
        assertThat(counter.counts()).isNotEmpty();
    }

    @Test
    public void test_add_one_twice() {
        Counter<String> counter = Counters.counter();
        String item = "hello";

        counter.add(item);
        assertThat(counter.get(item)).isEqualTo(1);
        assertThat(counter.counts().size()).isEqualTo(1);

        counter.add(item);
        assertThat(counter.get(item)).isEqualTo(2);
        assertThat(counter.counts().size()).isEqualTo(1);
    }

    @Test
    public void testAddAll() {
        Counter<String> counter = Counters.counter();
        String item1 = "hello";
        String item2 = "there";
        counter.addAll(Arrays.asList(item1, item1, item1, item2));
        assertThat(counter.get(item1)).isEqualTo(3);
        assertThat(counter.get(item2)).isEqualTo(1);
    }

    @Test
    public void testGet() {
        Counter<String> counter = Counters.counter();
        String item = "hello";
        assertThat(counter.get(item)).isEqualTo(0);

        counter.add(item);
        assertThat(counter.get(item)).isEqualTo(1);

        counter.add(item);
        assertThat(counter.get(item)).isEqualTo(2);
    }

    @Test(expected = UnsupportedOperationException.class)
    public void should_not_expose_internal_map_of_counts() {
        Counter<String> counter = Counters.counter();
        counter.counts().put("some key", 7);
    }
}

@@ -250,78 +250,48 @@
 oid 
+i
 te
-st_add_one() %7B%0A        Counter%3CString%3E counter = Counters.counter();
+m_never_added_should_have_count_0() %7B
 %0A   
@@ -310,116 +310,58 @@
 hat(
-c
+C
 ounter
-.counts()).isEmpty();%0A%0A        counter.add(%22hello%22);%0A        assertThat(counter.counts()).isNotEmpty(
+s.counter().get(%22nonexistent%22)).isEqualTo(0
 );%0A 
@@ -396,30 +396,78 @@
 oid 
+i
 te
-st
+m
 _add
+ed
 _on
+c
 e_
-twice() %7B
+should_have_count_1() %7B%0A        String item = %22value%22;
 %0A   
@@ -521,40 +521,8 @@
 ();%0A
-        String item = %22hello%22;%0A%0A
     
@@ -604,460 +604,206 @@
     
+%7D%0A%0A
     
-assertThat(counter.counts().size()).isEqualTo(1);%0A%0A        counter.add(item);%0A        assertThat(counter.get(item)).isEqualTo(2);%0A        assertThat(counter.counts().size()).isEqualTo(1);%0A    %7D%0A%0A    @Test%0A    public void testAddAll() %7B%0A        Counter%3CString%3E counter = Counters.counter();%0A        String item1 = %22hello%22;%0A        String item2 = %22there%22;%0A        counter.addAll(Arrays.asList(item1, item1, item1, item2));%0A        assertThat(
+@Test%0A    public void item_added_twice_should_have_count_2() %7B%0A        String item = %22value%22;%0A        Counter%3CString%3E counter = Counters.counter();%0A        counter.add(item);%0A        
 counter.
 get(
@@ -802,31 +802,16 @@
 ter.
-get
+add
 (item
-1)).isEqualTo(3
 );%0A 
@@ -844,17 +844,16 @@
 get(item
-2
 )).isEqu
@@ -849,33 +849,33 @@
 tem)).isEqualTo(
-1
+2
 );%0A    %7D%0A%0A    @T
@@ -902,11 +902,28 @@
 test
-Get
+_adding_many_at_once
 () %7B
@@ -992,24 +992,25 @@
  String item
+1
  = %22hello%22;%0A
@@ -1021,77 +1021,96 @@
     
-assertThat(counter.get(item)).isEqualTo(0);%0A%0A        counter.add(item
+String item2 = %22there%22;%0A        counter.addAll(Arrays.asList(item1, item1, item1, item2)
 );%0A 
@@ -1135,32 +1135,33 @@
 counter.get(item
+1
 )).isEqualTo(1);
@@ -1161,37 +1161,9 @@
 lTo(
-1);%0A%0A        counter.add(item
+3
 );%0A 
@@ -1188,32 +1188,33 @@
 counter.get(item
+2
 )).isEqualTo(2);
@@ -1202,33 +1202,33 @@
 em2)).isEqualTo(
-2
+1
 );%0A    %7D%0A%0A    @T

Rewrite test cases of Counter, simpler