use of com.simplecity.amp_library.ShuttleApplication in project Shuttle by timusus.
the class ShuttleUtilsPowerMockTest method testGetIpAddr.
@Test
public void testGetIpAddr() throws Exception {
ShuttleApplication mockApplication = mock(ShuttleApplication.class);
WifiManager mockWifiManager = mock(WifiManager.class);
WifiInfo mockWifiInfo = mock(WifiInfo.class);
// Setup mocked IP Address of 192.168.1.1
mockStatic(ShuttleApplication.class);
when(ShuttleApplication.getInstance()).thenReturn(mockApplication);
when(mockApplication.getSystemService(Context.WIFI_SERVICE)).thenReturn(mockWifiManager);
when(mockWifiManager.getConnectionInfo()).thenReturn(mockWifiInfo);
when(mockWifiInfo.getIpAddress()).thenReturn(16885952);
assertThat(ShuttleUtils.getIpAddr()).isEqualTo("192.168.1.1");
}
use of com.simplecity.amp_library.ShuttleApplication in project Shuttle by timusus.
the class ShuttleUtilsPowerMockTest method testIsOnlineWifiConnected.
@Test
public void testIsOnlineWifiConnected() {
ShuttleApplication mockApplication = mock(ShuttleApplication.class);
SharedPreferences mockSharedPreferences = mock(SharedPreferences.class);
ConnectivityManager mockConnectivityManager = mock(ConnectivityManager.class);
NetworkInfo mockNetworkInfo = mock(NetworkInfo.class);
mockStatic(PreferenceManager.class);
mockStatic(ShuttleApplication.class);
when(PreferenceManager.getDefaultSharedPreferences(any(Context.class))).thenReturn(mockSharedPreferences);
when(ShuttleApplication.getInstance()).thenReturn(mockApplication);
// Mock the connection to Wi-Fi
when(mockApplication.getSystemService(Context.CONNECTIVITY_SERVICE)).thenReturn(mockConnectivityManager);
when(mockConnectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI)).thenReturn(mockNetworkInfo);
when(mockNetworkInfo.isConnectedOrConnecting()).thenReturn(true);
// Test when we care about Wi-Fi (and it's connected), regardless of user preference
assertThat(ShuttleUtils.isOnline(true)).isTrue();
// Test when we don't care about Wi-Fi (but it's connected anyway), regardless of user preference
assertThat(ShuttleUtils.isOnline(false)).isTrue();
}
use of com.simplecity.amp_library.ShuttleApplication in project Shuttle by timusus.
the class ShuttleUtilsPowerMockTest method testIsOnlineCellularConnected.
@Test
public void testIsOnlineCellularConnected() {
ShuttleApplication mockApplication = mock(ShuttleApplication.class);
SharedPreferences mockSharedPreferences = mock(SharedPreferences.class);
ConnectivityManager mockConnectivityManager = mock(ConnectivityManager.class);
NetworkInfo mockNetworkInfo = mock(NetworkInfo.class);
mockStatic(PreferenceManager.class);
mockStatic(ShuttleApplication.class);
when(PreferenceManager.getDefaultSharedPreferences(any(Context.class))).thenReturn(mockSharedPreferences);
when(ShuttleApplication.getInstance()).thenReturn(mockApplication);
// Mock the connection to cellular data, but not Wi-Fi
when(mockApplication.getSystemService(Context.CONNECTIVITY_SERVICE)).thenReturn(mockConnectivityManager);
when(mockConnectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI)).thenReturn(null);
when(mockConnectivityManager.getActiveNetworkInfo()).thenReturn(mockNetworkInfo);
when(mockNetworkInfo.isConnectedOrConnecting()).thenReturn(true);
// Test when we care about Wi-Fi and so does the user (but only cellular is connected)
when(mockSharedPreferences.getBoolean(eq("pref_download_wifi_only"), anyBoolean())).thenReturn(true);
assertThat(ShuttleUtils.isOnline(true)).isFalse();
// Test when we care about Wi-Fi, but the user doesn't (and only cellular is connected)
when(mockSharedPreferences.getBoolean(eq("pref_download_wifi_only"), anyBoolean())).thenReturn(false);
assertThat(ShuttleUtils.isOnline(true)).isTrue();
// Test when we don't care about Wi-Fi, even if the user does (and only cellular is connected)
when(mockSharedPreferences.getBoolean(eq("pref_download_wifi_only"), anyBoolean())).thenReturn(true);
assertThat(ShuttleUtils.isOnline(false)).isTrue();
// Test when we don't care about Wi-Fi and neither does the user (and only cellular is connected)
when(mockSharedPreferences.getBoolean(eq("pref_download_wifi_only"), anyBoolean())).thenReturn(false);
assertThat(ShuttleUtils.isOnline(false)).isTrue();
}
use of com.simplecity.amp_library.ShuttleApplication in project Shuttle by timusus.
the class ShuttleUtilsPowerMockTest method testIsUpgraded.
@Test
public void testIsUpgraded() throws Exception {
ShuttleApplication mockApplication = mock(ShuttleApplication.class);
mockStatic(ShuttleApplication.class);
when(ShuttleApplication.getInstance()).thenReturn(mockApplication);
when(mockApplication.getIsUpgraded()).thenReturn(true);
assertThat(ShuttleUtils.isUpgraded()).isTrue();
when(mockApplication.getIsUpgraded()).thenReturn(false);
when(mockApplication.getPackageName()).thenReturn("com.simplecity.amp_pro");
assertThat(ShuttleUtils.isUpgraded()).isTrue();
when(mockApplication.getPackageName()).thenReturn("bad.package.name");
assertThat(ShuttleUtils.isUpgraded()).isFalse();
}
Aggregations