import eu.toldi.rss.Article;
import eu.toldi.rss.Feed;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;

public class FeedTest {

    private Feed sample;

    @Before
    public void setup() throws IOException {
        sample = new Feed(new URL("https://www.rssboard.org/files/sample-rss-2.xml"));
    }

    @Test
    public void nameTest(){
        Assert.assertEquals("Liftoff News",sample.getName());
    }

    @Test
    public void articleCountTest(){
        Assert.assertEquals(4,sample.getArticleCount());
    }

    @Test
    public void firstArticleTest(){
        Article a =sample.get(0);
        Assert.assertEquals("Star City",a.getTitle());
        Assert.assertEquals("http://liftoff.msfc.nasa.gov/news/2003/news-starcity.asp",a.getURL());
        Assert.assertEquals("How do Americans get ready to work with Russians aboard the International Space Station? They take a crash course in culture, language and protocol at Russia's <a href=\"http://howe.iki.rssi.ru/GCTC/gctc_e.htm\">Star City</a>.",a.getDescription());
        Assert.assertEquals("2003-06-03T09:39:21",a.getPubDate().toString());
    }

    @Test
    public void newArticle(){
        Article a = new Article();
        sample.addArticle(a);
        Assert.assertEquals(5,sample.getArticleCount());
    }
}
