Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Strapetz2010-08-19 13:34:44 +0000
committerMarc Strapetz2010-08-26 10:58:03 +0000
commit80c622c49c22e6d303856b8cb916b5fd0da86712 (patch)
treed430984eb4582368a360b316656832491e1db18c /org.eclipse.jgit.test
parent6517a7c923e012ea4b3d9f2497122d9c64dbdd5e (diff)
downloadjgit-80c622c49c22e6d303856b8cb916b5fd0da86712.tar.gz
jgit-80c622c49c22e6d303856b8cb916b5fd0da86712.tar.xz
jgit-80c622c49c22e6d303856b8cb916b5fd0da86712.zip
Fix parsing of multiple authors in PersonIdent.
PersonIdent should be parsable for an invalid commit which contains multiple authors, like "A <a@a.org>, B <b@b.org>". PersonIdent(String) constructor now delegates to RawParseUtils.parsePersonIdent(). Change-Id: Ie9798d36d9ecfcc0094ca795f5a44b003136eaf7
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0001_PersonIdent.java54
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevCommitParseTest.java15
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/util/ChangeIdUtilTest.java4
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawParseUtils_ParsePersonIdentTest.java103
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);
}
}

Back to the top