package lan.dk.podcastserver.controller.api;

import javaslang.collection.HashSet;
import javaslang.collection.List;
import javaslang.collection.Set;
import lan.dk.podcastserver.business.TagBusiness;
import lan.dk.podcastserver.entity.Tag;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

import java.util.UUID;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.*;

/**
 * Created by kevin on 15/09/15 for Podcast Server
 */
@RunWith(MockitoJUnitRunner.class)
public class TagControllerTest {

    @Mock TagBusiness tagBusiness;
    @InjectMocks TagController tagController;

    @Test
    public void should_find_tag_by_id() {
        /* Given */
        UUID id = UUID.randomUUID();
        Tag value = new Tag();
        when(tagBusiness.findOne(eq(id))).thenReturn(value);

        /* When */
        Tag tagById = tagController.findById(id);

        /* Then */
        assertThat(tagById).isSameAs(value);
        verify(tagBusiness, only()).findOne(eq(id));
    }

    @Test
    public void should_find_all_tag() {
        /* Given */
        List<Tag> tags = List.empty();
        when(tagBusiness.findAll()).thenReturn(tags);

        /* When */
        List<Tag> tagList = tagController.findAll();

        /* Then */
        assertThat(tagList).isSameAs(tags);
        verify(tagBusiness, only()).findAll();
    }

    @Test
    public void should_find_by_name() {
        /* Given */
        String name = "Foo";
        Set<Tag> tags = HashSet.empty();
        when(tagBusiness.findByNameLike(eq(name))).thenReturn(tags);

        /* When */
        Set<Tag> tagsFoundByName = tagController.findByNameLike(name);

        /* Then */
        assertThat(tagsFoundByName).isSameAs(tags);
        verify(tagBusiness, only()).findByNameLike(eq(name));
    }
}
@@ -480,47 +480,8 @@
 at;%0A
-import static org.mockito.Matchers.eq;%0A
 impo
@@ -513,16 +513,16 @@
 kito.*;%0A
+
 %0A/**%0A * 
@@ -646,16 +646,24 @@
  %7B%0A%0A    
+private 
 @Mock Ta
@@ -689,16 +689,24 @@
 ss;%0A    
+private 
 @InjectM
@@ -917,16 +917,12 @@
 One(
-eq(
 id))
-)
 .the
@@ -1120,15 +1120,11 @@
 One(
-eq(
 id)
-)
 ;%0A  
@@ -1666,18 +1666,14 @@
 ike(
-eq(
 name))
-)
 .the
@@ -1905,17 +1905,13 @@
 ike(
-eq(
 name)
-)
 ;%0A  

simplify code execution with mockito