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 @@ -19,9 +19,11 @@

import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.jupiter.api.Tag;
import org.junit.runners.Suite;

/**
Expand All @@ -46,6 +48,16 @@ public static Class<?>[] getCategoryAnnotations(Class<?> c) {
return new Class<?>[0];
}

public static String[] getTagAnnotations(Class<?> c) {
// TODO handle optional Tags annotation
Tag[] tags = c.getAnnotationsByType(Tag.class);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this used for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the replacement for @category in Junit 5.

Copy link
Contributor Author

@stoty stoty Sep 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test is for checking that all test classes have some kind of @category (or now @tag) annotation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, also comment on another PR, we'd better introduce String constants for these tags.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried, but String constants are not accepted, only literals.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correction: it works as long as it's a simple static string.
I tried to initialize it with Class.toString() that one did not work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Going to open a new ticket and PR

List<String> values = new ArrayList<>();
for (Tag tag : tags) {
values.add(tag.value());
}
return values.toArray(new String[values.size()]);
}

/** Filters both test classes and anything in the hadoop-compat modules */
public static class TestFileNameFilter implements FileNameFilter, ResourcePathFilter {
private static final Pattern hadoopCompactRe = Pattern.compile("hbase-hadoop\\d?-compat");
Expand Down Expand Up @@ -92,7 +104,10 @@ private boolean isTestClass(Class<?> c) {
}

for (Method met : c.getMethods()) {
if (met.getAnnotation(Test.class) != null) {
if (
met.getAnnotation(org.junit.Test.class) != null
|| met.getAnnotation(org.junit.jupiter.api.Test.class) != null
) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,15 @@ public void checkClasses() throws Exception {
List<Class<?>> badClasses = new java.util.ArrayList<>();
ClassTestFinder classFinder = new ClassTestFinder();
for (Class<?> c : classFinder.findClasses(false)) {
if (ClassTestFinder.getCategoryAnnotations(c).length == 0) {
if (
ClassTestFinder.getCategoryAnnotations(c).length == 0
&& ClassTestFinder.getTagAnnotations(c).length == 0
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is where we check for either.

) {
badClasses.add(c);
}
}
assertTrue("There are " + badClasses.size() + " test classes without category: " + badClasses,
assertTrue(
"There are " + badClasses.size() + " test classes without category and tag: " + badClasses,
badClasses.isEmpty());
}
}