private void verifyContextContents(final String cmd, String ctxCmd) throws Exception {
    Connection hs2Conn = getConnection("user1");
    Statement stmt = hs2Conn.createStatement();

    stmt.execute(cmd);
    stmt.close();
    hs2Conn.close();

    ArgumentCaptor<HiveAuthzContext> contextCapturer = ArgumentCaptor
        .forClass(HiveAuthzContext.class);

    verify(mockedAuthorizer).checkPrivileges(any(HiveOperationType.class),
        anyList(), any(), contextCapturer.capture());

    HiveAuthzContext context = contextCapturer.getValue();

    assertEquals("Command ", ctxCmd, context.getCommandString());
    assertTrue("ip address pattern check", context.getIpAddress().matches("[.:a-fA-F0-9]+"));
    // ip address size check - check for something better than non zero
    assertTrue("ip address size check", context.getIpAddress().length() > 7);

  }
This factory creates a mocked HiveAuthorizer class.
Use the mocked class to capture the argument passed to it in the test case.
itests/hive-unit/src/test/java/org/apache/hive/jdbc/authorization/TestHS2AuthzContext.java