package android.view.autofill;
import static com.google.common.truth.Truth.assertThat;
+import static com.google.common.truth.Truth.assertWithMessage;
import static org.testng.Assert.assertThrows;
final AutofillId realIdSame = new AutofillId(42);
assertThat(realId).isEqualTo(realIdSame);
assertThat(realIdSame).isEqualTo(realId);
+ assertEqualsIgnoreSession(realId, realIdSame);
+ assertEqualsIgnoreSession(realIdSame, realId);
assertThat(realId.hashCode()).isEqualTo(realIdSame.hashCode());
final AutofillId realIdDifferent = new AutofillId(108);
assertThat(realId).isNotEqualTo(realIdDifferent);
assertThat(realIdDifferent).isNotEqualTo(realId);
+ assertNotEqualsIgnoreSession(realId, realIdDifferent);
+ assertNotEqualsIgnoreSession(realIdDifferent, realId);
+ assertThat(realId.hashCode()).isNotEqualTo(realIdDifferent.hashCode());
final AutofillId virtualId = new AutofillId(42, 1);
final AutofillId virtualIdSame = new AutofillId(42, 1);
assertThat(virtualId).isEqualTo(virtualIdSame);
assertThat(virtualIdSame).isEqualTo(virtualId);
+ assertEqualsIgnoreSession(virtualId, virtualIdSame);
+ assertEqualsIgnoreSession(virtualIdSame, virtualId);
assertThat(virtualId.hashCode()).isEqualTo(virtualIdSame.hashCode());
assertThat(virtualId).isNotEqualTo(realId);
assertThat(realId).isNotEqualTo(virtualId);
+ assertNotEqualsIgnoreSession(realId, virtualId);
+ assertNotEqualsIgnoreSession(virtualId, realId);
final AutofillId virtualIdDifferentChild = new AutofillId(42, 2);
assertThat(virtualIdDifferentChild).isNotEqualTo(virtualId);
assertThat(virtualId).isNotEqualTo(virtualIdDifferentChild);
+ assertNotEqualsIgnoreSession(virtualIdDifferentChild, virtualId);
+ assertNotEqualsIgnoreSession(virtualId, virtualIdDifferentChild);
assertThat(virtualIdDifferentChild).isNotEqualTo(realId);
assertThat(realId).isNotEqualTo(virtualIdDifferentChild);
+ assertNotEqualsIgnoreSession(virtualIdDifferentChild, realId);
+ assertNotEqualsIgnoreSession(realId, virtualIdDifferentChild);
final AutofillId virtualIdDifferentParent = new AutofillId(108, 1);
assertThat(virtualIdDifferentParent).isNotEqualTo(virtualId);
assertThat(virtualId).isNotEqualTo(virtualIdDifferentParent);
+ assertNotEqualsIgnoreSession(virtualIdDifferentParent, virtualId);
+ assertNotEqualsIgnoreSession(virtualId, virtualIdDifferentParent);
assertThat(virtualIdDifferentParent).isNotEqualTo(virtualIdDifferentChild);
assertThat(virtualIdDifferentChild).isNotEqualTo(virtualIdDifferentParent);
+ assertNotEqualsIgnoreSession(virtualIdDifferentParent, virtualIdDifferentChild);
+ assertNotEqualsIgnoreSession(virtualIdDifferentChild, virtualIdDifferentParent);
final AutofillId virtualIdDifferentSession = new AutofillId(new AutofillId(42), 1L, 108);
assertThat(virtualIdDifferentSession).isNotEqualTo(virtualId);
assertThat(virtualId).isNotEqualTo(virtualIdDifferentSession);
+ if (false) { // TODO: doesn't work because one object uses int virtual ids, other uses long
+ assertEqualsIgnoreSession(virtualIdDifferentSession, virtualId);
+ assertEqualsIgnoreSession(virtualId, virtualIdDifferentSession);
+ }
assertThat(virtualIdDifferentSession).isNotEqualTo(realId);
assertThat(realId).isNotEqualTo(virtualIdDifferentSession);
+ assertNotEqualsIgnoreSession(virtualIdDifferentSession, realId);
+ assertNotEqualsIgnoreSession(realId, virtualIdDifferentSession);
final AutofillId sameVirtualIdDifferentSession =
new AutofillId(new AutofillId(42), 1L, 108);
assertThat(sameVirtualIdDifferentSession).isEqualTo(virtualIdDifferentSession);
assertThat(virtualIdDifferentSession).isEqualTo(sameVirtualIdDifferentSession);
+ assertEqualsIgnoreSession(sameVirtualIdDifferentSession, virtualIdDifferentSession);
+ assertEqualsIgnoreSession(virtualIdDifferentSession, sameVirtualIdDifferentSession);
assertThat(sameVirtualIdDifferentSession.hashCode())
.isEqualTo(virtualIdDifferentSession.hashCode());
}
+ @Test
+ public void testEqualsIgnoreSession() {
+ final AutofillId id1 = new AutofillId(new AutofillId(42), 1L, 108);
+ final AutofillId id2 = new AutofillId(new AutofillId(42), 1L, 666);
+ assertThat(id1).isNotEqualTo(id2);
+ assertThat(id2).isNotEqualTo(id1);
+ assertEqualsIgnoreSession(id1, id2);
+ assertEqualsIgnoreSession(id2, id1);
+ }
+
private AutofillId cloneThroughParcel(AutofillId id) {
Parcel parcel = Parcel.obtain();
parcel.recycle();
}
}
+
+ public static void assertEqualsIgnoreSession(AutofillId id1, AutofillId id2) {
+ assertWithMessage("id1 is null").that(id1).isNotNull();
+ assertWithMessage("id2 is null").that(id2).isNotNull();
+ assertWithMessage("%s is not equal to %s", id1, id2).that(id1.equalsIgnoreSession(id2))
+ .isTrue();
+ }
+
+ public static void assertNotEqualsIgnoreSession(AutofillId id1, AutofillId id2) {
+ assertWithMessage("id1 is null").that(id1).isNotNull();
+ assertWithMessage("id2 is null").that(id2).isNotNull();
+ assertWithMessage("%s is not equal to %s", id1, id2).that(id1.equalsIgnoreSession(id2))
+ .isFalse();
+ }
}