Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add getter method for Request arguments #359

Open
10sa opened this issue Jan 13, 2023 · 0 comments
Open

Add getter method for Request arguments #359

10sa opened this issue Jan 13, 2023 · 0 comments

Comments

@10sa
Copy link

10sa commented Jan 13, 2023

Describe the feature

Add arguments getter to Request interface and implementations.

Use cases

I'm testing about Verticle (Redis used), The purpose of the test is to test whether the processing about data received from Redis and check intented command sent to Redis. (Not about Redis connection)

I replaced the Redis object with a mock, but couldn't construct a proper assertion on the Request object passed to the RedisConnection.send method.

The Request object does not provide getters for Arguments entered so far, so the following code hard to implements.

Redis redis = mock(Redis.class);
RedisConnection conn = mock(RedisConnection.class);
when(redis.connection()).thenReturn(Future.succeededFuture(conn));

verify(conn).send(argThat(request -> {
    // Assertion request arguments, but how?
    return false;
});

If the Arguments getter method added to Request interface, the test code above can assert which arguments were included in the request, like so:

// Verify `conn.send` method call with specific arguments
verify(conn).send(argThat(request -> "TEST_KEY".equals(new String(request.getArgs().get(0))));

I have written examples of use only for testing purposes, but it can be used general purpose in areas such as logging or something else.

Contribution

I can implement this myself if you deem it a worthy feature request. In RequestImpl class, arguments are stored byte[] object, but since the main purpose is to add a simple getter method, only a few lines of code are required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

1 participant