Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fix JENKINS-16737] and [Fix JENKINS-10434] - no exception if author …
…not found Return unknown user rather than throwing exception in GitChangeSet Refer to [JENKINS-16737] and [JENKINS-10434] for two cases where a GitChangeSet cannot find an author and throws a RuntimeException when it would be much better to report an unknown user and allow execution to continue. Added a Polish character to the accented character test Use more diacritics in the latin accented character test Use parameterized GitChangeSet test to better cover cases
- Loading branch information
1 parent
6610db3
commit 287e543
Showing
5 changed files
with
502 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
src/test/java/hudson/plugins/git/GitChangeSetEmptyTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package hudson.plugins.git; | ||
|
||
import java.util.ArrayList; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import static org.junit.Assert.*; | ||
|
||
public class GitChangeSetEmptyTest { | ||
|
||
private GitChangeSet changeSet = null; | ||
|
||
public GitChangeSetEmptyTest() { | ||
} | ||
|
||
@Before | ||
public void createEmptyChangeSet() { | ||
changeSet = new GitChangeSet(new ArrayList<String>(), false); | ||
} | ||
|
||
@Test | ||
public void testGetDate() { | ||
assertNull(changeSet.getDate()); | ||
} | ||
|
||
@Test | ||
public void testGetCommitId() { | ||
assertNull(changeSet.getCommitId()); | ||
} | ||
|
||
@Test | ||
public void testSetParent() { | ||
changeSet.setParent(null); | ||
assertNull(changeSet.getParent()); | ||
} | ||
|
||
@Test | ||
public void testGetParentCommit() { | ||
assertNull(changeSet.getParentCommit()); | ||
} | ||
|
||
@Test | ||
public void testGetAffectedPaths() { | ||
assertTrue(changeSet.getAffectedPaths().isEmpty()); | ||
} | ||
|
||
@Test | ||
public void testGetPaths() { | ||
assertTrue(changeSet.getPaths().isEmpty()); | ||
} | ||
|
||
@Test | ||
public void testGetAffectedFiles() { | ||
assertTrue(changeSet.getAffectedFiles().isEmpty()); | ||
} | ||
|
||
@Test | ||
public void testGetAuthorName() { | ||
assertNull(changeSet.getAuthorName()); | ||
} | ||
|
||
@Test | ||
public void testGetMsg() { | ||
assertNull(changeSet.getMsg()); | ||
} | ||
|
||
@Test | ||
public void testGetId() { | ||
assertNull(changeSet.getId()); | ||
} | ||
|
||
@Test | ||
public void testGetRevision() { | ||
assertNull(changeSet.getRevision()); | ||
} | ||
|
||
@Test | ||
public void testGetComment() { | ||
assertNull(changeSet.getComment()); | ||
} | ||
|
||
@Test | ||
public void testGetBranch() { | ||
assertNull(changeSet.getBranch()); | ||
} | ||
|
||
@Test | ||
public void testHashCode() { | ||
assertTrue(changeSet.hashCode() != 0); | ||
} | ||
|
||
@Test | ||
public void testEquals() { | ||
assertFalse(changeSet.equals(null)); | ||
} | ||
|
||
} |
146 changes: 146 additions & 0 deletions
146
src/test/java/hudson/plugins/git/GitChangeSetEuroTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
package hudson.plugins.git; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import static org.junit.Assert.*; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
|
||
@RunWith(Parameterized.class) | ||
public class GitChangeSetEuroTest { | ||
|
||
private GitChangeSet changeSet = null; | ||
private final String id = "1567861636cd854f4dd6fa40bf94c0c657681dd5"; | ||
private final String parent = "e74a24e995305bd67a180f0ebc57927e2b8783ce"; | ||
private final String authorName = "Mr. Åhłañder"; | ||
private final String committerName = "Mister Åhländèr"; | ||
private final String msg = "[task] Updated version."; | ||
private final String comment1 = "Including earlier updates."; | ||
private final String commentStartText = msg + "\n\n" + comment1 + "\n"; | ||
|
||
protected final boolean useAuthorName; | ||
|
||
public GitChangeSetEuroTest(String useAuthorName) { | ||
this.useAuthorName = Boolean.valueOf(useAuthorName); | ||
} | ||
|
||
@Parameterized.Parameters(name = "{0}") | ||
public static Collection permuteAuthorNameAndLegacyLayout() { | ||
List<Object[]> values = new ArrayList<Object[]>(); | ||
String[] allowed = {"true", "false"}; | ||
for (String authorName : allowed) { | ||
Object[] combination = {authorName}; | ||
values.add(combination); | ||
} | ||
return values; | ||
} | ||
|
||
@Before | ||
public void createEuroChangeSet() { | ||
ArrayList<String> gitChangeLog = new ArrayList<String>(); | ||
gitChangeLog.add("commit " + id); | ||
gitChangeLog.add("tree 66236cf9a1ac0c589172b450ed01f019a5697c49"); | ||
gitChangeLog.add("parent " + parent); | ||
gitChangeLog.add("author " + authorName + " <mister.ahlander@ericsson.com> 1363879004 +0100"); | ||
gitChangeLog.add("committer " + committerName + " <mister.ahlander@ericsson.com> 1364199539 -0400"); | ||
gitChangeLog.add(""); | ||
gitChangeLog.add(" " + msg); | ||
gitChangeLog.add(" "); | ||
gitChangeLog.add(" " + comment1); | ||
gitChangeLog.add(" "); | ||
gitChangeLog.add(" Changes in this version:"); | ||
gitChangeLog.add(" - Changed to take the gerrit url from gerrit query command."); | ||
gitChangeLog.add(" - Aligned reason information with our new commit hooks"); | ||
gitChangeLog.add(" "); | ||
gitChangeLog.add(" Change-Id: Ife96d2abed5b066d9620034bec5f04cf74b8c66d"); | ||
gitChangeLog.add(" Reviewed-on: https://gerrit.e.se/12345"); | ||
gitChangeLog.add(" Tested-by: Jenkins <jenkins@no-mail.com>"); | ||
gitChangeLog.add(" Reviewed-by: Mister Another <mister.another@ericsson.com>"); | ||
gitChangeLog.add(""); | ||
changeSet = new GitChangeSet(gitChangeLog, useAuthorName); | ||
} | ||
|
||
@Test | ||
public void testGetDate() { | ||
assertEquals(useAuthorName ? "2013-03-21T09:16:44-0600 +0100" : "2013-03-25T02:18:59-0600 -0400", changeSet.getDate()); | ||
} | ||
|
||
@Test | ||
public void testGetTimestamp() { | ||
assertEquals(useAuthorName ? 1363879004000L : 1364199539000L, changeSet.getTimestamp()); | ||
} | ||
|
||
@Test | ||
public void testGetCommitId() { | ||
assertEquals(id, changeSet.getCommitId()); | ||
} | ||
|
||
@Test | ||
public void testSetParent() { | ||
changeSet.setParent(null); | ||
assertNull(changeSet.getParent()); | ||
} | ||
|
||
@Test | ||
public void testGetParentCommit() { | ||
assertEquals(parent, changeSet.getParentCommit()); | ||
} | ||
|
||
@Test | ||
public void testGetAffectedPaths() { | ||
assertTrue(changeSet.getAffectedPaths().isEmpty()); | ||
} | ||
|
||
@Test | ||
public void testGetPaths() { | ||
assertTrue(changeSet.getPaths().isEmpty()); | ||
} | ||
|
||
@Test | ||
public void testGetAffectedFiles() { | ||
assertTrue(changeSet.getAffectedFiles().isEmpty()); | ||
} | ||
|
||
@Test | ||
public void testGetAuthorName() { | ||
assertEquals(useAuthorName ? authorName : committerName, changeSet.getAuthorName()); | ||
} | ||
|
||
@Test | ||
public void testGetMsg() { | ||
assertEquals(msg, changeSet.getMsg()); | ||
} | ||
|
||
@Test | ||
public void testGetId() { | ||
assertEquals(id, changeSet.getId()); | ||
} | ||
|
||
@Test | ||
public void testGetRevision() { | ||
assertEquals(id, changeSet.getRevision()); | ||
} | ||
|
||
@Test | ||
public void testGetComment() { | ||
assertTrue(changeSet.getComment().startsWith(commentStartText)); | ||
} | ||
|
||
@Test | ||
public void testGetBranch() { | ||
assertNull(changeSet.getBranch()); | ||
} | ||
|
||
@Test | ||
public void testHashCode() { | ||
assertTrue(changeSet.hashCode() != 0); | ||
} | ||
|
||
@Test | ||
public void testEquals() { | ||
assertFalse(changeSet.equals(null)); | ||
} | ||
} |
Oops, something went wrong.