mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-30 13:35:18 +00:00
parent
4d8108f34d
commit
200fc0c599
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user