use of com.github.ljtfreitas.julian.Arguments in project julian-http-client by ljtfreitas.
the class HTTPStatusResponseTTest method compose.
@Test
void compose(@Mock ResponseFn<Void, Void> fn, @Mock HTTPResponse<Void> response) {
Arguments arguments = Arguments.empty();
HTTPStatus httpStatus = new HTTPStatus(HTTPStatusCode.OK);
when(response.status()).thenReturn(httpStatus);
when(response.cast(notNull())).thenCallRealMethod();
HTTPStatus actual = responseT.bind(endpoint, fn).join(Promise.done(response), arguments);
assertEquals(httpStatus, actual);
}
use of com.github.ljtfreitas.julian.Arguments in project julian-http-client by ljtfreitas.
the class TryResponseTTest method bindFailure.
@Test
void bindFailure() {
RuntimeException failure = new RuntimeException("oops");
ResponseFn<String, Object> fn = new ObjectResponseT<>().bind(endpoint, null);
Promise<Response<String>> promise = Promise.failed(failure);
Arguments arguments = Arguments.empty();
Try<Object> attempt = responseT.bind(endpoint, fn).join(promise, arguments);
assertTrue(attempt.isFailure());
Exception exception = (Exception) attempt.getCause();
assertSame(failure, exception);
}
use of com.github.ljtfreitas.julian.Arguments in project julian-http-client by ljtfreitas.
the class EitherResponseTTest method bind.
@Test
void bind(@Mock Promise<Response<String>> promise, @Mock ResponseFn<String, Object> fn) {
Arguments arguments = Arguments.empty();
String content = "hello";
when(endpoint.returnType()).thenReturn(JavaType.parameterized(Either.class, Exception.class, String.class));
when(fn.run(promise, arguments)).thenReturn(Promise.done(content));
Either<Exception, Object> either = responseT.bind(endpoint, fn).join(promise, arguments);
assertTrue(either.isRight());
assertThat(either.get(), equalTo(content));
}
use of com.github.ljtfreitas.julian.Arguments in project julian-http-client by ljtfreitas.
the class FutureResponseTTest 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(fn.run(promise, arguments)).then(i -> Promise.failed(failure));
Future<Object> future = responseT.bind(endpoint, fn).join(promise, arguments);
assertTrue(future.isFailure());
Object failureMessage = future.recover(Throwable::getMessage).get();
assertThat(failureMessage, equalTo(failure.getMessage()));
}
use of com.github.ljtfreitas.julian.Arguments in project julian-http-client by ljtfreitas.
the class LazyResponseTTest 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(fn.run(promise, arguments)).then(i -> Promise.failed(failure));
Lazy<Object> lazy = responseT.bind(endpoint, fn).join(promise, arguments);
assertFalse(lazy.isEvaluated());
RuntimeException actual = assertThrows(RuntimeException.class, lazy::get);
assertSame(failure, actual);
}