Search in sources :

Example 6 with Arguments

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

Example 7 with Arguments

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

Example 8 with Arguments

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

Example 9 with Arguments

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

Example 10 with Arguments

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