package lan.dk.podcastserver.entity;

import com.google.common.collect.Sets;
import org.junit.Before;
import org.junit.Test;

import java.time.ZonedDateTime;
import java.util.UUID;

import static lan.dk.podcastserver.assertion.Assertions.assertThat;

/**
 * Created by kevin on 15/06/15 for HackerRank problem
 */
public class PodcastTest {

    public static final ZonedDateTime NOW = ZonedDateTime.now();
    public static final Cover COVER = new Cover("ACover");
    public static final Podcast PODCAST = new Podcast();
    public static String PODCAST_TOSTRING;
    UUID id;


    @Before
    public void init() {
        /* Given */
        id = UUID.randomUUID();
        PODCAST.setId(id);
        PODCAST.setTitle("PodcastDeTest");
        PODCAST.setUrl("http://nowhere.com");
        PODCAST.setSignature("ae4b93a7e8249d6be591649c936dbe7d");
        PODCAST.setType("Youtube");
        PODCAST.setLastUpdate(NOW);
        PODCAST.setCover(COVER);
        PODCAST.setDescription("A long Description");
        PODCAST.setHasToBeDeleted(true);
        PODCAST.setItems(Sets.newHashSet());
        PODCAST.setTags(Sets.newHashSet());

        PODCAST_TOSTRING = "Podcast{id="+ id +", title='PodcastDeTest', url='http://nowhere.com', signature='ae4b93a7e8249d6be591649c936dbe7d', type='Youtube', lastUpdate=%s}";
    }

    @Test
    public void should_have_all_setters_and_getters_working() {
        /* Then */
        assertThat(PODCAST)
                .hasId(id)
                .hasTitle("PodcastDeTest")
                .hasUrl("http://nowhere.com")
                .hasSignature("ae4b93a7e8249d6be591649c936dbe7d")
                .hasType("Youtube")
                .hasLastUpdate(NOW)
                .hasCover(COVER)
                .hasDescription("A long Description")
                .hasHasToBeDeleted(true)
                .hasNoItems()
                .hasNoTags();
    }
    
    @Test
    public void should_have_toString() {
        org.assertj.core.api.Assertions.
                assertThat(PODCAST.toString())
                    .isEqualTo(String.format(PODCAST_TOSTRING, NOW));
    }
    
    @Test
    public void should_have_hashcode_and_equals() {
        /* Given */
        Podcast samePodcast = new Podcast();
        samePodcast.setId(id);
        samePodcast.setLastUpdate(NOW);
        samePodcast.setSignature("ae4b93a7e8249d6be591649c936dbe7d");
        samePodcast.setTitle("PodcastDeTest");
        samePodcast.setUrl("http://nowhere.com");

        Object notPodcast = new Object();

        /* Then */
        assertThat(PODCAST).isEqualTo(PODCAST);
        assertThat(PODCAST).isNotEqualTo(notPodcast);
        assertThat(PODCAST).isEqualTo(samePodcast);

        org.assertj.core.api.Assertions.
                assertThat(PODCAST.hashCode())
                .isNotNull();
    }
    
    @Test
    public void should_add_an_item() {
        Item itemToAdd = new Item();
        /* When */
        PODCAST.add(itemToAdd);
        /* Then */
        assertThat(itemToAdd).hasPodcast(PODCAST);
        assertThat(PODCAST).hasOnlyItems(itemToAdd);
    }

    @Test
    public void should_contains_item() {
        Item itemToAdd = new Item().setId(UUID.randomUUID());
        Item itemToAdd2 = new Item().setId(UUID.randomUUID());
        PODCAST.add(itemToAdd);

        org.assertj.core.api.Assertions.
                assertThat(PODCAST.contains(itemToAdd)).isTrue();
        org.assertj.core.api.Assertions.
                assertThat(PODCAST.contains(itemToAdd2)).isFalse();
    }
    
    @Test
    public void should_be_update_now() {
        /* When */
        PODCAST.lastUpdateToNow();
        /* Then */
        org.assertj.core.api.Assertions.
                assertThat(PODCAST.getLastUpdate().isAfter(NOW));
    }

}
@@ -242,16 +242,74 @@
 ertThat;
+%0Aimport static org.assertj.core.api.Assertions.assertThat;
 %0A%0A/**%0A *
@@ -394,29 +394,30 @@
 est %7B%0A%0A    p
-ublic
+rivate
  static fina
@@ -456,37 +456,38 @@
 ime.now();%0A    p
-ublic
+rivate
  static final Co
@@ -501,18 +501,28 @@
 ER =
- new
  Cover
+.builder().url
 (%22AC
@@ -527,28 +527,37 @@
 ACover%22)
+.build()
 ;%0A    p
-ublic
+rivate
  static 
@@ -600,21 +600,22 @@
 );%0A    p
-ublic
+rivate
  static 
@@ -627,24 +627,25 @@
 g PODCAST_TO
+_
 STRING;%0A    
@@ -644,16 +644,24 @@
 NG;%0A    
+private 
 UUID id;
@@ -1238,24 +1238,25 @@
   PODCAST_TO
+_
 STRING = %22Po
@@ -2038,57 +2038,8 @@
 ) %7B%0A
-        org.assertj.core.api.Assertions.%0A        
     
@@ -2076,29 +2076,8 @@
 g())
-%0A                    
 .isE
@@ -2107,16 +2107,17 @@
 DCAST_TO
+_
 STRING, 
@@ -2720,58 +2720,8 @@
 t);%0A
-%0A        org.assertj.core.api.Assertions.%0A        
     
@@ -2754,33 +2754,16 @@
 hCode())
-%0A                
 .isNotNu
@@ -3259,57 +3259,8 @@
 );%0A%0A
-        org.assertj.core.api.Assertions.%0A        
     
@@ -3317,57 +3317,8 @@
 ();%0A
-        org.assertj.core.api.Assertions.%0A        
     
@@ -3512,57 +3512,8 @@
  */%0A
-        org.assertj.core.api.Assertions.%0A        
     

remove usage of default constructor and use builder instead