Exemplo n.º 1
0
  public void testAddNullObject() throws Exception {
    // act
    Observable<E> result = realmCache.add(null);
    result.subscribe(testSubscriber);

    // assert
    testSubscriber.assertNotCompleted();
    testSubscriber.assertError(RealmException.class);

    verify(mockDataMapper, never()).transform(any(getRealmObjClass()));
  }
  /** Test that request location throw Exception if provider disabled */
  @Test
  public void requestLocation_ProviderDisabled() {
    // set provider disabled
    setIsProviderEnabled(provider, false);

    final RxLocationManager rxLocationManager = getDefaullRxLocationManager();

    final TestSubscriber<Location> subscriber = new TestSubscriber<>();
    rxLocationManager.requestLocation(provider).subscribe(subscriber);
    subscriber.awaitTerminalEvent();
    subscriber.assertError(ProviderDisabledException.class);
  }
  /** Test that request location throw TimeOutException */
  @Test
  public void requestLocation_TimeOutError() {
    // set provider enabled
    setIsProviderEnabled(provider, true);

    final RxLocationManager rxLocationManager = getDefaullRxLocationManager();

    final TestSubscriber<Location> subscriber = new TestSubscriber<>();
    rxLocationManager
        .requestLocation(provider, new LocationTime(5, TimeUnit.SECONDS))
        .subscribe(subscriber);
    subscriber.awaitTerminalEvent();
    subscriber.assertError(TimeoutException.class);
  }
  /**
   * Test that getLastLocation throw ElderLocationException if howOldCanBe is provided
   *
   * @throws SecurityException
   */
  @Test
  public void getLastLocation_Old() throws SecurityException {
    final Location expectedLocation = buildFakeLocation(provider);
    expectedLocation.setTime(System.currentTimeMillis() - TimeUnit.HOURS.toMillis(1));

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

    final RxLocationManager rxLocationManager = getDefaullRxLocationManager();

    final TestSubscriber<Location> subscriber = new TestSubscriber<>();
    rxLocationManager
        .getLastLocation(provider, new LocationTime(30, TimeUnit.MINUTES))
        .subscribe(subscriber);
    subscriber.awaitTerminalEvent();
    subscriber.assertError(ElderLocationException.class);
  }
 @Test
 public void testObservableRaiseHystrixRuntimeException() {
   TestSubscriber<Void> testSubscriber = new TestSubscriber<Void>();
   service.observableCommandShouldRaiseHystrixRuntimeException().subscribe(testSubscriber);
   testSubscriber.assertError(HystrixRuntimeException.class);
 }