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);
}
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);
}
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);
}
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));
});
}
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>");
}
}
Aggregations