Fixed #638 - Don't NPE if one of the filter specs is not specified in a Jenkinsfile
This commit is contained in:
parent
45217ac90c
commit
5670e3df84
|
@ -4,6 +4,7 @@ import com.google.common.base.Splitter;
|
|||
import org.springframework.util.AntPathMatcher;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -49,6 +50,9 @@ class NameBasedFilter implements BranchFilter {
|
|||
}
|
||||
|
||||
private List<String> convert(String commaSeparatedString) {
|
||||
if (commaSeparatedString == null)
|
||||
return Collections.EMPTY_LIST;
|
||||
|
||||
ArrayList<String> result = new ArrayList<>();
|
||||
for (String s : Splitter.on(',').omitEmptyStrings().trimResults().split(commaSeparatedString)) {
|
||||
result.add(s);
|
||||
|
|
|
@ -16,6 +16,7 @@ public class NameBasedFilterTest {
|
|||
|
||||
assertThat(nameBasedFilter.isBranchAllowed("master"), is(true));
|
||||
assertThat(nameBasedFilter.isBranchAllowed("develop"), is(true));
|
||||
assertThat(nameBasedFilter.isBranchAllowed("not-included-branch"), is(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -35,4 +36,29 @@ public class NameBasedFilterTest {
|
|||
assertThat(nameBasedFilter.isBranchAllowed("develop"), is(false));
|
||||
assertThat(nameBasedFilter.isBranchAllowed("not-excluded-and-not-included-branch"), is(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void allowIncludeAndExcludeToBeNull() {
|
||||
NameBasedFilter nameBasedFilter = new NameBasedFilter(null, null);
|
||||
|
||||
assertThat(nameBasedFilter.isBranchAllowed("master"), is(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void allowIncludeToBeNull() {
|
||||
NameBasedFilter nameBasedFilter = new NameBasedFilter(null, "master, develop");
|
||||
|
||||
assertThat(nameBasedFilter.isBranchAllowed("master"), is(false));
|
||||
assertThat(nameBasedFilter.isBranchAllowed("develop"), is(false));
|
||||
assertThat(nameBasedFilter.isBranchAllowed("not-excluded-branch"), is(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void allowExcludeToBeNull() {
|
||||
NameBasedFilter nameBasedFilter = new NameBasedFilter("master, develop", null);
|
||||
|
||||
assertThat(nameBasedFilter.isBranchAllowed("master"), is(true));
|
||||
assertThat(nameBasedFilter.isBranchAllowed("develop"), is(true));
|
||||
assertThat(nameBasedFilter.isBranchAllowed("not-included-branch"), is(false));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue