1package com.xtremelabs.robolectric.shadows;
2
3import static org.junit.Assert.*;
4
5import java.io.File;
6
7import org.junit.After;
8import org.junit.Test;
9import org.junit.runner.RunWith;
10
11import android.os.Environment;
12
13import com.xtremelabs.robolectric.WithTestDefaultsRunner;
14
15import static org.hamcrest.CoreMatchers.equalTo;
16
17@RunWith(WithTestDefaultsRunner.class)
18public class EnvironmentTest {
19
20	@After
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
28	public void testExternalStorageState() {
29		assertThat( Environment.getExternalStorageState(), equalTo("removed") );
30		ShadowEnvironment.setExternalStorageState("mounted");
31		assertThat( Environment.getExternalStorageState(), equalTo("mounted") );
32	}
33
34	@Test
35	public void testGetExternalStorageDirectory() {
36		 assertTrue(Environment.getExternalStorageDirectory().exists());
37	}
38
39	@Test
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
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