Added JUnit

This commit is contained in:
Balazs Toldi 2020-11-30 17:38:43 +01:00
parent 1ebd171c1b
commit 9186406a97
Signed by: Bazsalanszky
GPG key ID: 89199E441116203D
4 changed files with 168 additions and 0 deletions

View file

@ -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());
}
}

View file

@ -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<Article> articleList= test.getArticleList();
Assert.assertEquals(0,articleList.size());
Assert.assertEquals(articleList.size(),test.getArticleCount());
}
}

View file

@ -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());
}
}

View file

@ -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 <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());
}
}