title: How to mock a @Value class using Mockito?
body: <p>I want to unit test the following class:</p>
  <pre class="lang-java prettyprint-override"><code>@Data
  @AllArgsConstructor
  public class MyClass {
  
     private MyValueClass valueObject;
  
     public BigDecimal someMethod(int startId, int endId) {
  
        List&lt;BigDecimal&gt; values = valueObject.get(startId, endId);
        
        ...
  </code></pre>
  <p>I tried to mock <code>MyValueClass</code> which looks like:</p>
  <pre class="lang-java prettyprint-override"><code>@Value //lombok annotation
  public class MyValueClass {
  
     private List&lt;Data&gt; someData;
  
     public List&lt;BigDecimal&gt; get(int startId, int endId) {
  
         //code to get subset of someData with ids between startId and endId
  
     }
  </code></pre>
  <p>But when I run this junit (jupiter) test:</p>
  <pre class="lang-java prettyprint-override"><code>@ExtendWith(MockitoExtension.class)
  class MyClassTest {
  
     private MyClass myClass;
  
     @Mock
     private MyValueClass valueOjectMock;
  
     @BeforeEach
     public void setUp() {
        myClass= new myClass(valueOjectMock);
     }
  
     @Test
     void test() {
        when(valueOjectMock.get(1,5))
           .thenReturn(new ArrayList&lt;&gt;());
        ....
     }
  }
  </code></pre>
  <p>I get the following error:</p>
  <pre><code>org.mockito.exceptions.base.MockitoException: 
  Cannot mock/spy class com.seasset.funds.performance.domain.FundReturns
  Mockito cannot mock/spy because :
   - final class
      at org.mockito.junit.jupiter.MockitoExtension.beforeEach(MockitoExtension.java:153)
  </code></pre>
  <p>But <code>MyValueClass</code> is not final. Why do I get this error? How can I mock this class?</p>