Search in sources :

Example 6 with Single

use of rx.Single in project retrofit by square.

the class RxJavaCallAdapterFactoryTest method responseTypes.

@Test
public void responseTypes() {
    Type oBodyClass = new TypeToken<Observable<String>>() {
    }.getType();
    assertThat(factory.get(oBodyClass, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
    Type sBodyClass = new TypeToken<Single<String>>() {
    }.getType();
    assertThat(factory.get(sBodyClass, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
    Type oBodyWildcard = new TypeToken<Observable<? extends String>>() {
    }.getType();
    assertThat(factory.get(oBodyWildcard, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
    Type sBodyWildcard = new TypeToken<Single<? extends String>>() {
    }.getType();
    assertThat(factory.get(sBodyWildcard, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
    Type oBodyGeneric = new TypeToken<Observable<List<String>>>() {
    }.getType();
    assertThat(factory.get(oBodyGeneric, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(new TypeToken<List<String>>() {
    }.getType());
    Type sBodyGeneric = new TypeToken<Single<List<String>>>() {
    }.getType();
    assertThat(factory.get(sBodyGeneric, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(new TypeToken<List<String>>() {
    }.getType());
    Type oResponseClass = new TypeToken<Observable<Response<String>>>() {
    }.getType();
    assertThat(factory.get(oResponseClass, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
    Type sResponseClass = new TypeToken<Single<Response<String>>>() {
    }.getType();
    assertThat(factory.get(sResponseClass, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
    Type oResponseWildcard = new TypeToken<Observable<Response<? extends String>>>() {
    }.getType();
    assertThat(factory.get(oResponseWildcard, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
    Type sResponseWildcard = new TypeToken<Single<Response<? extends String>>>() {
    }.getType();
    assertThat(factory.get(sResponseWildcard, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
    Type oResultClass = new TypeToken<Observable<Result<String>>>() {
    }.getType();
    assertThat(factory.get(oResultClass, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
    Type sResultClass = new TypeToken<Single<Result<String>>>() {
    }.getType();
    assertThat(factory.get(sResultClass, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
    Type oResultWildcard = new TypeToken<Observable<Result<? extends String>>>() {
    }.getType();
    assertThat(factory.get(oResultWildcard, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
    Type sResultWildcard = new TypeToken<Single<Result<? extends String>>>() {
    }.getType();
    assertThat(factory.get(sResultWildcard, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
}
Also used : Observable(rx.Observable) Type(java.lang.reflect.Type) Single(rx.Single) TypeToken(com.google.common.reflect.TypeToken) Test(org.junit.Test)

Example 7 with Single

use of rx.Single in project requery by requery.

the class RxTest method testDelete.

@Test
public void testDelete() throws Exception {
    Person person = randomPerson();
    data.insert(person).flatMap(new Func1<Person, Single<Void>>() {

        @Override
        public Single<Void> call(Person person) {
            return data.delete(person);
        }
    }).toBlocking().value();
    Person cached = data.select(Person.class).where(Person.ID.equal(person.getId())).get().firstOrNull();
    assertNull(cached);
}
Also used : Single(rx.Single) Person(io.requery.test.model.Person) Test(org.junit.Test)

Example 8 with Single

use of rx.Single in project requery by requery.

the class RxTest method testInsertOneToMany.

@Test
public void testInsertOneToMany() throws Exception {
    final Person person = randomPerson();
    data.insert(person).map(new Func1<Person, Phone>() {

        @Override
        public Phone call(Person person) {
            Phone phone1 = randomPhone();
            phone1.setOwner(person);
            return phone1;
        }
    }).flatMap(new Func1<Phone, Single<?>>() {

        @Override
        public Single<?> call(Phone phone) {
            return data.insert(phone);
        }
    }).toBlocking().value();
    assertTrue(person.getPhoneNumbers().toList().size() == 1);
}
Also used : Single(rx.Single) Phone(io.requery.test.model.Phone) Func1(rx.functions.Func1) Person(io.requery.test.model.Person) Test(org.junit.Test)

Example 9 with Single

use of rx.Single in project spring-framework by spring-projects.

the class ModelAttributeMethodArgumentResolverTests method validationErrorToSingle.

@Test
public void validationErrorToSingle() throws Exception {
    MethodParameter parameter = this.testMethod.annotPresent(ModelAttribute.class).arg(Single.class, Foo.class);
    testValidationError(parameter, resolvedArgumentMono -> {
        Object value = resolvedArgumentMono.block(Duration.ofSeconds(5));
        assertNotNull(value);
        assertTrue(value instanceof Single);
        return Mono.from(RxReactiveStreams.toPublisher((Single<?>) value));
    });
}
Also used : Single(rx.Single) ModelAttribute(org.springframework.web.bind.annotation.ModelAttribute) MethodParameter(org.springframework.core.MethodParameter) Test(org.junit.Test)

Example 10 with Single

use of rx.Single in project retrofit by square.

the class RxJavaCallAdapterFactoryTest method rawResultTypeThrows.

@Test
public void rawResultTypeThrows() {
    Type observableType = new TypeToken<Observable<Result>>() {
    }.getType();
    try {
        factory.get(observableType, NO_ANNOTATIONS, retrofit);
        fail();
    } catch (IllegalStateException e) {
        assertThat(e).hasMessage("Result must be parameterized as Result<Foo> or Result<? extends Foo>");
    }
    Type singleType = new TypeToken<Single<Result>>() {
    }.getType();
    try {
        factory.get(singleType, NO_ANNOTATIONS, retrofit);
        fail();
    } catch (IllegalStateException e) {
        assertThat(e).hasMessage("Result must be parameterized as Result<Foo> or Result<? extends Foo>");
    }
}
Also used : Type(java.lang.reflect.Type) Single(rx.Single) Observable(rx.Observable) Test(org.junit.Test)

Aggregations

Single (rx.Single)13 Test (org.junit.Test)12 Type (java.lang.reflect.Type)4 Observable (rx.Observable)4 Person (io.requery.test.model.Person)3 MethodParameter (org.springframework.core.MethodParameter)3 Phone (io.requery.test.model.Phone)2 ResolvableType (org.springframework.core.ResolvableType)2 ModelAttribute (org.springframework.web.bind.annotation.ModelAttribute)2 ServerWebInputException (org.springframework.web.server.ServerWebInputException)2 Context (android.content.Context)1 Handler (android.os.Handler)1 HandlerThread (android.os.HandlerThread)1 Task (bolts.Task)1 DDPClientWrapper (chat.rocket.android.api.DDPClientWrapper)1 MethodCallHelper (chat.rocket.android.api.MethodCallHelper)1 LogIfError (chat.rocket.android.helper.LogIfError)1 TextUtils (chat.rocket.android.helper.TextUtils)1 RCLog (chat.rocket.android.log.RCLog)1 ActiveUsersSubscriber (chat.rocket.android.service.ddp.base.ActiveUsersSubscriber)1