1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
package it.niedermann.nextcloud.deck.util;
import android.os.Build;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import it.niedermann.nextcloud.deck.model.Attachment;
import it.niedermann.nextcloud.deck.model.enums.EAttachmentType;
import it.niedermann.nextcloud.deck.model.ocs.Version;
import static org.junit.Assert.assertEquals;
@RunWith(RobolectricTestRunner.class)
@Config(sdk = {Build.VERSION_CODES.P})
public class AttachmentUtilTest {
@Test
public void testGetThumbnailUrl() {
final Version versionThatDoesSupportFileAttachments = new Version("1.3.0", 1, 3, 0);
final Version versionThatDoesNotSupportFileAttachments = new Version("1.2.0", 1, 2, 0);
final String accountUrl = "https://example.com";
final Attachment attachment1 = new Attachment();
attachment1.setFileId(1337L);
attachment1.setType(EAttachmentType.FILE);
final String thumbnailUrl1 = AttachmentUtil.getThumbnailUrl(versionThatDoesSupportFileAttachments, accountUrl, -1L, attachment1, 500);
assertEquals("https://example.com/index.php/core/preview?fileId=1337&x=500&y=500", thumbnailUrl1);
final Attachment attachment2 = new Attachment();
attachment2.setFileId(815L);
attachment2.setType(EAttachmentType.FILE);
final String thumbnailUrl2 = AttachmentUtil.getThumbnailUrl(versionThatDoesSupportFileAttachments, accountUrl, 0L, attachment2, 4711);
assertEquals("https://example.com/index.php/core/preview?fileId=815&x=4711&y=4711", thumbnailUrl2);
// Given there is an invalid fileId...
final Attachment attachment3 = new Attachment();
attachment3.setId(999L);
attachment3.setFileId(null);
final String thumbnailUrl3 = AttachmentUtil.getThumbnailUrl(versionThatDoesSupportFileAttachments, accountUrl, 15L, attachment3, 205);
// ... a fallback to the attachment itself should be returned
assertEquals("https://example.com/index.php/apps/deck/cards/15/attachment/999", thumbnailUrl3);
// Given the server version does not support file attachments yet...
final Attachment attachment4 = new Attachment();
attachment4.setId(111L);
attachment4.setFileId(222L);
final String thumbnailUrl4 = AttachmentUtil.getThumbnailUrl(versionThatDoesNotSupportFileAttachments, accountUrl, 333L, attachment4, 444);
// ... a fallback to the attachment itself should be returned
assertEquals("https://example.com/index.php/apps/deck/cards/333/attachment/111", thumbnailUrl4);
}
}
|