title: Object is not getting mocked. Throwing Null Pointer Exception
body: <p>I am running my code with mockito framework. Framework is creating mocked object for One Implementation and not creating any mock object for other object due to that it is throwing null pointer exceptions. Here is my code and output:</p>
  
  <pre><code>package com.sohi;
  
  import java.io.IOException;
  
  import org.apache.hadoop.hbase.client.Get;
  import org.apache.hadoop.hbase.client.HTableInterface;
  import org.apache.hadoop.hbase.client.HTablePool;
  import org.apache.hadoop.hbase.client.Result;
  import org.apache.hadoop.hbase.util.Bytes;
  
  public class HbaseExample {
  
      private HTablePool pool;
  
      private static final String HTABLE_NAME = "table1";
  
      public String getValue(String rowKey, String columnFamily, String columnName) throws IOException {
  
          HTableInterface table = pool.getTable(HTABLE_NAME);
  
          Get get = new Get(Bytes.toBytes(rowKey)).addColumn(Bytes.toBytes(columnFamily), Bytes.toBytes(columnName));
  
          System.out.println("Is table Null  ? " + (table == null));
  
          Result result = table.get(get);
  
          System.out.println("is result null ? " + (result == null));
  
          byte [] val = result.value();
  
  
  
          return Bytes.toString(val);
      }
  
  }
  </code></pre>
  
  <hr>
  
  <p>My Mockito Test class is :</p>
  
  <hr>
  
  <pre><code>import static org.junit.Assert.*;
  import org.apache.hadoop.hbase.client.Get;
  import org.apache.hadoop.hbase.client.HTable;
  import org.apache.hadoop.hbase.client.HTablePool;
  import org.apache.hadoop.hbase.client.Result;
  import org.apache.hadoop.hbase.util.Bytes;
  import org.junit.Test;
  import org.junit.runner.RunWith;
  import org.mockito.InjectMocks;
  import org.mockito.Mock;
  import org.mockito.Mockito;
  import org.mockito.runners.MockitoJUnitRunner;
  
  import com.sohi.HbaseExample;
  
  
  @RunWith(MockitoJUnitRunner.class)
  public class HbaseExampleTest {
  
      @Mock
      HTablePool pool;
  
      @Mock
      HTable hTable;
  
      @Mock
      Result result;
  
  
      @InjectMocks
      HbaseExample hbase = new HbaseExample();
  
      private static final String HTABLE_NAME = "table1";
  
      private static final String ROW_KEY = "k1";
      private static final String COLUMN_FAMILY = "col1";
      private static final String COLUMN_NAME = "c1";
  
      private static final String CELL_VALUE = "v1";
  
      @Test
      public void test1() throws Exception {
          Get get1 = new Get(Bytes.toBytes(ROW_KEY)).addColumn(Bytes.toBytes(COLUMN_FAMILY), Bytes.toBytes(COLUMN_NAME));
  
          Mockito.when(pool.getTable(HTABLE_NAME)).thenReturn(hTable);
          Mockito.when(hTable.get(get1)).thenReturn(result);
          Mockito.when(result.value()).thenReturn(Bytes.toBytes(CELL_VALUE));
  
          String str = hbase.getValue(ROW_KEY, COLUMN_FAMILY, COLUMN_NAME);
  
          assertEquals(str, CELL_VALUE);
  
      }
  
  }
  </code></pre>
  
  <p>Output is :</p>
  
  <p>Is table Null  ? false
  is result null ? true</p>
  
  <p>And Also throwing null pointer exception near result.value().</p>
  
  <p>only table object is getting mocked.</p>