public static Connection getMockedConnection(final Configuration conf) throws IOException {
    Connection connection = Mockito.mock(Connection.class);
    Mockito.when(connection.getConfiguration()).thenReturn(conf);

    // Some test cases need Mock of getTable and getScanner
    Table t = Mockito.mock(Table.class);
    Mockito.when(connection.getTable(Mockito.any())).thenReturn(t);
    ResultScanner rs = Mockito.mock(ResultScanner.class);
    Mockito.when(t.getScanner((Scan) Mockito.any())).thenReturn(rs);

    return connection;
  }
Get a Mocked {@link Connection} that goes with the passed <code>conf</code> configuration
instance. Minimally the mock will return &lt;code>conf&lt;/conf> when
{@link Connection#getConfiguration()} is invoked. Be sure to shutdown the connection when done
by calling {@link Connection#close()} else it will stick around; this is probably not what you
want.
@param conf configuration
@return ConnectionImplementation object for <code>conf</code>
hbase-server/src/test/java/org/apache/hadoop/hbase/client/HConnectionTestingUtility.java