Search in sources :

Example 1 with Arguments

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);
}
Also used : Arguments(com.github.ljtfreitas.julian.Arguments) Test(org.junit.jupiter.api.Test)

Example 2 with Arguments

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);
}
Also used : Response(com.github.ljtfreitas.julian.Response) Arguments(com.github.ljtfreitas.julian.Arguments) Test(org.junit.jupiter.api.Test)

Example 3 with Arguments

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));
}
Also used : Arguments(com.github.ljtfreitas.julian.Arguments) Either(io.vavr.control.Either) Test(org.junit.jupiter.api.Test)

Example 4 with Arguments

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()));
}
Also used : Arguments(com.github.ljtfreitas.julian.Arguments) Test(org.junit.jupiter.api.Test)

Example 5 with Arguments

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);
}
Also used : Arguments(com.github.ljtfreitas.julian.Arguments) Test(org.junit.jupiter.api.Test)

Aggregations

Arguments (com.github.ljtfreitas.julian.Arguments)12 Test (org.junit.jupiter.api.Test)12 Either (io.vavr.control.Either)2 Response (com.github.ljtfreitas.julian.Response)1