Skip to content

Commit

Permalink
commonlib: Add convenience method to get all PolicyTag tags
Browse files Browse the repository at this point in the history
Signed-off-by: kingthorin <kingthorin@users.noreply.github.com>
  • Loading branch information
kingthorin committed Nov 27, 2024
1 parent 77331fd commit 74c88b7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -43,4 +47,8 @@ private PolicyTag() {
public String getTag() {
return this.tag;
}

public static List<String> getAllTags() {
return Stream.of(PolicyTag.values()).map(PolicyTag::getTag).collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<String> tags = PolicyTag.getAllTags();
// Then
assertThat(PolicyTag.values().length, is(equalTo(tags.size())));
}
}

0 comments on commit 74c88b7

Please sign in to comment.