From 200fc0c5990fe39c291bad2bbc254c4d5af236bb Mon Sep 17 00:00:00 2001 From: Rhodey Orbits Date: Sun, 31 May 2015 16:08:40 -0700 Subject: [PATCH] fix the PartDatabase tests Closes #3210 // FREEBIE --- .../securesms/database/PartDatabase.java | 10 +++++++++ .../securesms/database/PartDatabaseTest.java | 21 ++++++++++--------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/org/thoughtcrime/securesms/database/PartDatabase.java b/src/org/thoughtcrime/securesms/database/PartDatabase.java index 938f2036e4..afca0de324 100644 --- a/src/org/thoughtcrime/securesms/database/PartDatabase.java +++ b/src/org/thoughtcrime/securesms/database/PartDatabase.java @@ -640,5 +640,15 @@ public class PartDatabase extends Database { public boolean isValid() { return rowId >= 0 && uniqueId >= 0; } + + @Override + public boolean equals(Object object) { + if (!(object instanceof PartId)){ + return false; + } + + PartId other = (PartId) object; + return rowId == other.rowId && uniqueId == other.uniqueId; + } } } diff --git a/test/androidTest/java/org/thoughtcrime/securesms/database/PartDatabaseTest.java b/test/androidTest/java/org/thoughtcrime/securesms/database/PartDatabaseTest.java index a16e426094..786e7ce1cc 100644 --- a/test/androidTest/java/org/thoughtcrime/securesms/database/PartDatabaseTest.java +++ b/test/androidTest/java/org/thoughtcrime/securesms/database/PartDatabaseTest.java @@ -4,6 +4,7 @@ import android.net.Uri; import org.thoughtcrime.securesms.TextSecureTestCase; import org.thoughtcrime.securesms.crypto.MasterSecret; +import org.thoughtcrime.securesms.database.PartDatabase.PartId; import java.io.FileNotFoundException; import java.io.InputStream; @@ -12,7 +13,6 @@ import ws.com.google.android.mms.pdu.PduPart; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyFloat; -import static org.mockito.Matchers.anyLong; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; @@ -23,7 +23,8 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; public class PartDatabaseTest extends TextSecureTestCase { - private static final long PART_ID = 1L; + private static final long ROW_ID = 1L; + private static final long UNIQUE_ID = 2L; private PartDatabase database; @@ -33,21 +34,21 @@ public class PartDatabaseTest extends TextSecureTestCase { } public void testTaskNotRunWhenThumbnailExists() throws Exception { - when(database.getPart(eq(PART_ID))).thenReturn(getPduPartSkeleton("x/x")); - doReturn(mock(InputStream.class)).when(database).getDataStream(any(MasterSecret.class), anyLong(), eq("thumbnail")); + when(database.getPart(new PartId(ROW_ID, UNIQUE_ID))).thenReturn(getPduPartSkeleton("x/x")); + doReturn(mock(InputStream.class)).when(database).getDataStream(any(MasterSecret.class), any(PartId.class), eq("thumbnail")); - database.getThumbnailStream(null, PART_ID); + database.getThumbnailStream(null, new PartId(ROW_ID, UNIQUE_ID)); - verify(database, never()).updatePartThumbnail(any(MasterSecret.class), anyLong(), any(PduPart.class), any(InputStream.class), anyFloat()); + verify(database, never()).updatePartThumbnail(any(MasterSecret.class), any(PartId.class), any(PduPart.class), any(InputStream.class), anyFloat()); } public void testTaskRunWhenThumbnailMissing() throws Exception { - when(database.getPart(eq(PART_ID))).thenReturn(getPduPartSkeleton("image/png")); - doReturn(null).when(database).getDataStream(any(MasterSecret.class), anyLong(), eq("thumbnail")); - doNothing().when(database).updatePartThumbnail(any(MasterSecret.class), anyLong(), any(PduPart.class), any(InputStream.class), anyFloat()); + when(database.getPart(new PartId(ROW_ID, UNIQUE_ID))).thenReturn(getPduPartSkeleton("image/png")); + doReturn(null).when(database).getDataStream(any(MasterSecret.class), any(PartId.class), eq("thumbnail")); + doNothing().when(database).updatePartThumbnail(any(MasterSecret.class), any(PartId.class), any(PduPart.class), any(InputStream.class), anyFloat()); try { - database.new ThumbnailFetchCallable(mock(MasterSecret.class), PART_ID).call(); + database.new ThumbnailFetchCallable(mock(MasterSecret.class), new PartId(ROW_ID, UNIQUE_ID)).call(); throw new AssertionError("didn't try to generate thumbnail"); } catch (FileNotFoundException fnfe) { // success