package com.janosgyerik.utils.counter;

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

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertEquals;

public class CounterTest {

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

        counter.add("hello");
        assertFalse(counter.counts().isEmpty());
    }

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

        counter.add("hello");
        assertEquals(1, counter.counts().size());

        counter.add("hello");
        assertEquals(1, counter.counts().size());
    }

    @Test
    public void testAddAll() {
        Counter<String> counter = Counters.counter();
        counter.addAll(Arrays.asList("hello", "hello", "hello", "world"));
        assertEquals(3, counter.get("hello"));
        assertEquals(1, counter.get("world"));
    }

    @Test
    public void testEntrySet() {
        Counter<String> counter = Counters.counter();
        counter.addAll(Arrays.asList("hello", "hello", "hello", "world"));

        Map<String, Integer> entries = new HashMap<>();
        entries.put("hello", 3);
        entries.put("world", 1);
        assertEquals(entries, counter.counts());
    }

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

        counter.add("hello");
        assertEquals(1, counter.get("hello"));

        counter.add("hello");
        assertEquals(2, counter.get("hello"));
    }

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

@@ -135,56 +135,8 @@
 ays;
-%0Aimport java.util.HashMap;%0Aimport java.util.Map;
 %0A%0Aim
@@ -194,140 +194,8 @@
 hat;
-%0Aimport static org.junit.Assert.assertTrue;%0Aimport static org.junit.Assert.assertFalse;%0Aimport static org.junit.Assert.assertEquals;
 %0A%0Apu
@@ -324,35 +324,35 @@
 %0A        assertT
-rue
+hat
 (counter.counts(
@@ -344,32 +344,33 @@
 counter.counts()
+)
 .isEmpty());%0A%0A  
@@ -355,33 +355,32 @@
 nts()).isEmpty()
-)
 ;%0A%0A        count
@@ -414,13 +414,12 @@
 sert
-False
+That
 (cou
@@ -431,27 +431,30 @@
 counts()
+)
 .is
+Not
 Empty()
-)
 ;%0A    %7D%0A
@@ -569,46 +569,29 @@
     
-assertTrue(counter.counts().isEmpty())
+String item = %22hello%22
 ;%0A%0A 
@@ -601,39 +601,36 @@
     counter.add(
-%22hello%22
+item
 );%0A        asser
@@ -634,72 +634,43 @@
 sert
-Equals(1, counter.counts().size());%0A%0A        counter.add(%22hello%22
+That(counter.get(item)).isEqualTo(1
 );%0A 
@@ -678,34 +678,29 @@
       assert
-Equals(1, 
+That(
 counter.coun
@@ -715,112 +715,24 @@
 e())
-;%0A    %7D%0A%0A    @Test%0A    public void testAddAll() %7B%0A        Counter%3CString%3E counter = Counters.counter(
+.isEqualTo(1
 );%0A
+%0A
     
@@ -750,61 +750,13 @@
 .add
-All(Arrays.asList(%22hello%22, %22hello%22, %22hello%22, %22world%22)
+(item
 );%0A 
@@ -772,18 +772,13 @@
 sert
-Equals(3, 
+That(
 coun
@@ -789,63 +789,84 @@
 get(
-%22hello%22));%0A        assertEquals(1, counter.get(%22world%22)
+item)).isEqualTo(2);%0A        assertThat(counter.counts().size()).isEqualTo(1
 );%0A 
@@ -905,16 +905,14 @@
 test
-EntrySet
+AddAll
 () %7B
@@ -978,75 +978,31 @@
     
-counter.addAll(Arrays.asList(%22hello%22, %22hello%22, %22hello%22, %22world%22));%0A
+String item1 = %22hello%22;
 %0A   
@@ -1010,168 +1010,202 @@
     
-Map%3C
 String
-, Integer%3E entries = new HashMap%3C%3E();%0A        entries.put(%22hello%22, 3);%0A        entries.put(%22world%22, 1);%0A        assertEquals(entries, counter.counts()
+ item2 = %22there%22;%0A        counter.addAll(Arrays.asList(item1, item1, item1, item2));%0A        assertThat(counter.get(item1)).isEqualTo(3);%0A        assertThat(counter.get(item2)).isEqualTo(1
 );%0A 
@@ -1314,44 +1314,80 @@
     
-assertEquals(0, counter.get(%22hello%22)
+String item = %22hello%22;%0A        assertThat(counter.get(item)).isEqualTo(0
 );%0A%0A
@@ -1398,39 +1398,36 @@
     counter.add(
-%22hello%22
+item
 );%0A        asser
@@ -1431,18 +1431,13 @@
 sert
-Equals(1, 
+That(
 coun
@@ -1444,24 +1444,34 @@
 ter.get(
-%22hello%22)
+item)).isEqualTo(1
 );%0A%0A    
@@ -1478,39 +1478,36 @@
     counter.add(
-%22hello%22
+item
 );%0A        asser
@@ -1511,18 +1511,13 @@
 sert
-Equals(2, 
+That(
 coun
@@ -1524,24 +1524,34 @@
 ter.get(
-%22hello%22)
+item)).isEqualTo(2
 );%0A    %7D

Rewrite test cases using assertj