1+ package fr .free .nrw .commons .upload ;
2+
3+ import android .net .Uri ;
4+ import android .support .test .InstrumentationRegistry ;
5+ import android .support .test .runner .AndroidJUnit4 ;
6+
7+ import org .junit .Test ;
8+ import org .junit .runner .RunWith ;
9+
10+ import static org .hamcrest .CoreMatchers .is ;
11+ import static org .junit .Assert .assertThat ;
12+
13+ @ RunWith (AndroidJUnit4 .class )
14+ public class FileUtilsTest {
15+ @ Test
16+ public void isSelfOwned () throws Exception {
17+ Uri uri = Uri .parse ("content://fr.free.nrw.commons.provider/document/1" );
18+ boolean selfOwned = FileUtils .isSelfOwned (InstrumentationRegistry .getTargetContext (), uri );
19+ assertThat (selfOwned , is (true ));
20+ }
21+
22+ @ Test
23+ public void isNotSelfOwned () throws Exception {
24+ Uri uri = Uri .parse ("content://com.android.providers.media.documents/document/1" );
25+ boolean selfOwned = FileUtils .isSelfOwned (InstrumentationRegistry .getTargetContext (), uri );
26+ assertThat (selfOwned , is (false ));
27+ }
28+
29+ @ Test
30+ public void getPathWithExternalImage () throws Exception {
31+ String expectedPath = "/storage/emulated/0/ZetaTemp/IMG_20170703_133510.625.jpeg" ;
32+ Uri uri = Uri .parse ("content://com.android.providers.media.documents/document/image:68" );
33+ String path = FileUtils .getPath (InstrumentationRegistry .getTargetContext (), uri );
34+ assertThat (path , is (expectedPath ));
35+ }
36+
37+ @ Test
38+ public void getPathWithDownloadedImage () throws Exception {
39+ String expectedPath = "/storage/emulated/0/Download/mathematics.jpg" ;
40+ Uri uri = Uri .parse ("content://com.android.providers.downloads.documents/document/43" );
41+ String path = FileUtils .getPath (InstrumentationRegistry .getTargetContext (), uri );
42+ assertThat (path , is (expectedPath ));
43+ }
44+
45+ @ Test
46+ public void getDataColumn () throws Exception {
47+ }
48+ }
0 commit comments