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

Add public CategoryFilter constructor that was removed in JUnit 4.12 #1403

Merged
merged 3 commits into from
Jan 10, 2017

Conversation

kcooney
Copy link
Member

@kcooney kcooney commented Jan 2, 2017

Note that this constructor was removed in #503

@kcooney kcooney force-pushed the CategoryFilter-constructor branch 3 times, most recently from a1e22da to 6ec5c8d Compare January 2, 2017 02:07
@kcooney kcooney added the 4.13 label Jan 2, 2017
Copy link
Member

@marcphilipp marcphilipp left a comment

Choose a reason for hiding this comment

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

Looks good in general, just some minor suggestions.

final Set<Class<?>> set= new HashSet<Class<?>>();
if (t != null) {
Collections.addAll(set, t);
private static Set<Class<?>> createSet(Class<?>[] t) {
Copy link
Member

Choose a reason for hiding this comment

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

While you're at it, can you please rename t to something with a little more meaning?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

Copy link
Member Author

Choose a reason for hiding this comment

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

Done


return t.length == 1
? Collections.<Class<?>>singleton(t[0])
: new HashSet<Class<?>>(Arrays.asList(t));
Copy link
Member

Choose a reason for hiding this comment

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

How about a LinkedHashSet so the iteration order stays intact?

Copy link
Member Author

Choose a reason for hiding this comment

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

The previous code used HashSet for this case. I don't think ordering matters, since these are inclusion/exclusion filters. Am I missing something?

Copy link
Member

Choose a reason for hiding this comment

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

You're right: The ordering doesn't really matter. In general, I like to preserve it whenever possible so it's easier to debug/test and to not confuse users with a different order in error messages. However, in this case using HashSet should be fine.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point about debugging. The toString() and describe() methods do print out the categories. Printing them in the same order makes sense. Changed to use LinkedHashSet in a separate commit

Copy link
Member

Choose a reason for hiding this comment

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

👍

included = createSet(inclusions);
excluded = createSet(exclusions);
}

Copy link
Member

Choose a reason for hiding this comment

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

Is it possible to remove the duplication in these constructors by having only a single private one that does the assignments?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think doing that would sacrifice readability

Copy link
Member

Choose a reason for hiding this comment

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

Ok

This makes describe() and toString() print the categories in the
same order that they were provided to the user.
@kcooney kcooney force-pushed the CategoryFilter-constructor branch from 6ec5c8d to 07bd583 Compare January 3, 2017 04:35
@kcooney kcooney merged commit d112596 into junit-team:master Jan 10, 2017
@kcooney kcooney modified the milestone: 4.13 Aug 6, 2017
@kcooney kcooney removed the 4.13 label Aug 6, 2017
sebasjm pushed a commit to sebasjm/junit4 that referenced this pull request Mar 11, 2018
…unit-team#1403)

* Add back public CategoryFilter constructor that was removed in JUnit 4.12.

* Remove duplicated code that handles null categories.

* Change CategoryFilter to use LinkedHashSet().

This makes describe() and toString() print the categories in the
same order that they were provided to the user.
aristotle0x01 pushed a commit to aristotle0x01/junit4 that referenced this pull request Jun 27, 2022
…unit-team#1403)

* Add back public CategoryFilter constructor that was removed in JUnit 4.12.

* Remove duplicated code that handles null categories.

* Change CategoryFilter to use LinkedHashSet().

This makes describe() and toString() print the categories in the
same order that they were provided to the user.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants