-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Asserts for CharSequence contents #1432
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
Comments
Important issue, but I would prefer to do it in You might want to consider using assertion frameworks with a fluent API (like Truth or Fest). |
The problem with I agree that picking the right method would become a bit trickier. But it's anyway better than the current lack of proper |
Could you list what specific methods you are proposing? |
So far I've been thinking of just these two: |
Could you give better examples? I would never write Also I do think DSL based frameworks are often a better fit. In Truth I would write:
Note that |
Here is an example of how it might look in a test: Adding also a |
Thanks. Since |
Good point. Though I am hesitant because having expected and actual values with the same type looks cleaner. And I would also compare the lengths first. To avoid calling |
I would like to take this feature request, please. Could it please be assigned to me. Thank you. |
@joseph-mccarthy GitHub apparently only lets you assign issues to someone on the project's team. But we almost never assign issues anyway. Feel free to submit a pull request after reading https://github.com/junit-team/junit4/blob/master/CONTRIBUTING.md |
@joseph-mccarthy are you still working on this? |
@kcooney I am assuming that @joseph-mccarthy is no longer working on this and I've opened a PR with implementation. |
@coderdeadpool JUnit 4.x is in "maintenance mode". Unless there's a critical bug or security issue there likely won't be a release in the foreseeable future, so any work you might do for this issue may not be released for a long time. If anyone is interested in this functionality, I suggest either 1) using a more robust assertion framework with a fluent API (like Truth or Fest) or 2) exploring what JUnit 5 has to offer (you should be able to use most JUnit 5 assertion APIs without migrating your tests to JUnit 5). I'm going to close this issue and the related PRs. Feel free to comment if the above suggestions don't work for you. |
A lot of APIs in Android deal with
CharSequence
. And usingassertEquals()
withCharSequence
arguments is cumbersome and unstable. One has to reproduce the exact same type which might change later.And sometimes it just does not work (e.g.
StringBuilder
uses defaultObject.equals()
implementation).Therefore I would suggest to add new methods like
assertContentEquals(CharSequence expected, CharSequence actual)
that would compare just the content, irregardless of the type it's been wrapped into.
(Pull request #949 was trying to do that with generic
assertEquals()
which is indeed questionable)I can create a pull request if you find this proposal reasonable.
The text was updated successfully, but these errors were encountered: