Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
/.DS_Store
/build
*.iml
.gradletasknamecache
.gradletasknamecach
*.exec
1 change: 0 additions & 1 deletion app-kotlin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ dependencies {
buildscript {
repositories {
mavenCentral()
jcenter()
google()
maven {
url 'https://plugins.gradle.org/m2/'
Expand Down
1 change: 0 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ dependencies {
buildscript {
repositories {
mavenCentral()
jcenter()
google()
maven {
url 'https://plugins.gradle.org/m2/'
Expand Down
10 changes: 4 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ apply plugin: 'io.codearte.nexus-staging'
ext {
minSdkVersion = 14
minSdkVersionApps = 23
compileSdkVersion = 28
compileSdkVersion = 29
buildToolsVersion = '28.0.3'
gradleVersion = '4.6'
kotlinVersion = '1.4.0'
detektVersion = '1.0.0.RC6-1'
}

ext.deps = [rxjava2 : 'io.reactivex.rxjava2:rxjava:2.2.19',
ext.deps = [rxjava2 : 'io.reactivex.rxjava2:rxjava:2.2.21',
rxandroid2 : 'io.reactivex.rxjava2:rxandroid:2.1.1',
annotation : 'androidx.annotation:annotation:1.1.0',
appcompat : 'androidx.appcompat:appcompat:1.2.0',
junit : 'junit:junit:4.13',
truth : 'com.google.truth:truth:1.0.1',
robolectric : 'org.robolectric:robolectric:4.3.1',
robolectric : 'org.robolectric:robolectric:4.9',
mockitocore : 'org.mockito:mockito-core:3.5.2',
nullaway : 'com.uber.nullaway:nullaway:0.8.0',
errorprone : 'com.google.errorprone:error_prone_core:2.3.4',
Expand All @@ -31,14 +31,13 @@ ext.deps = [rxjava2 : 'io.reactivex.rxjava2:rxjava:2.2.19',
buildscript {
repositories {
google()
jcenter()
mavenCentral()
maven {
url 'https://plugins.gradle.org/m2/'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.3'
classpath 'com.android.tools.build:gradle:3.6.4'
classpath('com.hiya:jacoco-android:0.2') {
exclude group: 'org.codehaus.groovy', module: 'groovy-all'
}
Expand All @@ -54,7 +53,6 @@ buildscript {
allprojects {
repositories {
google()
jcenter()
mavenCentral()
maven {
url 'https://plugins.gradle.org/m2/'
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ org.gradle.jvmargs=-XX:MaxPermSize=1024m -XX:+CMSClassUnloadingEnabled -XX:+Heap

android.useAndroidX=true
android.enableJetifier=true
android.jetifier.blacklist=bcprov-jdk15on
android.enableR8.fullMode=false
android.enableUnitTestBinaryResources=true
3 changes: 3 additions & 0 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ android {
jacoco {
includeNoLocationClasses = true
}
systemProperty 'robolectric.dependency.repo.url', 'https://repo1.maven.org/maven2'
}
}

Expand All @@ -65,6 +66,7 @@ android {
api deps.rxandroid2
implementation deps.annotation

testImplementation project(path: ':library')
testImplementation deps.junit
testImplementation deps.truth
testImplementation deps.robolectric
Expand Down Expand Up @@ -92,5 +94,6 @@ android {

tasks.withType(Test) {
jacoco.includeNoLocationClasses = true
jacoco.excludes = ['jdk.internal.*']
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
.typeName(TYPE_NAME_WIFI)
.build();

//noinspection CStyleArrayDeclaration
final NetworkInfo.State states[] =
{ NetworkInfo.State.CONNECTED, NetworkInfo.State.CONNECTING };

Expand Down Expand Up @@ -109,6 +110,7 @@
.build();

// note that unknown type is added initially by the ConnectivityPredicate#hasType method
//noinspection CStyleArrayDeclaration
final int givenTypes[] = { connectivity.type(), Connectivity.UNKNOWN_TYPE };

// when
Expand All @@ -127,6 +129,7 @@
.build();

// note that unknown type is added initially by the ConnectivityPredicate#hasType method
//noinspection CStyleArrayDeclaration
final int givenTypes[] = {
ConnectivityManager.TYPE_WIFI, ConnectivityManager.TYPE_MOBILE, Connectivity.UNKNOWN_TYPE
};
Expand All @@ -147,6 +150,7 @@
.build();

// note that unknown type is added initially by the ConnectivityPredicate#hasType method
//noinspection CStyleArrayDeclaration
final int givenTypes[] = { ConnectivityManager.TYPE_MOBILE, Connectivity.UNKNOWN_TYPE };

// when
Expand All @@ -163,6 +167,7 @@ public void createShouldThrowAnExceptionWhenContextIsNull() {
final Context context = null;

// when
//noinspection ConstantConditions
Connectivity.create(context);

// then
Expand Down Expand Up @@ -318,10 +323,11 @@ public void shouldAppendUnknownTypeWhileFilteringNetworkTypesInsidePredicateForE

@Test public void shouldCreateDefaultConnectivityWhenConnectivityManagerIsNull() {
// given
final Context context = RuntimeEnvironment.application.getApplicationContext();
final Context context = RuntimeEnvironment.getApplication().getApplicationContext();
final ConnectivityManager connectivityManager = null;

// when
@SuppressWarnings("ConstantConditions")
Connectivity connectivity = Connectivity.create(context, connectivityManager);

// then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,17 @@
import io.reactivex.Observable;
import io.reactivex.Single;
import java.lang.reflect.Method;
import java.util.concurrent.Callable;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowConnectivityManager;

import static com.google.common.truth.Truth.assertThat;

@RunWith(RobolectricTestRunner.class)
@Config(shadows = ShadowConnectivityManager.class)
@SuppressWarnings("NullAway") public class ReactiveNetworkTest {

private static final String TEST_VALID_HOST = "www.test.com";
Expand Down Expand Up @@ -75,7 +76,11 @@

private void networkConnectivityObservableShouldNotBeNull() {
// given
final Context context = RuntimeEnvironment.application;
final Application context = RuntimeEnvironment.getApplication();
//final ConnectivityManager connectivityManagerMock = (ConnectivityManager) context
// .getSystemService(Context.CONNECTIVITY_SERVICE);
//
//shadowOf(connectivityManagerMock);

// when
Observable<Connectivity> observable;
Expand All @@ -87,7 +92,8 @@ private void networkConnectivityObservableShouldNotBeNull() {

@Test public void observeNetworkConnectivityWithStrategyShouldNotBeNull() {
// given
final Context context = RuntimeEnvironment.application;
final Application context = RuntimeEnvironment.getApplication();

NetworkObservingStrategy strategy = new LollipopNetworkObservingStrategy();

// when
Expand All @@ -111,7 +117,7 @@ private void networkConnectivityObservableShouldNotBeNull() {

@Test public void observeNetworkConnectivityShouldBeConnectedOnStartWhenNetworkIsAvailable() {
// given
final Application context = RuntimeEnvironment.application;
final Application context = RuntimeEnvironment.getApplication();

// when
Connectivity connectivity = ReactiveNetwork.observeNetworkConnectivity(context).blockingFirst();
Expand All @@ -127,6 +133,7 @@ public void observeNetworkConnectivityShouldThrowAnExceptionForNullContext() {
final NetworkObservingStrategy strategy = new LollipopNetworkObservingStrategy();

// when
//noinspection ConstantConditions
ReactiveNetwork.observeNetworkConnectivity(context, strategy);

// then an exception is thrown
Expand All @@ -151,6 +158,7 @@ public void observeInternetConnectivityShouldThrowAnExceptionWhenStrategyIsNull(
final ErrorHandler errorHandler = new DefaultErrorHandler();

// when
//noinspection ConstantConditions
ReactiveNetwork.observeInternetConnectivity(strategy, TEST_VALID_INITIAL_INTERVAL,
TEST_VALID_INTERVAL, TEST_VALID_HOST, TEST_VALID_PORT, TEST_VALID_TIMEOUT,
TEST_VALID_HTTP_RESPONSE, errorHandler);
Expand Down Expand Up @@ -265,11 +273,7 @@ public void shouldCheckInternetConnectivityWithCustomSettings() {

@Override public Single<Boolean> checkInternetConnectivity(String host, int port,
int timeoutInMs, int httpResponse, ErrorHandler errorHandler) {
return Single.fromCallable(new Callable<Boolean>() {
@Override public Boolean call() {
return true;
}
});
return Single.fromCallable(() -> true);
}

@Override public String getDefaultPingHost() {
Expand All @@ -279,9 +283,7 @@ public void shouldCheckInternetConnectivityWithCustomSettings() {
}

@NonNull private ErrorHandler createTestErrorHandler() {
return new ErrorHandler() {
@Override public void handleError(Exception exception, String message) {
}
return (exception, message) -> {
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,6 @@ public void shouldBuildSettings() {
}

@NonNull private ErrorHandler createTestErrorHandler() {
return new ErrorHandler() {
@Override public void handleError(Exception exception, String message) {
}
};
return (exception, message) -> { };
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@
*/
package com.github.pwittchen.reactivenetwork.library.rx2.network.observing;

import android.annotation.SuppressLint;
import android.content.Context;
import android.net.NetworkInfo;
import com.github.pwittchen.reactivenetwork.library.rx2.Connectivity;
import com.github.pwittchen.reactivenetwork.library.rx2.network.observing.strategy.LollipopNetworkObservingStrategy;
import com.github.pwittchen.reactivenetwork.library.rx2.network.observing.strategy.PreLollipopNetworkObservingStrategy;
import io.reactivex.functions.Consumer;
import io.reactivex.disposables.Disposable;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;

import static com.google.common.truth.Truth.assertThat;

@RunWith(RobolectricTestRunner.class)
Expand All @@ -47,17 +47,19 @@
assertThatIsConnected(strategy);
}

@SuppressWarnings("CheckReturnValue")
@SuppressLint("CheckResult")
private void assertThatIsConnected(NetworkObservingStrategy strategy) {
// given
final Context context = RuntimeEnvironment.application.getApplicationContext();
final Context context = RuntimeEnvironment.getApplication().getApplicationContext();

//when
strategy.observeNetworkConnectivity(context).subscribe(new Consumer<Connectivity>() {
@Override public void accept(Connectivity connectivity) throws Exception {
// then
assertThat(connectivity.state()).isEqualTo(NetworkInfo.State.CONNECTED);
}
});
Disposable disposable = strategy.observeNetworkConnectivity(context)
.subscribe(
(@SuppressLint("CheckResult") Connectivity connectivity) -> {
// then
assertThat(connectivity.state()).isEqualTo(NetworkInfo.State.CONNECTED);
});

disposable.dispose();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
@Test public void shouldObserveConnectivity() {
// given
final NetworkObservingStrategy strategy = new LollipopNetworkObservingStrategy();
final Context context = RuntimeEnvironment.application.getApplicationContext();
final Context context = RuntimeEnvironment.getApplication().getApplicationContext();

// when
Connectivity connectivity = strategy.observeNetworkConnectivity(context).blockingFirst();
Expand All @@ -56,7 +56,7 @@
@Test public void shouldStopObservingConnectivity() {
// given
final NetworkObservingStrategy strategy = new LollipopNetworkObservingStrategy();
final Application context = RuntimeEnvironment.application;
final Application context = RuntimeEnvironment.getApplication();
final Observable<Connectivity> observable = strategy.observeNetworkConnectivity(context);
final TestObserver<Connectivity> observer = new TestObserver<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@
@Spy private Context context;

@Before public void setUp() {
context = RuntimeEnvironment.application.getApplicationContext();
context = RuntimeEnvironment.getApplication().getApplicationContext();
}

@Test public void shouldObserveConnectivity() {
// given
final Context context = RuntimeEnvironment.application.getApplicationContext();
final Context context = RuntimeEnvironment.getApplication().getApplicationContext();

// when
Connectivity connectivity = strategy.observeNetworkConnectivity(context).blockingFirst();
Expand Down
Loading