Generate and return a mocked HBase RPC for testing purposes with a valid Deferred that can be called on execution. @param deferred A deferred to watch for results @return The RPC to pass through unit tests.
(final Deferred<Object> deferred)
| 398 | * @return The RPC to pass through unit tests. |
| 399 | */ |
| 400 | protected HBaseRpc getMockHBaseRpc(final Deferred<Object> deferred) { |
| 401 | final HBaseRpc rpc = mock(HBaseRpc.class); |
| 402 | rpc.attempt = 0; |
| 403 | when(rpc.getDeferred()).thenReturn(deferred); |
| 404 | when(rpc.toString()).thenReturn("MockRPC"); |
| 405 | PowerMockito.doAnswer(new Answer<Void>() { |
| 406 | @Override |
| 407 | public Void answer(InvocationOnMock invocation) throws Throwable { |
| 408 | if (deferred != null) { |
| 409 | deferred.callback(invocation.getArguments()[0]); |
| 410 | } else { |
| 411 | System.out.println("Deferred was null!!"); |
| 412 | } |
| 413 | return null; |
| 414 | } |
| 415 | }).when(rpc).callback(Object.class); |
| 416 | return rpc; |
| 417 | } |
| 418 | } |
no test coverage detected