|
34 | 34 | import jenkins.scm.api.trait.SCMHeadPrefilter;
|
35 | 35 | import jenkins.scm.impl.NullSCMSource;
|
36 | 36 | import org.apache.commons.lang3.time.DateUtils;
|
37 |
| -import org.junit.jupiter.api.Test; |
38 | 37 | import org.junit.jupiter.params.ParameterizedTest;
|
39 | 38 | import org.junit.jupiter.params.provider.Arguments;
|
40 | 39 | import org.junit.jupiter.params.provider.MethodSource;
|
|
43 | 42 |
|
44 | 43 | class DiscardOldTagTraitTest {
|
45 | 44 |
|
46 |
| - static Stream<Arguments> verify_that_tag_is_not_excluded_args() { |
| 45 | + static Stream<Arguments> tagSCMHeadProvider() { |
47 | 46 | return Stream.of(
|
48 |
| - Arguments.argumentSet("too_recent", |
49 |
| - new BitbucketTagSCMHead("tag/1234", DateUtils.addDays(new Date(), -4).getTime())), |
50 |
| - Arguments.argumentSet("no_timestamp", new BitbucketTagSCMHead("tag/zer0", 0L)), |
51 |
| - Arguments.argumentSet("not_a_tag", new BranchSCMHead("someBranch")) |
| 47 | + Arguments.argumentSet("expired", new BitbucketTagSCMHead("tag/1234", DateUtils.addDays(new Date(), -6).getTime()), true), |
| 48 | + Arguments.argumentSet("too_recent", new BitbucketTagSCMHead("tag/1234", DateUtils.addDays(new Date(), -4).getTime()), false), |
| 49 | + Arguments.argumentSet("no_timestamp", new BitbucketTagSCMHead("tag/zer0", 0L), false), |
| 50 | + Arguments.argumentSet("not_a_tag", new BranchSCMHead("someBranch"), false) |
52 | 51 | );
|
53 | 52 | }
|
54 | 53 |
|
55 | 54 | @ParameterizedTest
|
56 |
| - @MethodSource("verify_that_tag_is_not_excluded_args") |
57 |
| - void verify_that_tag_is_not_excluded(SCMHead head) { |
| 55 | + @MethodSource("tagSCMHeadProvider") |
| 56 | + void verify_that_tag_is_not_excluded(SCMHead head, boolean expectedResult) { |
58 | 57 | DiscardOldTagTrait trait = new DiscardOldTagTrait(5);
|
59 | 58 | BitbucketSCMSourceContext ctx = new BitbucketSCMSourceContext(null, SCMHeadObserver.none());
|
60 | 59 | trait.decorateContext(ctx);
|
61 | 60 | assertThat(ctx.prefilters()).hasAtLeastOneElementOfType(ExcludeOldSCMTag.class);
|
62 | 61 |
|
63 | 62 | for (SCMHeadPrefilter filter : ctx.prefilters()) {
|
64 |
| - assertThat(filter.isExcluded(new NullSCMSource(), head)).isFalse(); |
65 |
| - } |
66 |
| - } |
67 |
| - |
68 |
| - @Test |
69 |
| - void verify_that_tag_is_excluded_if_expired() { |
70 |
| - DiscardOldTagTrait trait = new DiscardOldTagTrait(5); |
71 |
| - BitbucketSCMSourceContext ctx = new BitbucketSCMSourceContext(null, SCMHeadObserver.none()); |
72 |
| - trait.decorateContext(ctx); |
73 |
| - assertThat(ctx.prefilters()).hasAtLeastOneElementOfType(ExcludeOldSCMTag.class); |
74 |
| - |
75 |
| - Date now = new Date(); |
76 |
| - |
77 |
| - BitbucketTagSCMHead head = new BitbucketTagSCMHead("tag/1234", DateUtils.addDays(now, -6).getTime()); |
78 |
| - |
79 |
| - for (SCMHeadPrefilter filter : ctx.prefilters()) { |
80 |
| - assertThat(filter.isExcluded(new NullSCMSource(), head)).isTrue(); |
| 63 | + assertThat(filter.isExcluded(new NullSCMSource(), head)).isEqualTo(expectedResult); |
81 | 64 | }
|
82 | 65 | }
|
83 | 66 |
|
|
0 commit comments