Skip to content
Permalink
Browse files

Merge pull request #115 from thesam/jenkins15235

[FIXES JENKINS-15235] Add whitespace trimming of branch name.
  • Loading branch information...
ndeloof committed Dec 19, 2012
2 parents 707a991 + 7a1e61e commit 442eecdd44365a3d3420578db3c9e8325c7aec8e
@@ -29,18 +29,18 @@ public String getName() {
return name;
}

public void setName(String value) {
this.name = value;
}

@DataBoundConstructor
public BranchSpec(String name) {
if(name == null)
public void setName(String name) {
if(name == null)
throw new IllegalArgumentException();
else if(name.length() == 0)
this.name = "**";
else
this.name = name;
this.name = name.trim();
}

@DataBoundConstructor
public BranchSpec(String name) {
setName(name);
}

public String toString() {
@@ -45,4 +45,27 @@ public void testMatch() {
Assert.assertTrue(p.matches("origin/x"));
Assert.assertFalse(p.matches("origin/my-branch/b1"));
}

public void testEmptyName() {
BranchSpec branchSpec = new BranchSpec("");
assertEquals("**",branchSpec.getName());
}

public void testNullName() {
boolean correctExceptionThrown = false;
try {
BranchSpec branchSpec = new BranchSpec(null);
} catch (IllegalArgumentException e) {
correctExceptionThrown = true;
}
assertTrue(correctExceptionThrown);
}

public void testNameTrimming() {
BranchSpec branchSpec = new BranchSpec(" master ");
assertEquals("master",branchSpec.getName());
branchSpec.setName(" other ");
assertEquals("other",branchSpec.getName());
}

}

0 comments on commit 442eecd

Please sign in to comment.
You can’t perform that action at this time.