Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

commonlib: Add convenience method to get all PolicyTag tags #5955

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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())));
}
}