title: Mockito: Mock a class but set the value of the final field when the constructor is protected
body: <p>Here's the class:</p>
  
  <pre><code>public class A {
  
     public final SqlOperator op;
     public final ImmutableList&lt;RexNode&gt; operands;
     public final RelDataType type;
  
     protected A(RelDataType type,SqlOperator op,List&lt;? extends RexNode&gt; operands) {
       assert type != null : "precondition: type != null";
       assert op != null : "precondition: op != null";
       assert operands != null : "precondition: operands != null";
       this.type = type;
       this.op = op;
       this.operands = ImmutableList.copyOf(operands);
       assert op.getKind() != null : op;
       assert op.validRexOperands(operands.size(), Litmus.THROW) : this;
  }
  </code></pre>
  
  <p>I want to mock class A but set the value of "operands" field to an empty list. The field being final I cannot modify it outside the constructor when I mock the class.</p>
  
  <p>I tried to use Reflection but that didn't work with Mockito.</p>
  
  <p>The code for which test case is needed:</p>
  
  <pre><code>public static String extractGranularity(A call) {
      if (call.getKind() != SqlKind.FLOOR || call.getOperands().size() != 2) {
          return null;
      }
      final B flag = (B) call.operands.get(1);   // This is the problem area
      final TimeUnitRange timeUnit = (TimeUnitRange) flag.getValue();
      if (timeUnit == null) {
          return null;
      }
      return timeUnitSwitch(timeUnit);
  }
  </code></pre>