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

import android.content.Context;

import org.junit.Test;

import io.reactivex.Observable;
import io.reactivex.Single;

import static junit.framework.Assert.assertTrue;
import static org.mockito.Mockito.mock;

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

  @Test
  public void check() {
    Single<Boolean> single = NetworkWatcher.check(mock(Context.class));

    assertTrue(null != single);
  }

  @Test
  public void watch() {
    Observable<Boolean> network = Observable.fromCallable(() -> true);
    Observable<Boolean> internet = Observable.fromCallable(() -> false);
    Observable<Boolean> watch = NetworkWatcher.watch(network, internet);
    watch.test()
      .assertSubscribed()
      .assertComplete()
      .assertResult(false);

    network = Observable.fromCallable(() -> true);
    internet = Observable.fromCallable(() -> true);
    NetworkWatcher.watch(network, internet).test()
      .assertSubscribed()
      .assertComplete()
      .assertResult(true);

    network = Observable.fromCallable(() -> false);
    internet = Observable.fromCallable(() -> true);
    NetworkWatcher.watch(network, internet).test()
      .assertSubscribed()
      .assertComplete()
      .assertResult(false);

    network = Observable.fromCallable(() -> false);
    internet = Observable.fromCallable(() -> false);
    NetworkWatcher.watch(network, internet).test()
      .assertSubscribed()
      .assertComplete()
      .assertResult(false);
  }
}