diff --git a/src/test/java/ArticleTest.java b/src/test/java/ArticleTest.java new file mode 100644 index 0000000..459ee04 --- /dev/null +++ b/src/test/java/ArticleTest.java @@ -0,0 +1,50 @@ +import eu.toldi.rss.Article; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.time.LocalDateTime; + +public class ArticleTest { + + private Article a; + + @Before + public void setup(){ + a=new Article(); + } + + @Test + public void setTitleTest(){ + a.setTitle("Menő cikk"); + Assert.assertEquals("Menő cikk",a.getTitle()); + } + + @Test + public void setURLTest(){ + a.setURL("http://example.com/"); + Assert.assertEquals("http://example.com/",a.getURL()); + } + @Test + public void setAuthorTest(){ + a.setAuthor("Alice & Bob"); + Assert.assertEquals("Alice & Bob",a.getAuthor()); + } + @Test + public void setDescTest(){ + a.setDescription("Something very cool happened"); + Assert.assertEquals("Something very cool happened",a.getDescription()); + } + + @Test + public void setDateTest(){ + a.setPubDate(LocalDateTime.parse("2020-11-30T09:55:23")); + Assert.assertEquals("2020-11-30T09:55:23",a.getPubDate().toString()); + } + + @Test + public void setImageTest(){ + a.setImageURL("https://upload.wikimedia.org/wikipedia/commons/4/4d/Cat_November_2010-1a.jpg"); + Assert.assertEquals("https://upload.wikimedia.org/wikipedia/commons/4/4d/Cat_November_2010-1a.jpg",a.getImageURL()); + } +} diff --git a/src/test/java/BasicFeedTest.java b/src/test/java/BasicFeedTest.java new file mode 100644 index 0000000..7110f03 --- /dev/null +++ b/src/test/java/BasicFeedTest.java @@ -0,0 +1,35 @@ +import eu.toldi.rss.Article; +import eu.toldi.rss.Feed; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.util.List; + +public class BasicFeedTest { + + private Feed test; + + @Before + public void setup(){ + test = new Feed("TestFeed"); + } + + @Test + public void nameTest(){ + Assert.assertEquals("TestFeed",test.getName()); + } + + @Test + public void nameChangeTest(){ + test.setName("Test Feed"); + Assert.assertEquals("Test Feed",test.getName()); + } + + @Test + public void testList(){ + List
articleList= test.getArticleList(); + Assert.assertEquals(0,articleList.size()); + Assert.assertEquals(articleList.size(),test.getArticleCount()); + } +} diff --git a/src/test/java/FeedGroupTest.java b/src/test/java/FeedGroupTest.java new file mode 100644 index 0000000..9dd11df --- /dev/null +++ b/src/test/java/FeedGroupTest.java @@ -0,0 +1,35 @@ +import eu.toldi.rss.Feed; +import eu.toldi.rss.FeedGroup; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; + +public class FeedGroupTest { + + private FeedGroup testGroup; + private Feed feed1; + + @Before + public void setup() throws IOException { + testGroup = new FeedGroup("New Feed Group"); + feed1 = new Feed(new URL("https://www.rssboard.org/files/sample-rss-2.xml")); + } + + @Test + public void sanityCheck(){ + Assert.assertEquals(0,testGroup.getArticleCount()); + Assert.assertEquals("New Feed Group",testGroup.getName()); + Assert.assertEquals(4,feed1.getArticleCount()); + } + + @Test + public void addFeedTest(){ + testGroup.addFeed(feed1); + Assert.assertEquals(4,testGroup.getArticleCount()); + } + +} diff --git a/src/test/java/FeedTest.java b/src/test/java/FeedTest.java new file mode 100644 index 0000000..1c9da9a --- /dev/null +++ b/src/test/java/FeedTest.java @@ -0,0 +1,48 @@ +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 Star City.",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()); + } +}