Skip to content

Commit

Permalink
More tests (#1635)
Browse files Browse the repository at this point in the history
* Added more tests for Cookie

* Enabled some layout tests and added test for StringUtil.intValueOfWithNull

* Updated a test

* Split tests
  • Loading branch information
oscargus authored Jul 28, 2016
1 parent be54a1f commit 20e4c82
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 17 deletions.
14 changes: 8 additions & 6 deletions src/test/java/net/sf/jabref/logic/layout/LayoutTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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}}");
Expand All @@ -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<br>text ", layoutText);
Expand All @@ -100,15 +103,14 @@ public void testPluginLoading() throws IOException {
* @throws Exception
*/
@Test
@Ignore
public void testLayout() throws IOException {

String layoutText = layout(
"<font face=\"arial\">\\begin{abstract}<BR><BR><b>Abstract: </b> \\format[HTMLChars]{\\abstract}\\end{abstract}</font>",
t1BibtexString());

Assert.assertEquals(
"<font face=\"arial\"><BR><BR><b>Abstract: </b> &ntilde; &ntilde; &iacute; &#305; &#305;</font>",
"<font face=\"arial\"><BR><BR><b>Abstract: </b> &ntilde; &ntilde; &iacute; &imath; &imath;</font>",
layoutText);
}
}
85 changes: 74 additions & 11 deletions src/test/java/net/sf/jabref/logic/net/CookieTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
33 changes: 33 additions & 0 deletions src/test/java/net/sf/jabref/logic/util/strings/StringUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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:", "", ':'));
Expand Down

0 comments on commit 20e4c82

Please sign in to comment.