@Test
  public void requestLocation_Success() throws SecurityException {
    final Location expectedLocation = buildFakeLocation(provider);

    // set provider enabled
    setIsProviderEnabled(provider, true);

    // answer
    Mockito.doAnswer(
            new Answer() {
              @Override
              public Object answer(InvocationOnMock invocation) throws Throwable {
                final Object[] args = invocation.getArguments();
                final LocationListener l = (LocationListener) args[1];
                l.onLocationChanged(expectedLocation);
                return null;
              }
            })
        .when(locationManager)
        .requestSingleUpdate(
            Mockito.eq(provider), Mockito.any(LocationListener.class), Mockito.any(Looper.class));

    final RxLocationManager rxLocationManager = getDefaullRxLocationManager();

    final TestSubscriber<Location> subscriber = new TestSubscriber<>();
    rxLocationManager.requestLocation(provider).subscribe(subscriber);
    subscriber.awaitTerminalEvent();
    subscriber.assertCompleted();
    subscriber.assertValue(expectedLocation);
  }
 @Test
 public void shouldEmmitGroundOverlay() throws Exception {
   TestSubscriber<GroundOverlay> testSubscriber = new TestSubscriber<>();
   new GroundOverlayClickFunc().call(googleMap).subscribe(testSubscriber);
   verify(googleMap).setOnGroundOverlayClickListener(argumentCaptor.capture());
   argumentCaptor.getValue().onGroundOverlayClick(null);
   testSubscriber.assertNoErrors();
   testSubscriber.assertValueCount(1);
   testSubscriber.assertValue(null);
 }
  /**
   * Test that all fine
   *
   * @throws SecurityException
   */
  @Test
  public void getLastLocation_Success() throws SecurityException {
    final Location expectedLocation = buildFakeLocation(provider);

    Mockito.when(locationManager.getLastKnownLocation(provider)).thenReturn(expectedLocation);

    final RxLocationManager rxLocationManager = getDefaullRxLocationManager();

    final TestSubscriber<Location> subscriber = new TestSubscriber<>();
    rxLocationManager.getLastLocation(provider).subscribe(subscriber);
    subscriber.awaitTerminalEvent();
    subscriber.assertCompleted();
    subscriber.assertValue(expectedLocation);
  }
  @Test
  public void builder_Success3() throws SecurityException {
    final Location location1 = buildFakeLocation(provider);

    final LocationRequestBuilder locationRequestBuilder = getDefaultLocationRequestBuilder();

    final Observable<Location> createdObservable =
        locationRequestBuilder.setDefaultLocation(location1).create();

    final TestSubscriber<Location> subscriber = new TestSubscriber<>();
    createdObservable.subscribe(subscriber);
    subscriber.awaitTerminalEvent();
    subscriber.assertValue(location1);
  }
  @Test
  public void lightService_turnOff() {
    LightModel light = mockLightModel();
    mockClient();

    TestSubscriber<LightModel> tester = new TestSubscriber<>();
    lightService.turnOff(light).subscribe(tester);

    verify(commonService).findClient(GATEWAY_UUID);

    tester.assertValue(light);
    tester.assertCompleted();
    tester.assertNoErrors();
  }
Exemplo n.º 6
0
  @Test
  public void testCreate() throws Exception {

    final Value<String> value = Value.create("1");
    assertEquals(value.get(), "1");
    TestSubscriber<String> testSubscriber = new TestSubscriber<>();
    Subscription subscribe = value.asObservable().subscribe(testSubscriber);

    testSubscriber.assertValueCount(1);
    testSubscriber.assertValue("1");

    value.set("2");

    testSubscriber.assertValueCount(2);
    testSubscriber.assertValues("1", "2");

    subscribe.unsubscribe();

    testSubscriber = new TestSubscriber<>();
    value.asObservable().subscribe(testSubscriber);

    testSubscriber.assertValueCount(1);
    testSubscriber.assertValue("2");
  }
Exemplo n.º 7
0
  @Test
  public void rxBindingSingleValue() {
    when(cursor.getCount()).thenReturn(1);
    when(cursor.moveToNext()).thenReturn(true, false);
    when(cursor.getString(0)).thenReturn("Yo");

    TestSubscriber<String> testSubscriber = new TestSubscriber<>();

    Fetcher fetcher = Fetcher.of(cursor);
    fetcher.subscribe(Converter.STRING, testSubscriber);

    testSubscriber.requestMore(1);
    testSubscriber.assertValueCount(1);
    testSubscriber.assertValue("Yo");
  }
  @Test
  public void lightService_add() {
    String LIGHT_UUID = "myUuid";
    LightModel lightModel = new LightModel();

    when(lightRepository.add(lightModel)).thenReturn(Observable.just(LIGHT_UUID));

    TestSubscriber<String> tester = new TestSubscriber<>();
    lightService.add(lightModel).subscribe(tester);

    verify(lightRepository).add(lightModel);

    tester.assertValue(LIGHT_UUID);
    tester.assertCompleted();
    tester.assertNoErrors();
  }
Exemplo n.º 9
0
  public void testDelete() throws Exception {
    // arrange
    E entity = getFakeEntity();
    insertFakeToRealm();
    RealmQuery<V> query = realm.where(getRealmObjClass());
    assertThat(query.findFirst(), is(notNullValue()));

    TestSubscriber<Boolean> subscriber = new TestSubscriber<>();

    // act
    Observable<Boolean> result = realmCache.delete(entity);
    result.subscribe(subscriber);

    // assert
    subscriber.assertCompleted();
    subscriber.assertNoErrors();
    subscriber.assertValue(true);

    query = realm.where(getRealmObjClass());
    assertThat(query.findFirst(), is(nullValue()));
  }
  /**
   * Return null if no default location is setted and no value was emitted
   *
   * @throws SecurityException
   */
  @Test
  public void builder_Success2() throws SecurityException {
    final Location location1 = buildFakeLocation(provider);
    location1.setTime(System.currentTimeMillis() - TimeUnit.HOURS.toMillis(1));

    final LocationRequestBuilder locationRequestBuilder = getDefaultLocationRequestBuilder();

    final Observable<Location> createdObservable =
        locationRequestBuilder
            .addLastLocation(provider, new LocationTime(10, TimeUnit.MINUTES), false)
            .addRequestLocation(provider, new LocationTime(5, TimeUnit.SECONDS))
            .create();

    // set provider enabled
    setIsProviderEnabled(provider, true);

    Mockito.when(locationManager.getLastKnownLocation(provider)).thenReturn(location1);

    final TestSubscriber<Location> subscriber = new TestSubscriber<>();
    createdObservable.subscribe(subscriber);
    subscriber.awaitTerminalEvent();
    subscriber.assertValue(null);
  }