square/assertj-android

Palette support library module

JakeWharton opened this issue · 7 comments

Palette support library module

Hi @JakeWharton. I implemented the Palette support library module, but the problem occured: the PaletteItem class doesn't override the equals method. So for example assertion:

public PaletteAssert hasVibrantColor(PaletteItem color) {
  isNotNull();
  PaletteItem actualColor = actual.getVibrantColor();
  assertThat(actualColor) //
      .overridingErrorMessage("Expected vibrant color <%s> but was <%s>", color, actualColor) //
      .isEqualTo(color);
  return this;
}

fails with the error for equal colors:

java.lang.AssertionError: Expected vibrant color <PaletteItem [ffeaaf11][HSL: [43.686638, 0.8645418,  
0.49215686]][Population: 1153]> but was <PaletteItem [ffeaaf11][HSL: [43.686638, 0.8645418, 
0.49215686]][Population: 1153]>

How to handle this?

For now we can check equality manually. We should file a bug on b.android.com about this as well.

Add a private static equals method in the assertion which takes two instances. Or you can also compare the toString output, but I like that a lot less.

Okay, I have opened a bug for this.

The problem with a manual equality check is that getPopulation() method is not public. However this attribute must be involved in the comparison. Using reflection is not a case, am I right?

So 2 options remain:

  • compare toString() outputs
  • wait until the equals(...) method will be addded in the upcoming releases

Use toString for now. Thanks for filing and for the work. I'll take a look
at the rest later.
On Aug 3, 2014 12:00 PM, "Melnykov Oleksandr" notifications@github.com
wrote:

Okay, I have opened a bug
https://code.google.com/p/android/issues/detail?id=74434&thanks=74434&ts=1407091929
for this.

The problem with a manual equality check is that getPopulation() method
is not public. However this attribute must be involved in the comparison.
Using reflection is not a case, am I right?

So 2 options remain:

  • compare toString() outputs
  • wait until the equals(...) methid will be addded in the upcoming
    releases


Reply to this email directly or view it on GitHub
#109 (comment)
.

Isn't there a equalsByComparingFields in assertj?

Yes, it has isEqualToComparingFieldByField method(and some other modifications), however it compares only accessible fields values. In our case getPopulation() is not accesible getter (it has the package-private visibility).