1 package org.robolectric.plugins;
2 
3 import static com.google.common.base.StandardSystemProperty.OS_NAME;
4 import static com.google.common.truth.Truth.assertThat;
5 
6 import java.util.Properties;
7 import org.junit.Test;
8 import org.junit.runner.RunWith;
9 import org.junit.runners.JUnit4;
10 import org.robolectric.annotation.SQLiteMode;
11 import org.robolectric.annotation.SQLiteMode.Mode;
12 
13 /** Unit tests for methods annotated with @{@link SQLiteMode}. */
14 @RunWith(JUnit4.class)
15 public class SQLiteModeConfigurerTest {
16 
17   @Test
defaultConfigWithPrePopulatedSQLiteMode()18   public void defaultConfigWithPrePopulatedSQLiteMode() {
19     Properties systemProperties1 = new Properties();
20     SQLiteModeConfigurer configurer1 =
21         new SQLiteModeConfigurer(systemProperties1, new PackagePropertiesLoader());
22 
23     systemProperties1.setProperty("robolectric.sqliteMode", "LEGACY");
24     assertThat(configurer1.defaultConfig()).isSameInstanceAs(Mode.LEGACY);
25 
26     Properties systemProperties2 = new Properties();
27     SQLiteModeConfigurer configurer2 =
28         new SQLiteModeConfigurer(systemProperties2, new PackagePropertiesLoader());
29     systemProperties2.setProperty("robolectric.sqliteMode", "NATIVE");
30     assertThat(configurer2.defaultConfig()).isSameInstanceAs(Mode.NATIVE);
31   }
32 
33   @Test
osArchSpecificConfig()34   public void osArchSpecificConfig() {
35     String oldName = OS_NAME.value();
36     try {
37       System.setProperty("os.name", "Mac OS X");
38       SQLiteModeConfigurer configurer1 =
39           new SQLiteModeConfigurer(System.getProperties(), new PackagePropertiesLoader());
40       assertThat(configurer1.defaultConfig()).isSameInstanceAs(Mode.NATIVE);
41 
42       System.setProperty("os.name", "Windows 7");
43       SQLiteModeConfigurer configurer2 =
44           new SQLiteModeConfigurer(System.getProperties(), new PackagePropertiesLoader());
45 
46       assertThat(configurer2.defaultConfig()).isSameInstanceAs(Mode.LEGACY);
47     } finally {
48       System.setProperty("os.name", oldName);
49     }
50   }
51 }
52