diff options
author | Shawn Pearce <spearce@spearce.org> | 2010-08-26 15:00:58 -0400 |
---|---|---|
committer | Code Review <codereview-daemon@eclipse.org> | 2010-08-26 15:00:58 -0400 |
commit | 7d9bfa390f5a329f7bfb703a91b4bfb8b4efec7c (patch) | |
tree | 903ea37888bd5de7808111e22d1e4598f08806a9 /org.eclipse.jgit.test | |
parent | 1edbefc5fa2c9d208b51060b9af2ebb89a6973af (diff) | |
parent | 80c622c49c22e6d303856b8cb916b5fd0da86712 (diff) | |
download | jgit-7d9bfa390f5a329f7bfb703a91b4bfb8b4efec7c.tar.gz jgit-7d9bfa390f5a329f7bfb703a91b4bfb8b4efec7c.zip |
Merge "Fix parsing of multiple authors in PersonIdent."
Diffstat (limited to 'org.eclipse.jgit.test')
4 files changed, 93 insertions, 83 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0001_PersonIdent.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0001_PersonIdent.java index aaa88c0281..b3aeb81b16 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0001_PersonIdent.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0001_PersonIdent.java @@ -55,57 +55,17 @@ public class T0001_PersonIdent extends TestCase { assertEquals("A U Thor", p.getName()); assertEquals("author@example.com", p.getEmailAddress()); assertEquals(1142878501000L, p.getWhen().getTime()); - assertEquals("A U Thor <author@example.com> 1142878501 -0500", p - .toExternalString()); + assertEquals("A U Thor <author@example.com> 1142878501 -0500", + p.toExternalString()); } - public void test002_ParseIdent() { - final String i = "A U Thor <author@example.com> 1142878501 -0500"; - final PersonIdent p = new PersonIdent(i); - assertEquals(i, p.toExternalString()); - assertEquals("A U Thor", p.getName()); - assertEquals("author@example.com", p.getEmailAddress()); - assertEquals(1142878501000L, p.getWhen().getTime()); - } - - public void test003_ParseIdent() { - final String i = "A U Thor <author@example.com> 1142878501 +0230"; - final PersonIdent p = new PersonIdent(i); - assertEquals(i, p.toExternalString()); - assertEquals("A U Thor", p.getName()); - assertEquals("author@example.com", p.getEmailAddress()); - assertEquals(1142878501000L, p.getWhen().getTime()); - } - - public void test004_ParseIdent() { - final String i = "A U Thor<author@example.com> 1142878501 +0230"; - final PersonIdent p = new PersonIdent(i); - assertEquals("A U Thor", p.getName()); - assertEquals("author@example.com", p.getEmailAddress()); - assertEquals(1142878501000L, p.getWhen().getTime()); - } - - public void test005_ParseIdent() { - final String i = "A U Thor<author@example.com>1142878501 +0230"; - final PersonIdent p = new PersonIdent(i); - assertEquals("A U Thor", p.getName()); - assertEquals("author@example.com", p.getEmailAddress()); - assertEquals(1142878501000L, p.getWhen().getTime()); - } - - public void test006_ParseIdent() { - final String i = "A U Thor <author@example.com>1142878501 +0230"; - final PersonIdent p = new PersonIdent(i); - assertEquals("A U Thor", p.getName()); - assertEquals("author@example.com", p.getEmailAddress()); - assertEquals(1142878501000L, p.getWhen().getTime()); - } - - public void test007_ParseIdent() { - final String i = "A U Thor<author@example.com>1142878501 +0230 "; - final PersonIdent p = new PersonIdent(i); + public void test002_NewIdent() { + final PersonIdent p = new PersonIdent("A U Thor", "author@example.com", + new Date(1142878501000L), TimeZone.getTimeZone("GMT+0230")); assertEquals("A U Thor", p.getName()); assertEquals("author@example.com", p.getEmailAddress()); assertEquals(1142878501000L, p.getWhen().getTime()); + assertEquals("A U Thor <author@example.com> 1142878501 +0230", + p.toExternalString()); } } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevCommitParseTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevCommitParseTest.java index 7be7dbc814..0ad724731e 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevCommitParseTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevCommitParseTest.java @@ -45,6 +45,7 @@ package org.eclipse.jgit.revwalk; import java.io.ByteArrayOutputStream; import java.io.UnsupportedEncodingException; +import java.util.TimeZone; import org.eclipse.jgit.lib.CommitBuilder; import org.eclipse.jgit.lib.Constants; @@ -59,10 +60,12 @@ public class RevCommitParseTest extends RepositoryTestCase { final String authorName = "A U. Thor"; final String authorEmail = "a_u_thor@example.com"; final int authorTime = 1218123387; + final String authorTimeZone = "+0700"; final String committerName = "C O. Miter"; final String committerEmail = "comiter@example.com"; final int committerTime = 1218123390; + final String committerTimeZone = "-0500"; final StringBuilder body = new StringBuilder(); body.append("tree "); @@ -75,7 +78,9 @@ public class RevCommitParseTest extends RepositoryTestCase { body.append(authorEmail); body.append("> "); body.append(authorTime); - body.append(" +0700\n"); + body.append(" "); + body.append(authorTimeZone); + body.append(" \n"); body.append("committer "); body.append(committerName); @@ -83,7 +88,9 @@ public class RevCommitParseTest extends RepositoryTestCase { body.append(committerEmail); body.append("> "); body.append(committerTime); - body.append(" -0500\n"); + body.append(" "); + body.append(committerTimeZone); + body.append("\n"); body.append("\n"); @@ -107,11 +114,15 @@ public class RevCommitParseTest extends RepositoryTestCase { assertNotNull(cAuthor); assertEquals(authorName, cAuthor.getName()); assertEquals(authorEmail, cAuthor.getEmailAddress()); + assertEquals((long)authorTime * 1000, cAuthor.getWhen().getTime()); + assertEquals(TimeZone.getTimeZone("GMT" + authorTimeZone), cAuthor.getTimeZone()); final PersonIdent cCommitter = c.getCommitterIdent(); assertNotNull(cCommitter); assertEquals(committerName, cCommitter.getName()); assertEquals(committerEmail, cCommitter.getEmailAddress()); + assertEquals((long)committerTime * 1000, cCommitter.getWhen().getTime()); + assertEquals(TimeZone.getTimeZone("GMT" + committerTimeZone), cCommitter.getTimeZone()); } private RevCommit create(final String msg) throws Exception { diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/ChangeIdUtilTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/ChangeIdUtilTest.java index a15cadfbda..c4adde3725 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/ChangeIdUtilTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/ChangeIdUtilTest.java @@ -61,10 +61,10 @@ public class ChangeIdUtilTest extends TestCase { private final String SOB2 = "Signed-off-by: J Committer <jc@example.com>\n"; - final PersonIdent p = new PersonIdent( + final PersonIdent p = RawParseUtils.parsePersonIdent( "A U Thor <author@example.com> 1142878501 -0500"); - final PersonIdent q = new PersonIdent( + final PersonIdent q = RawParseUtils.parsePersonIdent( "W Riter <writer@example.com> 1142878502 -0500"); ObjectId treeId = ObjectId diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawParseUtils_ParsePersonIdentTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawParseUtils_ParsePersonIdentTest.java index 2981e31c13..e76cd48b39 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawParseUtils_ParsePersonIdentTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawParseUtils_ParsePersonIdentTest.java @@ -43,58 +43,97 @@ package org.eclipse.jgit.util; -import java.io.UnsupportedEncodingException; import java.util.Date; import java.util.TimeZone; -import org.eclipse.jgit.lib.PersonIdent; - import junit.framework.TestCase; +import org.eclipse.jgit.lib.PersonIdent; + public class RawParseUtils_ParsePersonIdentTest extends TestCase { - public void testParsePersonIdent_legalCases() - throws UnsupportedEncodingException { + public void testParsePersonIdent_legalCases() { final Date when = new Date(1234567890000l); final TimeZone tz = TimeZone.getTimeZone("GMT-7"); - assertPersonIdent("Me <me@example.com> 1234567890 -0700", 0, + assertPersonIdent("Me <me@example.com> 1234567890 -0700", new PersonIdent("Me", "me@example.com", when, tz)); - assertPersonIdent(" Me <me@example.com> 1234567890 -0700", 1, - new PersonIdent("Me", "me@example.com", when, tz)); + assertPersonIdent(" Me <me@example.com> 1234567890 -0700", + new PersonIdent(" Me", "me@example.com", when, tz)); - assertPersonIdent("Me <> 1234567890 -0700", 0, new PersonIdent("Me", - "", when, tz)); + assertPersonIdent("A U Thor <author@example.com> 1234567890 -0700", + new PersonIdent("A U Thor", "author@example.com", when, tz)); - assertPersonIdent(" <me@example.com> 1234567890 -0700", 0, - new PersonIdent("", "me@example.com", when, tz)); + assertPersonIdent("A U Thor<author@example.com> 1234567890 -0700", + new PersonIdent("A U Thor", "author@example.com", when, tz)); + + assertPersonIdent("A U Thor<author@example.com>1234567890 -0700", + new PersonIdent("A U Thor", "author@example.com", when, tz)); + + assertPersonIdent( + " A U Thor < author@example.com > 1234567890 -0700", + new PersonIdent(" A U Thor ", " author@example.com ", when, tz)); + + assertPersonIdent("A U Thor<author@example.com>1234567890 -0700", + new PersonIdent("A U Thor", "author@example.com", when, tz)); + } + + public void testParsePersonIdent_fuzzyCases() { + final Date when = new Date(1234567890000l); + final TimeZone tz = TimeZone.getTimeZone("GMT-7"); + + assertPersonIdent( + "A U Thor <author@example.com>, C O. Miter <comiter@example.com> 1234567890 -0700", + new PersonIdent("A U Thor", "author@example.com", when, tz)); + + assertPersonIdent( + "A U Thor <author@example.com> and others 1234567890 -0700", + new PersonIdent("A U Thor", "author@example.com", when, tz)); + } + + public void testParsePersonIdent_incompleteCases() { + final Date when = new Date(1234567890000l); + final TimeZone tz = TimeZone.getTimeZone("GMT-7"); - assertPersonIdent(" <> 1234567890 -0700", 0, new PersonIdent("", "", + assertPersonIdent("Me <> 1234567890 -0700", new PersonIdent("Me", "", when, tz)); + + assertPersonIdent(" <me@example.com> 1234567890 -0700", + new PersonIdent("", "me@example.com", when, tz)); + + assertPersonIdent(" <> 1234567890 -0700", new PersonIdent("", "", when, + tz)); + + assertPersonIdent("<>", new PersonIdent("", "", 0, 0)); + + assertPersonIdent(" <>", new PersonIdent("", "", 0, 0)); + + assertPersonIdent("<me@example.com>", new PersonIdent("", + "me@example.com", 0, 0)); + + assertPersonIdent(" <me@example.com>", new PersonIdent("", + "me@example.com", 0, 0)); + + assertPersonIdent("Me <>", new PersonIdent("Me", "", 0, 0)); + + assertPersonIdent("Me <me@example.com>", new PersonIdent("Me", + "me@example.com", 0, 0)); + + assertPersonIdent("Me <me@example.com> 1234567890", new PersonIdent( + "Me", "me@example.com", 0, 0)); + + assertPersonIdent("Me <me@example.com> 1234567890 ", new PersonIdent( + "Me", "me@example.com", 0, 0)); } - public void testParsePersonIdent_malformedCases() - throws UnsupportedEncodingException { - assertPersonIdent("Me me@example.com> 1234567890 -0700", 0, null); - assertPersonIdent("Me <me@example.com 1234567890 -0700", 0, null); - - assertPersonIdent("<>", 0, null); - assertPersonIdent("<me@example.com>", 0, null); - assertPersonIdent(" <>", 0, null); - assertPersonIdent(" <me@example.com>", 0, null); - assertPersonIdent("Me <>", 0, null); - assertPersonIdent("Me <me@example.com>", 0, null); - - assertPersonIdent("Me <me@example.com> 1234567890", 0, null); - assertPersonIdent("<me@example.com> 1234567890 -0700", 0, null); - assertPersonIdent("<> 1234567890 -0700", 0, null); + public void testParsePersonIdent_malformedCases() { + assertPersonIdent("Me me@example.com> 1234567890 -0700", null); + assertPersonIdent("Me <me@example.com 1234567890 -0700", null); } - private void assertPersonIdent(String line, int nameB, PersonIdent expected) - throws UnsupportedEncodingException { - PersonIdent actual = RawParseUtils.parsePersonIdent(line - .getBytes("UTF-8"), nameB); + private void assertPersonIdent(String line, PersonIdent expected) { + PersonIdent actual = RawParseUtils.parsePersonIdent(line); assertEquals(expected, actual); } } |