RxNetworkInfo { public static RxNetworkInfo create() { return new Builder().build(); } @VisibleForTesting  RxNetworkInfo(); @VisibleForTesting  RxNetworkInfo(@NonNull Builder builder); static RxNetworkInfo create(); static RxNetworkInfo create(@NonNull NetworkInfo networkInfo); static RxNetworkInfo create(@NonNull Context context); @RequiresApi(LOLLIPOP) static RxNetworkInfo create(@NonNull Network network,
      @NonNull ConnectivityManager connectivityManager); static Builder builder(); NetworkInfo.State getState(); NetworkInfo.DetailedState getDetailedState(); int getType(); int getSubType(); boolean isAvailable(); boolean isFailover(); boolean isRoaming(); String getTypeName(); String getSubTypeName(); boolean isConnectedOrConnecting(); boolean isConnected(); String getReason(); String getExtraInfo(); @RequiresApi(LOLLIPOP) NetworkCapabilities getNetworkCapabilities(); @Override int hashCode(); @SuppressWarnings("ConstantConditions") @Override boolean equals(Object o); @SuppressLint("NewApi") @Override String toString();  }
@Test public void shouldNeverBeNull() { assertThat(create()).isNotNull(); }
@Test public void shouldBeEqualToSelf() { RxNetworkInfo sut = create(); assertThat(sut).isEqualTo(sut); }
@Test public void shouldNotBeEqual_whenNotAnInstanceOfRxNetworkInfo() { RxNetworkInfo sut = create(); assertThat(sut).isNotEqualTo(NOT_RXNETWORK_INFO_INSTANCE); }
@Test public void shouldNotBeEqualToNull() { RxNetworkInfo sut = create(); assertThat(sut).isNotEqualTo(null); }
@Test public void defaults_shouldBeEqual() { RxNetworkInfo rxni = create(); RxNetworkInfo rxni2 = create(); assertEqual(rxni, rxni2); }
@Test public void shouldBeEqual_whenCreatedFromSameNetworkInfo() { RxNetworkInfo rxni = RxNetworkInfo.create(NETWORK_INFO); RxNetworkInfo rxni2 = RxNetworkInfo.create(NETWORK_INFO); assertEqual(rxni, rxni2); }
@Test public void shouldNotBeEqual() { RxNetworkInfo rxni = create(); RxNetworkInfo rxni2 = RxNetworkInfo.create(NETWORK_INFO); assertNotEqual(rxni, rxni2); }
@Test(expected = NullPointerException.class) public void shouldThrow_whenProvidedNullNetworkInfo() { RxNetworkInfo.create(NULL_NETWORK_INFO); }
@Test public void shouldNeverBeNull_whenFromContext() { doReturn(connectivityManager).when(context).getSystemService(CONNECTIVITY_SERVICE); RxNetworkInfo sut = create(context); assertThat(sut).isNotNull(); }
@Test public void shouldFallbackToDefault_whenActiveNetworkInfoNull() { doReturn(connectivityManager).when(context).getSystemService(CONNECTIVITY_SERVICE); doReturn(null).when(connectivityManager).getActiveNetworkInfo(); RxNetworkInfo sut = create(context); assertThat(sut).isEqualTo(DEFAULT_RXNETWORK_INFO); }
@Test public void shouldReturnProperNetworkInfo_whenFromContext() { doReturn(connectivityManager).when(context).getSystemService(CONNECTIVITY_SERVICE); doReturn(NETWORK_INFO).when(connectivityManager).getActiveNetworkInfo(); RxNetworkInfo sut = create(context); assertThat(sut).isEqualTo(validRxNetworkInfo); }
@Test @Config(sdk = LOLLIPOP) public void shouldFallbackToDefault_whenNetworkInfoFromNetworkNull() { NETWORK = getNetwork(); doReturn(null).when(connectivityManager).getNetworkInfo(NETWORK); RxNetworkInfo sut = create(NETWORK, connectivityManager); assertThat(sut).isEqualTo(DEFAULT_RXNETWORK_INFO); }
@Test @Config(sdk = LOLLIPOP) public void shouldFallbackToDefault_whenNetworkInfoFromNetworkThrows() { NETWORK = getNetwork(); doThrow(Exception.class).when(connectivityManager).getNetworkInfo(NETWORK); RxNetworkInfo sut = create(NETWORK, connectivityManager); assertThat(sut).isEqualTo(DEFAULT_RXNETWORK_INFO); }
@Test @Config(sdk = LOLLIPOP) public void shouldReturnProperNetworkInfo_whenProvidedNetwork() { setUpNetworkWithNetworkCapabilities(); RxNetworkInfo sut = create(NETWORK, connectivityManager); assertThat(sut).isEqualTo(validRxNetworkInfoDetailed); }