Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -163,17 +163,20 @@ private List<Label> getLabels(final Description result) {
).reduce(Stream::concat).orElseGet(Stream::empty).collect(Collectors.toList());
}

private <T extends Annotation> Stream<Label> getLabels(final Description result, final Class<T> clazz,
private <T extends Annotation> Stream<Label> getLabels(final Description result, final Class<T> labelAnnotation,
final Function<T, Label> extractor) {

final List<Label> onMethod = getAnnotationsOnMethod(result, clazz).stream()
final List<Label> labels = getAnnotationsOnMethod(result, labelAnnotation).stream()
.map(extractor)
.collect(Collectors.toList());
if (!onMethod.isEmpty()) {
return onMethod.stream();

if (labelAnnotation.isAnnotationPresent(Repeatable.class) || labels.isEmpty()) {
final Stream<Label> onClassLabels = getAnnotationsOnClass(result, labelAnnotation).stream()
.map(extractor);
labels.addAll(onClassLabels.collect(Collectors.toList()));
}
return getAnnotationsOnClass(result, clazz).stream()
.map(extractor);

return labels.stream();
}

private Label createLabel(final Tag tag) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@

import java.util.List;

import static io.qameta.allure.junit4.samples.TaggedTests.CLASS_TAG1;
import static io.qameta.allure.junit4.samples.TaggedTests.CLASS_TAG2;
import static io.qameta.allure.junit4.samples.TaggedTests.METHOD_TAG1;
import static io.qameta.allure.junit4.samples.TaggedTests.METHOD_TAG2;

import static org.assertj.core.api.Assertions.assertThat;

public class FeatureCombinationsTest {
Expand Down Expand Up @@ -208,6 +211,6 @@ public void shouldSetTags() throws Exception {
.flatExtracting(TestResult::getLabels)
.filteredOn(label -> "tag".equals(label.getName()))
.extracting(Label::getValue)
.containsExactlyInAnyOrder(METHOD_TAG1, METHOD_TAG2);
.containsExactlyInAnyOrder(CLASS_TAG1, CLASS_TAG2, METHOD_TAG1, METHOD_TAG2);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
/**
* @author charlie (Dmitry Baev).
*/
@DisplayName("Should be overwritten by method annotation")
public class OneTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
/**
* @author jkttt on 05.07.17.
*/
@Tags({@Tag(TaggedTests.CLASS_TAG1), @Tag(TaggedTests.CLASS_TAG2)})
public class TaggedTests {

public static final String METHOD_TAG2 = "method_tag1";
public static final String METHOD_TAG1 = "method_tag2";
public static final String CLASS_TAG = "class_tag";
public static final String CLASS_TAG1 = "class_tag1";
public static final String CLASS_TAG2 = "class_tag2";

@Test
@Tags({@Tag(METHOD_TAG1),
Expand Down