From 20e4c8290ead7574fb265e53471edfe370e172f2 Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson Date: Thu, 28 Jul 2016 14:17:57 +0200 Subject: [PATCH] More tests (#1635) * Added more tests for Cookie * Enabled some layout tests and added test for StringUtil.intValueOfWithNull * Updated a test * Split tests --- .../sf/jabref/logic/layout/LayoutTest.java | 14 +-- .../net/sf/jabref/logic/net/CookieTest.java | 85 ++++++++++++++++--- .../logic/util/strings/StringUtilTest.java | 33 +++++++ 3 files changed, 115 insertions(+), 17 deletions(-) diff --git a/src/test/java/net/sf/jabref/logic/layout/LayoutTest.java b/src/test/java/net/sf/jabref/logic/layout/LayoutTest.java index 5d5e8cdf196..8a6705af398 100644 --- a/src/test/java/net/sf/jabref/logic/layout/LayoutTest.java +++ b/src/test/java/net/sf/jabref/logic/layout/LayoutTest.java @@ -38,8 +38,8 @@ public String t1BibtexString() { + " title = {Effective work practices for floss development: A model and propositions},\n" + " booktitle = {Hawaii International Conference On System Sciences (HICSS)},\n" + " year = {2005},\n" + " owner = {oezbek},\n" + " timestamp = {2006.05.29},\n" - + " url = {http://james.howison.name/publications.html},\n" + " abstract = {\\~{n}\n" + "\\~n\n" - + "\\'i\n" + "\\i\n" + "\\i}\n" + "}\n"; + + " url = {http://james.howison.name/publications.html},\n" + " abstract = {\\~{n} \\~n " + + "\\'i \\i \\i}\n" + "}\n"; } public static BibEntry bibtexString2BibtexEntry(String s) throws IOException { @@ -68,7 +68,6 @@ public void testLayoutBibtextype() throws IOException { } @Test - @Ignore public void testHTMLChar() throws IOException { String layoutText = layout("\\begin{author}\\format[HTMLChars]{\\author}\\end{author} ", "@other{bla, author={This\nis\na\ntext}}"); @@ -79,8 +78,12 @@ public void testHTMLChar() throws IOException { "@other{bla, author={This\nis\na\ntext}}"); Assert.assertEquals("This is a text", layoutText); + } - layoutText = layout("\\begin{author}\\format[HTMLChars]{\\author}\\end{author} ", + @Test + @Ignore + public void testHTMLCharDoubleLineBreak() throws IOException { + String layoutText = layout("\\begin{author}\\format[HTMLChars]{\\author}\\end{author} ", "@other{bla, author={This\nis\na\n\ntext}}"); Assert.assertEquals("This is a
text ", layoutText); @@ -100,7 +103,6 @@ public void testPluginLoading() throws IOException { * @throws Exception */ @Test - @Ignore public void testLayout() throws IOException { String layoutText = layout( @@ -108,7 +110,7 @@ public void testLayout() throws IOException { t1BibtexString()); Assert.assertEquals( - "

Abstract: ñ ñ í ı ı
", + "

Abstract: ñ ñ í ı ı
", layoutText); } } diff --git a/src/test/java/net/sf/jabref/logic/net/CookieTest.java b/src/test/java/net/sf/jabref/logic/net/CookieTest.java index c1f23cbfb8b..81d4747b722 100644 --- a/src/test/java/net/sf/jabref/logic/net/CookieTest.java +++ b/src/test/java/net/sf/jabref/logic/net/CookieTest.java @@ -5,36 +5,99 @@ import org.junit.Test; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; public class CookieTest { + @Test(expected = IllegalArgumentException.class) + public void testIncorrectExpiresFormat() throws URISyntaxException { + Cookie cookie = new Cookie(new URI("http://jabref.org/"), + "name=TestCookie; expires=Tue, 25/07/10 16:43:15 GMT"); + fail(); + } + + @Test(expected = IllegalArgumentException.class) + public void testIncorrectDomain() throws URISyntaxException { + Cookie cookie = new Cookie(new URI("http://jabref.org/"), + "name=TestCookie; domain=google.com"); + fail(); + } @Test - public void testCookieHyphenFormat() throws URISyntaxException { - Cookie cookie = new Cookie(new URI("hhh"), "name=TestCookie; expires=Tue, 25-Jul-2017 16:43:15 GMT"); + public void testHasExpiredFalse() throws URISyntaxException { + Cookie cookie = new Cookie(new URI("http://jabref.org/"), + "name=TestCookie; expires=Tue, 25-Jul-45 16:43:15 GMT"); + assertFalse(cookie.hasExpired()); } + @Test - public void testCookieHyphenTwoDigitYearFormat() throws URISyntaxException { - Cookie cookie = new Cookie(new URI("hhh"), "name=TestCookie; expires=Tue, 25-Jul-17 16:43:15 GMT"); + public void testHasExpiredFalseWhenNotSet() throws URISyntaxException { + Cookie cookie = new Cookie(new URI("http://jabref.org/"), "name=TestCookie; domain=jabref.org; path=/"); + assertFalse(cookie.hasExpired()); } @Test - public void testCookieSpaceFormat() throws URISyntaxException { - Cookie cookie = new Cookie(new URI("hhh"), "name=TestCookie; expires=Tue, 25 Jul 2017 16:43:15 GMT"); + public void testHasExpiredTrueSpaceFormat() throws URISyntaxException { + Cookie cookie = new Cookie(new URI("http://jabref.org/"), + "name=Nicholas; expires=Sat, 02 May 2009 23:38:25 GMT"); + assertTrue(cookie.hasExpired()); } @Test - public void testHasExpiredFalse() throws URISyntaxException { - Cookie cookie = new Cookie(new URI("hhh"), "name=TestCookie; expires=Tue, 25-Jul-45 16:43:15 GMT"); - assertFalse(cookie.hasExpired()); + public void testHasExpiredTrueHyphenFormat() throws URISyntaxException { + Cookie cookie = new Cookie(new URI("http://jabref.org/"), + "name=Nicholas; expires=Sat, 02-May-2009 23:38:25 GMT"); + assertTrue(cookie.hasExpired()); } @Test - public void testHasExpiredTrue() throws URISyntaxException { - Cookie cookie = new Cookie(new URI("hhh"), "name=Nicholas; expires=Sat, 02 May 2009 23:38:25 GMT"); + public void testHasExpiredTrueTwoDigitYearHyphenFormat() throws URISyntaxException { + Cookie cookie = new Cookie(new URI("http://jabref.org/"), "name=Nicholas; expires=Sat, 02-May-09 23:38:25 GMT"); assertTrue(cookie.hasExpired()); } + + @Test + public void testMatches() throws URISyntaxException { + Cookie cookie = new Cookie(new URI("http://jabref.org/"), + "LSID=LSDLSD; Domain=jabref.org; Path=/; Secure; expires=Sat, 02-May-99 23:38:25 GMT"); + assertTrue(cookie.matches(new URI("http://jabref.org/"))); + } + + @Test + public void testMatchesWWWInDomain() throws URISyntaxException { + Cookie cookie = new Cookie(new URI("http://www.jabref.org/"), + "LSID=LSDLSD; Domain=www.jabref.org; Path=/; Secure; expires=Sat, 02-May-99 23:38:25 GMT"); + assertTrue(cookie.matches(new URI("http://jabref.org/"))); + } + + @Test + public void testMatchesDotInDomain() throws URISyntaxException { + Cookie cookie = new Cookie(new URI("http://jabref.org/"), + "LSID=LSDLSD; Domain=.jabref.org; Path=/; Secure; expires=Sat, 02-May-99 23:38:25 GMT"); + assertTrue(cookie.matches(new URI("http://jabref.org/"))); + } + + @Test + public void testNotMatchesWhenExpired() throws URISyntaxException { + Cookie cookie = new Cookie(new URI("http://jabref.org/"), + "LSID=LSDLSD; Domain=jabref.org; Path=/; Secure; expires=Sat, 02-May-09 23:38:25 GMT"); + assertFalse(cookie.matches(new URI("http://jabref.org/"))); + } + + @Test + public void testNotMatchesWrongPath() throws URISyntaxException { + Cookie cookie = new Cookie(new URI("http://jabref.org/"), + "LSID=LSDLSD; Domain=jabref.org; Path=/blog/; Secure; expires=Sat, 02-May-99 23:38:25 GMT"); + assertFalse(cookie.matches(new URI("http://jabref.org/"))); + } + + @Test + public void testToString() throws URISyntaxException { + Cookie cookie = new Cookie(new URI("http://jabref.org/"), "LSID=LSDLSD; Domain=jabref.org; Path=/; Secure"); + assertEquals("LSID=LSDLSD", cookie.toString()); + } } diff --git a/src/test/java/net/sf/jabref/logic/util/strings/StringUtilTest.java b/src/test/java/net/sf/jabref/logic/util/strings/StringUtilTest.java index 85dc3faa627..20ad854e4eb 100644 --- a/src/test/java/net/sf/jabref/logic/util/strings/StringUtilTest.java +++ b/src/test/java/net/sf/jabref/logic/util/strings/StringUtilTest.java @@ -11,6 +11,7 @@ import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; public class StringUtilTest { @@ -243,6 +244,38 @@ public void testIntValueOfExceptionfIfStringEmpty() { StringUtil.intValueOf(""); } + @Test + public void testIntValueOfWithNullSingleDigit() { + assertEquals(Integer.valueOf(1), StringUtil.intValueOfWithNull("1")); + assertEquals(Integer.valueOf(2), StringUtil.intValueOfWithNull("2")); + assertEquals(Integer.valueOf(8), StringUtil.intValueOfWithNull("8")); + } + + @Test + public void testIntValueOfWithNullLongString() { + assertEquals(Integer.valueOf(1234567890), StringUtil.intValueOfWithNull("1234567890")); + } + + @Test + public void testIntValueOfWithNullStartWithZeros() { + assertEquals(Integer.valueOf(1234), StringUtil.intValueOfWithNull("001234")); + } + + @Test + public void testIntValueOfWithNullExceptionIfStringContainsLetter() { + assertNull(StringUtil.intValueOfWithNull("12A2")); + } + + @Test + public void testIntValueOfWithNullExceptionIfStringNull() { + assertNull(StringUtil.intValueOfWithNull(null)); + } + + @Test + public void testIntValueOfWithNullExceptionfIfStringEmpty() { + assertNull(StringUtil.intValueOfWithNull("")); + } + @Test public void testQuoteSimple() { assertEquals("a::", StringUtil.quote("a:", "", ':'));