Android Open Source - twawm2 Background Service Test






From Project

Back to project page twawm2.

License

The source code is released under:

Copyright (c) 2014, afnf All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistr...

If you think the Android project twawm2 listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.appspot.afnf4199ga.twawm.app;
// w  ww.j a v a 2  s.c  o m
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import net.afnf.and.twawm2.DexmakerInstrumentationTestCase;

import org.mockito.Mockito;

import android.net.wifi.ScanResult;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiInfo;

public class BackgroundServiceTest extends DexmakerInstrumentationTestCase {

    public void testGetSwitchTargetNetworkIdSet_01() {

        Set<Integer> networkIdSet = BackgroundService.getSwitchTargetNetworkIdSet(null, "ssid-dest999;ssid-dest2", null, null);
        assertNull(networkIdSet);
    }

    public void testGetSwitchTargetNetworkIdSet_02() {

        WifiInfo connectionInfo = Mockito.mock(WifiInfo.class);
        Mockito.when(connectionInfo.getSSID()).thenReturn(null);

        Set<Integer> networkIdSet = BackgroundService.getSwitchTargetNetworkIdSet(connectionInfo, "ssid-dest999;ssid-dest2",
                null, null);
        assertNull(networkIdSet);
    }

    public void testGetSwitchTargetNetworkIdSet_03() {

        WifiInfo connectionInfo = Mockito.mock(WifiInfo.class);
        Mockito.when(connectionInfo.getSSID()).thenReturn("ssid-dest2");

        List<ScanResult> scanResults = new ArrayList<ScanResult>();
        for (int i = 0; i < 3; i++) {
            ScanResult scanResult = Mockito.mock(ScanResult.class);
            scanResult.SSID = "ssid-dest" + i;
            scanResults.add(scanResult);
        }

        List<WifiConfiguration> configuredNetworks = new ArrayList<WifiConfiguration>();
        for (int i = 0; i < 3; i++) {
            WifiConfiguration configuredNetwork = Mockito.mock(WifiConfiguration.class);
            configuredNetwork.networkId = i;
            configuredNetwork.SSID = "\"ssid-dest" + (i + 1) + "\"";
            configuredNetworks.add(configuredNetwork);
        }

        Set<Integer> networkIdSet = BackgroundService.getSwitchTargetNetworkIdSet(connectionInfo, null, scanResults,
                configuredNetworks);
        assertNull(networkIdSet);
    }

    public void testGetSwitchTargetNetworkIdSet_04() {

        WifiInfo connectionInfo = Mockito.mock(WifiInfo.class);
        Mockito.when(connectionInfo.getSSID()).thenReturn("ssid-now");

        Set<Integer> networkIdSet = BackgroundService.getSwitchTargetNetworkIdSet(connectionInfo, "ssid-dest2", null, null);
        assertNull(networkIdSet);
    }

    public void testGetSwitchTargetNetworkIdSet_05() {

        WifiInfo connectionInfo = Mockito.mock(WifiInfo.class);
        Mockito.when(connectionInfo.getSSID()).thenReturn("ssid-now");

        List<ScanResult> scanResults = new ArrayList<ScanResult>();
        for (int i = 0; i < 3; i++) {
            ScanResult scanResult = Mockito.mock(ScanResult.class);
            scanResult.SSID = "ssid-dest" + i;
            scanResults.add(scanResult);
        }

        Set<Integer> networkIdSet = BackgroundService
                .getSwitchTargetNetworkIdSet(connectionInfo, "ssid-dest2", scanResults, null);
        assertNull(networkIdSet);
    }

    public void testGetSwitchTargetNetworkIdSet_09() {

        WifiInfo connectionInfo = Mockito.mock(WifiInfo.class);
        Mockito.when(connectionInfo.getSSID()).thenReturn("ssid-dest2");

        List<ScanResult> scanResults = new ArrayList<ScanResult>();
        for (int i = 0; i < 3; i++) {
            ScanResult scanResult = Mockito.mock(ScanResult.class);
            scanResult.SSID = "ssid-dest" + i;
            scanResults.add(scanResult);
        }

        List<WifiConfiguration> configuredNetworks = new ArrayList<WifiConfiguration>();
        for (int i = 0; i < 3; i++) {
            WifiConfiguration configuredNetwork = Mockito.mock(WifiConfiguration.class);
            configuredNetwork.networkId = i;
            configuredNetwork.SSID = "\"ssid-dest" + (i + 1) + "\"";
            configuredNetworks.add(configuredNetwork);
        }

        Set<Integer> networkIdSet = BackgroundService.getSwitchTargetNetworkIdSet(connectionInfo, "ssid-dest2", scanResults,
                configuredNetworks);
        assertNull(networkIdSet);
    }

    public void testGetSwitchTargetNetworkIdSet_11() {

        WifiInfo connectionInfo = Mockito.mock(WifiInfo.class);
        Mockito.when(connectionInfo.getSSID()).thenReturn("ssid-now");

        List<ScanResult> scanResults = new ArrayList<ScanResult>();
        for (int i = 0; i < 3; i++) {
            ScanResult scanResult = Mockito.mock(ScanResult.class);
            scanResult.SSID = "ssid-dest" + i;
            scanResults.add(scanResult);
        }

        List<WifiConfiguration> configuredNetworks = new ArrayList<WifiConfiguration>();
        for (int i = 0; i < 3; i++) {
            WifiConfiguration configuredNetwork = Mockito.mock(WifiConfiguration.class);
            configuredNetwork.networkId = i;
            configuredNetwork.SSID = "\"ssid-dest" + (i + 1) + "\"";
            configuredNetworks.add(configuredNetwork);
        }

        Set<Integer> networkIdSet = BackgroundService.getSwitchTargetNetworkIdSet(connectionInfo, "ssid-dest2", scanResults,
                configuredNetworks);
        assertNotNull(networkIdSet);
        assertEquals(1, networkIdSet.size());

        Iterator<Integer> ite = networkIdSet.iterator();
        assertEquals(Integer.valueOf(1), ite.next());
    }

    public void testGetSwitchTargetNetworkIdSet_12() {

        WifiInfo connectionInfo = Mockito.mock(WifiInfo.class);
        Mockito.when(connectionInfo.getSSID()).thenReturn("ssid-now");

        List<ScanResult> scanResults = new ArrayList<ScanResult>();
        for (int i = 0; i < 3; i++) {
            ScanResult scanResult = Mockito.mock(ScanResult.class);
            scanResult.SSID = "ssid-dest" + i;
            scanResults.add(scanResult);
        }

        List<WifiConfiguration> configuredNetworks = new ArrayList<WifiConfiguration>();
        for (int i = 0; i < 3; i++) {
            WifiConfiguration configuredNetwork = Mockito.mock(WifiConfiguration.class);
            configuredNetwork.networkId = i;
            configuredNetwork.SSID = "\"ssid-dest" + (i + 1) + "\"";
            configuredNetworks.add(configuredNetwork);
        }

        Set<Integer> networkIdSet = BackgroundService.getSwitchTargetNetworkIdSet(connectionInfo, "ssid-dest999", scanResults,
                configuredNetworks);
        assertNull(networkIdSet);
    }
}




Java Source Code List

com.appspot.afnf4199ga.twawm.BluetoothHelper.java
com.appspot.afnf4199ga.twawm.Const.java
com.appspot.afnf4199ga.twawm.Const.java
com.appspot.afnf4199ga.twawm.HostnameListTest.java
com.appspot.afnf4199ga.twawm.HostnameList.java
com.appspot.afnf4199ga.twawm.IconSelectorTest.java
com.appspot.afnf4199ga.twawm.IconSelector.java
com.appspot.afnf4199ga.twawm.OnlineChecker.java
com.appspot.afnf4199ga.twawm.StateMachineTest.java
com.appspot.afnf4199ga.twawm.StateMachine.java
com.appspot.afnf4199ga.twawm.TwawmUtils.java
com.appspot.afnf4199ga.twawm.app.BackgroundServiceTest.java
com.appspot.afnf4199ga.twawm.app.BackgroundService.java
com.appspot.afnf4199ga.twawm.app.DefaultWidgetProvider.java
com.appspot.afnf4199ga.twawm.app.InfoActivity.java
com.appspot.afnf4199ga.twawm.app.InitialConfigurationWizardActivity.java
com.appspot.afnf4199ga.twawm.app.LogSendActivity.java
com.appspot.afnf4199ga.twawm.app.MainActivity.java
com.appspot.afnf4199ga.twawm.app.MainApp.java
com.appspot.afnf4199ga.twawm.app.MyPreferenceActivity.java
com.appspot.afnf4199ga.twawm.app.NetworkSwitcher.java
com.appspot.afnf4199ga.twawm.app.StaticIntentListener.java
com.appspot.afnf4199ga.twawm.app.UIAct.java
com.appspot.afnf4199ga.twawm.ctl.CustomizeActionsActivityTest.java
com.appspot.afnf4199ga.twawm.ctl.CustomizeActionsActivity.java
com.appspot.afnf4199ga.twawm.ctl.CwacTouchListView.java
com.appspot.afnf4199ga.twawm.ctl.ListItem.java
com.appspot.afnf4199ga.twawm.router.EcoModeControlTest.java
com.appspot.afnf4199ga.twawm.router.EcoModeControl.java
com.appspot.afnf4199ga.twawm.router.InetLookupWrappter.java
com.appspot.afnf4199ga.twawm.router.InetLookupWrappter.java
com.appspot.afnf4199ga.twawm.router.MyHttpClientTest.java
com.appspot.afnf4199ga.twawm.router.MyHttpClient.java
com.appspot.afnf4199ga.twawm.router.MyHttpClient.java
com.appspot.afnf4199ga.twawm.router.RouterControlByHttpTest.java
com.appspot.afnf4199ga.twawm.router.RouterControlByHttp.java
com.appspot.afnf4199ga.twawm.router.RouterControlByHttp.java
com.appspot.afnf4199ga.twawm.router.RouterControl.java
com.appspot.afnf4199ga.twawm.router.RouterControl.java
com.appspot.afnf4199ga.twawm.router.RouterInfo.java
com.appspot.afnf4199ga.twawm.router.RouterInfo.java
com.appspot.afnf4199ga.utils.AndroidUtilsTest.java
com.appspot.afnf4199ga.utils.AndroidUtils.java
com.appspot.afnf4199ga.utils.AndroidUtils.java
com.appspot.afnf4199ga.utils.Logger.java
com.appspot.afnf4199ga.utils.Logger.java
com.appspot.afnf4199ga.utils.MyStringUtlisTest.java
com.appspot.afnf4199ga.utils.MyStringUtlis.java
com.appspot.afnf4199ga.utils.MyStringUtlis.java
com.appspot.afnf4199ga.utils.MyTestUtils.java
com.appspot.afnf4199ga.utils.MyUncaughtExceptionHandler.java
com.appspot.afnf4199ga.utils.MyUncaughtExceptionHandler.java
com.appspot.afnf4199ga.wmgraph.app.FetchThread.java
com.appspot.afnf4199ga.wmgraph.app.InetLookupThread.java
com.appspot.afnf4199ga.wmgraph.app.InfoActivity.java
com.appspot.afnf4199ga.wmgraph.app.MainActivity.java
com.appspot.afnf4199ga.wmgraph.app.MyPreferenceActivity.java
com.appspot.afnf4199ga.wmgraph.app.UIAct.java
net.afnf.and.twawm2.DexmakerInstrumentationTestCase.java
net.afnf.and.twawm2.MyInstrumentationTestRunner.java