Skip to content
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 @@ -5,7 +5,9 @@
import org.testng.IMethodInstance;

import java.lang.reflect.Method;
import java.util.Optional;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static java.util.Objects.nonNull;

Expand All @@ -22,7 +24,10 @@ private TestIdUtils() {
* @return Optional of either the {@link TmsLink} or {@link Issue} value.
* @throws IllegalStateException if {@link TmsLink} and {@link Issue}
* are specified inconstantly.
* @deprecated Use
* {@link com.frameworkium.core.common.reporting.TestIdUtils#getIssueOrTmsLinkValues(IMethodInstance)} instead
*/
@Deprecated
public static Optional<String> getIssueOrTmsLinkValue(IMethodInstance iMethod) {
Method method = iMethod.getMethod().getConstructorOrMethod().getMethod();
return getIssueOrTmsLinkValue(method);
Expand All @@ -34,7 +39,10 @@ public static Optional<String> getIssueOrTmsLinkValue(IMethodInstance iMethod) {
*
* @param method the method to check for test ID annotations.
* @return Optional of the {@link TmsLink} or {@link Issue} value.
* @deprecated Use
* {@link com.frameworkium.core.common.reporting.TestIdUtils#getIssueOrTmsLinkValues(Method)} instead.
*/
@Deprecated
public static Optional<String> getIssueOrTmsLinkValue(Method method) {
TmsLink tcIdAnnotation = method.getAnnotation(TmsLink.class);
Issue issueAnnotation = method.getAnnotation(Issue.class);
Expand All @@ -47,4 +55,36 @@ public static Optional<String> getIssueOrTmsLinkValue(Method method) {
return Optional.empty();
}
}

/**
* Get list of {@link TmsLink} or {@link Issue}.
*
* @param iMethod the {@link IMethodInstance} to check for test ID annotations.
* @return List of either the {@link TmsLink} or {@link Issue} value.
* @throws IllegalStateException if {@link TmsLink} and {@link Issue}
* are specified inconstantly.
*/
public static List<String> getIssueOrTmsLinkValues(IMethodInstance iMethod) {
Method method = iMethod.getMethod().getConstructorOrMethod().getMethod();
return getIssueOrTmsLinkValues(method);
}

/**
* Get a list of {@link TmsLink} or {@link Issue} for a method.
* If both are specified it will return just the list of {@link TmsLink} values.
*
* @param method the method to check for test Id annotations.
* @return List of {@link TmsLink} or {@link Issue} values.
*/
public static List<String> getIssueOrTmsLinkValues(Method method) {
TmsLink[] tcIdAnnotations = method.getAnnotationsByType(TmsLink.class);
Issue[] issueAnnotations = method.getAnnotationsByType(Issue.class);
if (tcIdAnnotations.length > 0) {
return Stream.of(tcIdAnnotations).map(TmsLink::value).collect(Collectors.toList());
}
if (issueAnnotations.length > 0) {
return Stream.of(issueAnnotations).map(Issue::value).collect(Collectors.toList());
}
return Collections.emptyList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,33 @@ class TestIdUtilsSpec extends Specification {
then:
value == expectedValue
where:
methodName | expectedValue
"none" | Optional.empty()
"tmsLink" | Optional.of("TMSLink")
"issue" | Optional.of("ISSUE")
"bothSame" | Optional.of("SAME")
"bothDifferent" | Optional.of("TMSLink")
methodName | expectedValue
"none" | Optional.empty()
"tmsLink" | Optional.of("TMSLink")
"issue" | Optional.of("ISSUE")
"bothSame" | Optional.of("SAME")
"bothDifferent" | Optional.of("TMSLink")
"multipleTmsLink" | Optional.empty()
"multipleTmsLinkAndIssue" | Optional.empty()
"multipleIssue" | Optional.empty()
}

def "GetIssueOrTmsLinkValues get TmsLink or Issue values for method #methodName"() {
when:
def value = TestIdUtils.getIssueOrTmsLinkValues(
TestIdData.getMethod(methodName))
then:
value == expectedValue
where:
methodName | expectedValue
"none" | []
"tmsLink" | ["TMSLink"]
"issue" | ["ISSUE"]
"bothSame" | ["SAME"]
"bothDifferent" | ["TMSLink"]
"multipleTmsLink" | ["TMSLink1", "TMSLink2"]
"multipleTmsLinkAndIssue" | ["TMSLink3", "TMSLink4"]
"multipleIssue" | ["Issue3", "Issue4"]
}

class TestIdData {
Expand All @@ -40,6 +61,20 @@ class TestIdUtilsSpec extends Specification {
@TmsLink("TMSLink")
@Issue("ISSUE")
void bothDifferent() {}

@TmsLink("TMSLink1")
@TmsLink("TMSLink2")
void multipleTmsLink() {}

@Issue("Issue1")
@Issue("Issue2")
@TmsLink("TMSLink3")
@TmsLink("TMSLink4")
void multipleTmsLinkAndIssue() {}

@Issue("Issue3")
@Issue("Issue4")
void multipleIssue() {}
}
}