package kr.co.zumo.app.lifeplus.network;

import android.net.ConnectivityManager;
import android.net.NetworkInfo;

import org.junit.Before;
import org.junit.Test;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue;
import static org.powermock.api.mockito.PowerMockito.mock;
import static org.powermock.api.mockito.PowerMockito.when;

/**
 * NetworkStatusTest
 * <pre>
 * </pre>
 *
 * @author 민효동
 * @version 1.0
 * @history 민효동   [2018. 9. 18.]   [최초 작성]
 * @since 2018. 9. 18.
 */
//@RunWith(RobolectricTestRunner.class)
public class NetworkStatusTest {

  NetworkInfo networkInfo;

  NetworkStatus networkStatus;

  @Before
  public void setUp() throws Exception {
  }

  @Test //(expected = NullPointerException.class)
  public void isConnected() {
    networkInfo = mock(NetworkInfo.class);
    when(networkInfo.isConnected()).thenReturn(true);

    networkStatus = new NetworkStatus(networkInfo);
    assertTrue(networkStatus.isConnected());

    networkStatus = new NetworkStatus(null);
    assertTrue(networkStatus.isConnected() == false);
  }

  @Test
  public void getConnectedType() {
    networkInfo = mock(NetworkInfo.class);
    when(networkInfo.getType()).thenReturn(ConnectivityManager.TYPE_MOBILE);

    networkStatus = new NetworkStatus(networkInfo);
    assertEquals(ConnectivityManager.TYPE_MOBILE, networkStatus.getConnectedType());

    networkStatus = new NetworkStatus(null);
    assertEquals(NetworkStatus.DISCONNECTED, networkStatus.getConnectedType());
  }

  @Test
  public void getTypeString() {
    networkInfo = mock(NetworkInfo.class);
    networkStatus = new NetworkStatus(networkInfo);

    assertEquals(NetworkStatus.TYPE_MOBILE, networkStatus.getTypeString(ConnectivityManager.TYPE_MOBILE));
    assertEquals(NetworkStatus.TYPE_WIFI, networkStatus.getTypeString(ConnectivityManager.TYPE_WIFI));
    assertEquals(NetworkStatus.TYPE_WIMAX, networkStatus.getTypeString(ConnectivityManager.TYPE_WIMAX));
  }
}