package net.kjulio.rxlocationtest;

import android.content.Context;
import android.location.Location;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;

import com.google.android.gms.location.LocationRequest;

import net.kjulio.rxlocation.RxLocation;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

@RunWith(AndroidJUnit4.class)
public class RxLocationTest {

    private Context context; // Context of the app under test.
    private final LocationRequest defaultLocationRequest = LocationRequest.create()
            .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);

    @Before
    public void setUp() {
        context = InstrumentationRegistry.getTargetContext();
    }

    @Test
    public void appPackageName() {
        assertEquals("net.kjulio.rxlocation.test", context.getPackageName());
    }

    @Test
    public void testLocationUpdates() {
        Location location = RxLocation.locationUpdates(context, defaultLocationRequest)
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .toBlocking()
                .first();
        assertNotNull(location);
    }

    @Test
    public void testLastLocation() {
        Location location = RxLocation.lastLocation(context)
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .toBlocking()
                .first();
        assertNotNull(location);
    }

}

@@ -394,77 +394,32 @@
  rx.
-android.schedulers.AndroidSchedulers;%0Aimport rx.schedulers.Schedul
+observers.TestSubscrib
 er
-s
 ;%0A%0Ai
@@ -465,54 +465,8 @@
 als;
-%0Aimport static org.junit.Assert.assertNotNull;
 %0A%0A@R
@@ -603,144 +603,47 @@
 ate 
-final LocationRequest defaultLocationRequest = LocationRequest.create()%0A            .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
+TestSubscriber%3CLocation%3E testSubscriber
 ;%0A%0A 
@@ -737,24 +737,74 @@
 tContext();%0A
+        testSubscriber = TestSubscriber.create();%0A
     %7D%0A%0A    @
@@ -959,30 +959,27 @@
 id testL
+astL
 ocation
-Updates
 () %7B%0A   
@@ -983,35 +983,71 @@
         
-Location location =
+// Successful run of lastLocation() observable.%0A       
  RxLocat
@@ -1055,30 +1055,27 @@
 on.l
+astL
 ocation
-Updates
 (context
 , de
@@ -1074,232 +1074,133 @@
 text
-, defaultLocationRequest)%0A                .subscribeOn(Schedulers.newThread())%0A                .observeOn(AndroidSchedulers.mainThread())%0A                .toBlocking()%0A                .first();%0A        assertNotNull(location
+).toBlocking().subscribe(testSubscriber);%0A        testSubscriber.assertValueCount(1);%0A        testSubscriber.assertCompleted(
 );%0A 
@@ -1232,35 +1232,38 @@
 c void testL
-astL
 ocation
+Updates
 () %7B%0A       
@@ -1267,171 +1267,264 @@
     
-Location location = RxLocation.lastLocation(context)%0A                .subscribeOn(Schedulers.newThread())%0A                .observeOn(AndroidSchedulers.mainThread()
+// Successful run of locationUpdates() observable.%0A        LocationRequest defaultLocationRequest = LocationRequest.create()%0A                .setPriority(LocationRequest.PRIORITY_NO_POWER);%0A        RxLocation.locationUpdates(context, defaultLocationRequest
 )%0A  
@@ -1537,16 +1537,24 @@
         
+.first()
 .toBlock
@@ -1562,65 +1562,77 @@
 ng()
-%0A                .first();%0A        assertNotNull(location
+.subscribe(testSubscriber);%0A        testSubscriber.assertValueCount(1
 );%0A 

Improve RxLocationTest using Rx's TestSubscriber.