square / assertj-android

A set of AssertJ helpers geared toward testing Android.
https://square.github.io/assertj-android/
Apache License 2.0
1.58k stars 156 forks source link

Add IntentAssert.hasFlags() #52

Closed f2prateek closed 11 years ago

f2prateek commented 11 years ago

extension of #48

I'm not sure how to retrieve each flag from the intent, so the flagToString doesn't work for multiple flags (just returns the original int value). I've been trying to look into how the system does it but haven't found it yet.

f2prateek commented 11 years ago

I updated the code to include the case for FLAG_RECEIVER_REGISTERED_ONLY. If either one of those flags (FLAG_ACTIVITY_NO_HISTORY or FLAG_RECEIVER_REGISTERED_ONLY) are in the intent, it will print out both. Let me know if you have a better suggestion for that.

Also would it be a good idea to move the actual checking in its own method given the number of times it's used? Something like

private static boolean checkHasFlag(int flags, int flag) {
  return (flags & flag) != 0;
}

So if ((flag & FLAG_ACTIVITY_BROUGHT_TO_FRONT) != 0) can be changed to if (checkHasFlag(flags,FLAG_ACTIVITY_BROUGHT_TO_FRONT))

JakeWharton commented 11 years ago

I'd go even further :)

return new BitMaskStringBuilder(flags)
    .flag(Thing.FLAG_ONE, "flagOne")
    .flag(Thing.FLAG_TWO, "flagTwo")
    .flag(Thing.FLAG_THREE, "flagThree")
    .get();