Android Open Source - twawm2 My Http Client 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.router;
//w  w w .  j a  v a  2  s.  c o  m
import java.net.InetAddress;

import net.afnf.and.twawm2.DexmakerInstrumentationTestCase;

import org.mockito.Mockito;

import android.net.DhcpInfo;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;

import com.appspot.afnf4199ga.twawm.Const;

public class MyHttpClientTest extends DexmakerInstrumentationTestCase {

    public void testIsRmtMainPath() {
        assertEquals(true, MyHttpClient.isRmtMainPath(Const.ROUTER_URL_INFO_RMTMAIN));
        assertEquals(true, MyHttpClient.isRmtMainPath(Const.ROUTER_URL_STANDBY_RMTMAIN));
        assertEquals(true, MyHttpClient.isRmtMainPath(Const.ROUTER_URL_STANDBY_BT_RMTMAIN));
        assertEquals(true, MyHttpClient.isRmtMainPath(Const.ROUTER_URL_REBOOT_WM_RMTMAIN));

        assertEquals(false, MyHttpClient.isRmtMainPath(null));
        assertEquals(false, MyHttpClient.isRmtMainPath(""));
        assertEquals(false, MyHttpClient.isRmtMainPath("aa"));

        assertEquals(false, MyHttpClient.isRmtMainPath(Const.ROUTER_URL_INFO_INFOBTN));
        assertEquals(false, MyHttpClient.isRmtMainPath(Const.ROUTER_URL_STANDBY_INFOBTN));
        assertEquals(false, MyHttpClient.isRmtMainPath(Const.ROUTER_URL_STANDBY_BT_INFOBTN));
        assertEquals(false, MyHttpClient.isRmtMainPath(Const.ROUTER_URL_WIMAX_DISCN_INFOBTN));
        assertEquals(false, MyHttpClient.isRmtMainPath(Const.ROUTER_URL_WIMAX_CONN_GETINFO));
        assertEquals(false, MyHttpClient.isRmtMainPath(Const.ROUTER_URL_WIMAX_CONN_INFOBTN));
        assertEquals(false, MyHttpClient.isRmtMainPath(Const.ROUTER_URL_REBOOT_WM_INFOBTN));
    }

    public void testGetRouterIpAddr10() throws Throwable {
        InetLookupWrappter mock = Mockito.mock(InetLookupWrappter.class);

        // ??
        String routerIpAddr = MyHttpClient.getRouterIpAddr(mock, "192.168.0.2");
        assertEquals("192.168.0.2", routerIpAddr);

        // ????????????
        Mockito.verifyNoMoreInteractions(mock);
    }

    /**
     * confRouterIpAddr????????????????????NG????????????
     */
    public void testGetRouterIpAddr11() throws Throwable {
        InetLookupWrappter mock = Mockito.mock(InetLookupWrappter.class);

        // ??
        String routerIpAddr = MyHttpClient.getRouterIpAddr(mock, "211.168.0.254");
        assertEquals("211.168.0.254", routerIpAddr);

        // ????????????
        Mockito.verifyNoMoreInteractions(mock);
    }

    /**
     * confRouterIpAddr??????
     */
    public void testGetRouterIpAddr12() throws Throwable {
        InetAddress val = InetAddress.getByName("192.168.0.7");
        InetLookupWrappter mock = Mockito.mock(InetLookupWrappter.class);
        Mockito.when(mock.getByName(Mockito.anyString())).thenReturn(val);

        // ??
        String routerIpAddr = MyHttpClient.getRouterIpAddr(mock, "211.168.0.255");
        assertEquals("192.168.0.7", routerIpAddr);

        // ??????????
        Mockito.verify(mock).getByName(Const.ROUTER_HOSTNAME);

        // ?????????????????????
        Mockito.verifyNoMoreInteractions(mock);
    }

    public void testGetRouterIpAddr20() throws Throwable {
        InetAddress val = InetAddress.getByName("192.168.0.20");
        InetLookupWrappter mock = Mockito.mock(InetLookupWrappter.class);
        Mockito.when(mock.getByName(Mockito.anyString())).thenReturn(val);

        // ??
        String routerIpAddr = MyHttpClient.getRouterIpAddr(mock, "");
        assertEquals("192.168.0.20", routerIpAddr);

        // ??????????
        Mockito.verify(mock).getByName(Const.ROUTER_HOSTNAME);

        // ?????????????????????
        Mockito.verifyNoMoreInteractions(mock);
    }

    /**
     * ????????????????????????NG????????????????????????
     */
    public void testGetRouterIpAddr21() throws Throwable {
        InetAddress val = InetAddress.getByName("210.168.0.21");
        InetLookupWrappter mock = Mockito.mock(InetLookupWrappter.class);
        Mockito.when(mock.getByName(Mockito.anyString())).thenReturn(val);

        // ??
        String routerIpAddr = MyHttpClient.getRouterIpAddr(mock, null);
        assertEquals(routerIpAddr, MyHttpClient.NOT_SITE_LOCAL_ADDR);

        // ??????????
        Mockito.verify(mock).getByName(Const.ROUTER_HOSTNAME);

        // ?????????????????????
        Mockito.verifyNoMoreInteractions(mock);
    }

    public void testGetRouterIpAddr22() throws Throwable {
        InetLookupWrappter mock = Mockito.mock(InetLookupWrappter.class);
        Mockito.when(mock.getByName(Mockito.anyString())).thenReturn(null);

        // ??
        String routerIpAddr = MyHttpClient.getRouterIpAddr(mock, "");
        assertNull(routerIpAddr);

        // ??????????
        Mockito.verify(mock).getByName(Const.ROUTER_HOSTNAME);

        // ?????????????????????
        Mockito.verifyNoMoreInteractions(mock);
    }

    //
    //        // ??????IP????????
    //        DhcpInfo dhcpInfo = wifi.getDhcpInfo();
    //        if (dhcpInfo != null) {
    //            return AndroidUtils.intToIpaddr(dhcpInfo.gateway);
    //        }
    //
    //        // ??????IP????????
    //        WifiInfo connectionInfo = wifi.getConnectionInfo();
    //        if (connectionInfo != null) {
    //            String ipaddr = AndroidUtils.intToIpaddr(connectionInfo.getIpAddress());
    //            if (ipaddr.indexOf(Const.ROUTER_IPADDR_NAD_PREFIX) == 0) {
    //                return Const.ROUTER_IPADDR_NAD_PREFIX + "1";
    //            }
    //            else if (ipaddr.indexOf(Const.ROUTER_IPADDR_WM_PREFIX) == 0) {
    //                return Const.ROUTER_IPADDR_WM_PREFIX + "1";
    //            }
    //        }

    public void testEstimateRouterIpAddr1() {
        WifiManager wifi = Mockito.mock(WifiManager.class);
        Mockito.when(wifi.getDhcpInfo()).thenReturn(null);
        Mockito.when(wifi.getConnectionInfo()).thenReturn(null);
        assertEquals(null, MyHttpClient.estimateRouterIpAddr(wifi));
    }

    public void testEstimateRouterIpAddr2() {
        DhcpInfo dhcpInfo = new DhcpInfo();
        dhcpInfo.gateway = 0x04030201;

        WifiManager wifi = Mockito.mock(WifiManager.class);
        Mockito.when(wifi.getDhcpInfo()).thenReturn(dhcpInfo);
        Mockito.when(wifi.getConnectionInfo()).thenReturn(null);
        assertEquals("1.2.3.4", MyHttpClient.estimateRouterIpAddr(wifi));
    }

    public void testEstimateRouterIpAddr3() {
        WifiInfo wi = Mockito.mock(WifiInfo.class);
        Mockito.when(wi.getIpAddress()).thenReturn(0x05030201); // 1.2.3.5

        WifiManager wifi = Mockito.mock(WifiManager.class);
        Mockito.when(wifi.getDhcpInfo()).thenReturn(null);
        Mockito.when(wifi.getConnectionInfo()).thenReturn(wi);
        assertEquals("1.2.3.1", MyHttpClient.estimateRouterIpAddr(wifi));
    }

    public void testEstimateRouterIpAddr4() {
        WifiInfo wi = Mockito.mock(WifiInfo.class);
        Mockito.when(wi.getIpAddress()).thenReturn(0x05b3a8c0); // 192.168.179.5

        WifiManager wifi = Mockito.mock(WifiManager.class);
        Mockito.when(wifi.getDhcpInfo()).thenReturn(null);
        Mockito.when(wifi.getConnectionInfo()).thenReturn(wi);
        assertEquals("192.168.179.1", MyHttpClient.estimateRouterIpAddr(wifi));
    }
}




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