-
Notifications
You must be signed in to change notification settings - Fork 119
Description
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.