Assertj-core: Add isEqualToNormalizingWhitespace and change isEqualToIgnoringWhitespace to really ignore all whitespace

Created on 22 Nov 2016  路  21Comments  路  Source: assertj/assertj-core

Summary

Assertion fails when comparing strings ignoring whitespaces (assertj 3.6.0)

Example

assertThat("with white spaces").isEqualToIgnoringWhitespace("withwhitespaces");
new feature

Most helpful comment

I agree that the method name is confusing. I guess isEqualToNormalizingWhitespace would be a better name for the existing method.

All 21 comments

According to the documentation this is the expected behavior

from http://joel-costigliola.github.io/assertj/core/api/org/assertj/core/api/AbstractCharSequenceAssert.html#isEqualToIgnoringWhitespace(java.lang.CharSequence)

Verifies that the actual CharSequence is equal to the given one, ignoring whitespace differences (mostly).
To be exact, the following whitespace rules are applied:

- all leading and trailing whitespace of both actual and expected strings are ignored
- any remaining whitespace, appearing within either string, is collapsed to a single space before comparison

Ok, so is there any other method to remove all whitespaces and then compare both strings?
If not this is my feature request :)

looks like it doesn't exist yet.

The hardest part would be to find the right name for this new method :-)

I think isEqualToIgnoringWhitespace means: compare two strings and ignore all whitespaces (more, whitechars) (not only in front or end...) (do not collapse all whitespaces into single one, just get rid of them)

But now the isEqualToIgnoringWhitespace method does: compare two strings ignoring whitespaces in front and at the end, but replace multiple whitespaces with single whitespace, only when they are in the middle of string.

So now method name lies. For me.

I agree that the method name is confusing. I guess isEqualToNormalizingWhitespace would be a better name for the existing method.

In hindsight I agree that was a poor name, I like @PascalSchumacher idea so let's rename this assertion to isEqualToNormalizingWhitespace and make isEqualToIgnoringWhitespace really ignoring all whitespace.

I will try to submit a pull request for this.

I guess this can be closed, as my pull requests fixed it.

indeed, thanks.

Was This removed on the way? I am using:

testCompile group: 'org.assertj', name: 'assertj-core', version: '3.6.2'

And I have same problem!

Not sure what you mean but nothing has been removed yet, this change will be part of the next release 2.7.0/3.7.0.

Oh, ok - I thought that 2.7 was released long time ago, and now its 3.6, but it's just different branch. Sorry for interruption.

In AssertJ 2.x versions target Java 7 while 3.x target Java 8, which means that 2.6 is way newer than 3.0 ! (might be a bit confusing but http://joel-costigliola.github.io/assertj/assertj-core-quick-start.html tries to clarify that).

I'm sorry everybody. Somehow this change/addition got lost on the way to 2.7.0 / 3.7.0. I could not figure out when/how. It will be in 2.8.0 / 3.8.0. Sorry again.

@PascalSchumacher I don't know either but I likely screwed up this one.

@joel-costigliola Will this issue be part of 2.7.1?

I feel it is more 2.8.0 as it is a breaking change which I'm happy to release instead of 2.7.1.
is this already in 2.x ? (I haven't looked at it thoroughly)

I was thinking to skip 2.7.1 to release directly 2.8.0 (and move the other 2.8.0 issues to 2.9.0).
I have fixed the isBetween issue in 3.7.0, it turned out to be a bug for Instant but more a new feature for the other Temporal assertions, it makes sense to me to release also a 3.8.0 instead of 3.7.1.

Sure. :+1:

AssertJ versions 2.8.0 / 3.8.0 with include this change/addition have just been released. :smile:

Was this page helpful?
0 / 5 - 0 ratings