use of com.github.ljtfreitas.julian.Arguments in project julian-http-client by ljtfreitas.
the class LazyResponseTTest method bind.
@Test
void bind(@Mock Promise<Response<String>> promise, @Mock ResponseFn<String, Object> fn) {
Arguments arguments = Arguments.empty();
String content = "hello";
when(fn.run(promise, arguments)).thenReturn(Promise.done(content));
Lazy<Object> lazy = responseT.bind(endpoint, fn).join(promise, arguments);
assertFalse(lazy.isEvaluated());
assertThat(lazy.get(), equalTo(content));
}
use of com.github.ljtfreitas.julian.Arguments in project julian-http-client by ljtfreitas.
the class OptionResponseTTest method bind.
@Test
void bind(@Mock Promise<Response<String>> promise, @Mock ResponseFn<String, Object> fn) {
Arguments arguments = Arguments.empty();
String content = "hello";
when(fn.run(promise, arguments)).thenReturn(Promise.done(content));
Option<Object> option = responseT.bind(endpoint, fn).join(promise, arguments);
assertTrue(option.exists(content::equals));
}
use of com.github.ljtfreitas.julian.Arguments in project julian-http-client by ljtfreitas.
the class HTTPHeadersResponseTTest method compose.
@Test
void compose(@Mock ResponseFn<Void, Void> fn, @Mock HTTPResponse<Void> response) {
Arguments arguments = Arguments.empty();
HTTPHeaders headers = HTTPHeaders.create(new HTTPHeader("X-Header", "x-header-content"));
when(response.headers()).thenReturn(headers);
when(response.cast(notNull())).thenCallRealMethod();
HTTPHeaders actual = responseT.bind(endpoint, fn).join(Promise.done(response), arguments);
assertThat(actual, contains(headers.all().toArray()));
}
use of com.github.ljtfreitas.julian.Arguments in project julian-http-client by ljtfreitas.
the class HTTPStatusCodeResponseTTest method compose.
@Test
void compose(@Mock ResponseFn<Void, Void> fn, @Mock HTTPResponse<Void> response) {
Arguments arguments = Arguments.empty();
HTTPStatusCode httpStatusCode = HTTPStatusCode.OK;
when(response.status()).thenReturn(new HTTPStatus(httpStatusCode));
when(response.cast(notNull())).thenCallRealMethod();
HTTPStatusCode actual = responseT.bind(endpoint, fn).join(Promise.done(response), arguments);
assertEquals(httpStatusCode, actual);
}
use of com.github.ljtfreitas.julian.Arguments in project julian-http-client by ljtfreitas.
the class EitherResponseTTest method bindFailure.
@Test
void bindFailure(@Mock Promise<Response<String>> promise, @Mock ResponseFn<String, Object> fn) {
Arguments arguments = Arguments.empty();
RuntimeException failure = new RuntimeException("oops");
when(endpoint.returnType()).thenReturn(JavaType.parameterized(Either.class, Exception.class, String.class));
when(fn.run(promise, arguments)).then(i -> Promise.failed(failure));
Either<Exception, Object> either = responseT.bind(endpoint, fn).join(promise, arguments);
assertTrue(either.isLeft());
Exception exception = either.swap().get();
assertSame(failure, exception);
}