|
| 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 java.util.Arrays; |
| 7 | +import java.util.Collections; |
| 8 | +import org.junit.jupiter.api.Test; |
| 9 | + |
| 10 | +/** |
| 11 | + * @author Robin Müller |
| 12 | + */ |
| 13 | +class PullRequestLabelFilterImplTest { |
| 14 | + |
| 15 | + @Test |
| 16 | + void includeLabels() { |
| 17 | + PullRequestLabelFilterImpl pullRequestLabelFilter = new PullRequestLabelFilterImpl("include, include2", ""); |
| 18 | + |
| 19 | + assertThat(pullRequestLabelFilter.isPullRequestAllowed(Collections.singleton("include")), is(true)); |
| 20 | + assertThat(pullRequestLabelFilter.isPullRequestAllowed(Collections.singleton("include2")), is(true)); |
| 21 | + assertThat(pullRequestLabelFilter.isPullRequestAllowed(Collections.singleton("other-label")), is(false)); |
| 22 | + } |
| 23 | + |
| 24 | + @Test |
| 25 | + void excludeLabels() { |
| 26 | + PullRequestLabelFilterImpl pullRequestLabelFilter = new PullRequestLabelFilterImpl("", "exclude, exclude2"); |
| 27 | + |
| 28 | + assertThat(pullRequestLabelFilter.isPullRequestAllowed(Collections.singleton("exclude")), is(false)); |
| 29 | + assertThat(pullRequestLabelFilter.isPullRequestAllowed(Collections.singleton("exclude2")), is(false)); |
| 30 | + assertThat(pullRequestLabelFilter.isPullRequestAllowed(Collections.singleton("other-label")), is(true)); |
| 31 | + assertThat(pullRequestLabelFilter.isPullRequestAllowed(Collections.emptySet()), is(true)); |
| 32 | + } |
| 33 | + |
| 34 | + @Test |
| 35 | + void includeAndExcludeLabels() { |
| 36 | + PullRequestLabelFilterImpl pullRequestLabelFilter = |
| 37 | + new PullRequestLabelFilterImpl("include, include2", "exclude, exclude2"); |
| 38 | + |
| 39 | + assertThat(pullRequestLabelFilter.isPullRequestAllowed(Collections.singleton("include")), is(true)); |
| 40 | + assertThat(pullRequestLabelFilter.isPullRequestAllowed(Collections.singleton("include2")), is(true)); |
| 41 | + assertThat(pullRequestLabelFilter.isPullRequestAllowed(Collections.singleton("exclude")), is(false)); |
| 42 | + assertThat(pullRequestLabelFilter.isPullRequestAllowed(Collections.singleton("exclude2")), is(false)); |
| 43 | + assertThat(pullRequestLabelFilter.isPullRequestAllowed(Collections.singleton("other-label")), is(false)); |
| 44 | + assertThat(pullRequestLabelFilter.isPullRequestAllowed(Arrays.asList("include", "exclude")), is(false)); |
| 45 | + } |
| 46 | +} |
0 commit comments