diff --git a/addOns/commonlib/src/main/java/org/zaproxy/addon/commonlib/PolicyTag.java b/addOns/commonlib/src/main/java/org/zaproxy/addon/commonlib/PolicyTag.java index 2f039c7f5c..26af6ce640 100644 --- a/addOns/commonlib/src/main/java/org/zaproxy/addon/commonlib/PolicyTag.java +++ b/addOns/commonlib/src/main/java/org/zaproxy/addon/commonlib/PolicyTag.java @@ -19,6 +19,10 @@ */ package org.zaproxy.addon.commonlib; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + /** * Tags to be associated with standardized scan policies which will be distributed as an add-on. * @@ -43,4 +47,8 @@ private PolicyTag() { public String getTag() { return this.tag; } + + public static List getAllTags() { + return Stream.of(PolicyTag.values()).map(PolicyTag::getTag).collect(Collectors.toList()); + } } diff --git a/addOns/commonlib/src/test/java/org/zaproxy/addon/commonlib/PolicyTagUnitTest.java b/addOns/commonlib/src/test/java/org/zaproxy/addon/commonlib/PolicyTagUnitTest.java index c55b59b749..58022ac5e5 100644 --- a/addOns/commonlib/src/test/java/org/zaproxy/addon/commonlib/PolicyTagUnitTest.java +++ b/addOns/commonlib/src/test/java/org/zaproxy/addon/commonlib/PolicyTagUnitTest.java @@ -20,11 +20,14 @@ package org.zaproxy.addon.commonlib; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.startsWith; import static org.hamcrest.core.DescribedAs.describedAs; +import java.util.List; +import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.EnumSource; @@ -44,4 +47,12 @@ void shouldHaveAllTagsStartingWithPolicyyUnderscoreInCapsEnumNamesWithout(Policy "Enum element name should not start with prefix", not(startsWith(PolicyTag.PREFIX)))); } + + @Test + void shouldHaveCompleteListWhenGettingAllTags() { + // Given / When + List tags = PolicyTag.getAllTags(); + // Then + assertThat(PolicyTag.values().length, is(equalTo(tags.size()))); + } }