Skip to content

Commit 02b5016

Browse files
authored
added AllBranchesFilterTest.java nad BranchFilterFactoryTest.java (#114)
1 parent c9288f0 commit 02b5016

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.gitee.jenkins.trigger.filter;
2+
3+
import static org.hamcrest.CoreMatchers.is;
4+
import static org.hamcrest.MatcherAssert.assertThat;
5+
6+
import org.apache.commons.lang.RandomStringUtils;
7+
import org.junit.jupiter.api.Test;
8+
9+
/**
10+
* @author Robin Müller
11+
*/
12+
class AllBranchesFilterTest {
13+
14+
@Test
15+
void isRandomBranchNameAllowed() {
16+
String randomBranchName = RandomStringUtils.random(10, true, false);
17+
18+
assertThat(new AllBranchesFilter().isBranchAllowed(randomBranchName), is(true));
19+
}
20+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.gitee.jenkins.trigger.filter;
2+
3+
import static com.gitee.jenkins.trigger.filter.BranchFilterConfig.BranchFilterConfigBuilder.branchFilterConfig;
4+
import static org.hamcrest.CoreMatchers.instanceOf;
5+
import static org.hamcrest.MatcherAssert.assertThat;
6+
7+
import org.junit.jupiter.api.Test;
8+
9+
/**
10+
* @author Robin Müller
11+
*/
12+
class BranchFilterFactoryTest {
13+
14+
@Test
15+
void getAllBranchesFilter() {
16+
BranchFilter branchFilter = BranchFilterFactory.newBranchFilter(branchFilterConfig()
17+
.withIncludeBranchesSpec("master")
18+
.withExcludeBranchesSpec("develop")
19+
.withTargetBranchRegex(".*")
20+
.build(BranchFilterType.All));
21+
22+
assertThat(branchFilter, instanceOf(AllBranchesFilter.class));
23+
}
24+
25+
@Test
26+
void getNameBasedFilterFilter() {
27+
BranchFilter branchFilter = BranchFilterFactory.newBranchFilter(branchFilterConfig()
28+
.withIncludeBranchesSpec("master")
29+
.withExcludeBranchesSpec("develop")
30+
.withTargetBranchRegex(".*")
31+
.build(BranchFilterType.NameBasedFilter));
32+
33+
assertThat(branchFilter, instanceOf(NameBasedFilter.class));
34+
}
35+
36+
@Test
37+
void getRegexBasedFilterFilter() {
38+
BranchFilter branchFilter = BranchFilterFactory.newBranchFilter(branchFilterConfig()
39+
.withIncludeBranchesSpec("master")
40+
.withExcludeBranchesSpec("develop")
41+
.withTargetBranchRegex(".*")
42+
.build(BranchFilterType.RegexBasedFilter));
43+
44+
assertThat(branchFilter, instanceOf(RegexBasedFilter.class));
45+
}
46+
}

0 commit comments

Comments
 (0)