• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.xtremelabs.robolectric.shadows;
2 
3 import static org.junit.Assert.*;
4 
5 import java.io.File;
6 
7 import org.junit.After;
8 import org.junit.Test;
9 import org.junit.runner.RunWith;
10 
11 import android.os.Environment;
12 
13 import com.xtremelabs.robolectric.WithTestDefaultsRunner;
14 
15 import static org.hamcrest.CoreMatchers.equalTo;
16 
17 @RunWith(WithTestDefaultsRunner.class)
18 public class EnvironmentTest {
19 
20 	@After
tearDown()21 	public void tearDown() throws Exception {
22 		deleteDir(ShadowContext.EXTERNAL_CACHE_DIR);
23 		deleteDir(ShadowContext.EXTERNAL_FILES_DIR);
24 		ShadowEnvironment.setExternalStorageState("removed");
25 	}
26 
27 	@Test
testExternalStorageState()28 	public void testExternalStorageState() {
29 		assertThat( Environment.getExternalStorageState(), equalTo("removed") );
30 		ShadowEnvironment.setExternalStorageState("mounted");
31 		assertThat( Environment.getExternalStorageState(), equalTo("mounted") );
32 	}
33 
34 	@Test
testGetExternalStorageDirectory()35 	public void testGetExternalStorageDirectory() {
36 		 assertTrue(Environment.getExternalStorageDirectory().exists());
37 	}
38 
39 	@Test
testGetExternalStoragePublicDirectory()40 	public void testGetExternalStoragePublicDirectory() {
41 		File extStoragePublic = Environment.getExternalStoragePublicDirectory("Movies");
42 		assertTrue(extStoragePublic.exists());
43 		assertThat(extStoragePublic, equalTo( new File(ShadowContext.EXTERNAL_FILES_DIR, "Movies" ) ) );
44 	}
45 
deleteDir(File path)46     public void deleteDir(File path) {
47 		if (path.isDirectory()) {
48 			File[] files = path.listFiles();
49 			for (File f : files) {
50 				deleteDir(f);
51 			}
52 		}
53 		path.delete();
54 	}
55 
56 }
57