title: Mockito when method working only on debug
body: <p>I have an issue while mocking one of interface values. When I am running test in debug mode it is working fine but while run I have <code>org.mockito.exceptions.misusing.UnfinishedStubbingException</code>. </p>
  
  <p>Update 16.08.2018: it's working only when I set up breakpoint on broken line or before -  without it test crashes also on debug. And if I hold F9 all the time some test passes and some fail so it have to be connected with time of inicialization but still no idea how to fix it </p>
  
  <p>On debug mode it passes but on run mode I got exception in Service while executing: <code>String name = getPhoneBookName();</code></p>
  
  <p>I also try to move <code>Mockito.when</code> to setup block but it doesn't help</p>
  
  <p>Any ideas?</p>
  
  <p>Code looks like:</p>
  
  <p>MyServiceSpec:</p>
  
  <pre><code>private PropertyDAO propertyDAO = mock(PropertyDAO.class)     
  
  def "Should fill all fields property for existing user"() {
  
  given:"mock values to check proper form" 
  when(propertyDAO.getValue(PropertyDAO.Key.REMOTE_BOOK_NAME)).thenReturn("Phonebook")
  
  when: 
  service.someMethod()
  </code></pre>
  
  <p>Service:</p>
  
  <pre><code>someMethod() {
      String name = getPhoneBookName();
      if (name != null) {
          map.put("remotePhoneBookName", name);
      }
  }
  
  @Override
  public String getPhoneBookName() {
      return propertyDAO.getValue(PropertyDAO.Key.REMOTE_BOOK_NAME);
  }
  </code></pre>
  
  <p>PropertyDao</p>
  
  <pre><code>public interface PropertyDAO {
  String VERSION_KEY = "VERSION";
  
  public enum Key {
      VERSION,
      REMOTE_BOOK_NAME
  }
  String getValue(Key key);
  </code></pre>
  
  <p>PropertyHibernateDAO</p>
  
  <pre><code>@Repository("propertyDAO")
  @Qualifier("hibernate")
  public class PropertyHibernateDAO implements PropertyDAO {
  
  @Override
  @Transactional(readOnly = true)
  public String getValue(Key key) {
      String result = null;
      Session session = sessionFactory.getCurrentSession();
      String dbKey = DB_KEYS.get(key);
      Criteria criteria = session.createCriteria(Property.class);
      criteria.add(Restrictions.eq("key", dbKey));
      Property property = (Property) criteria.uniqueResult();
      if (property != null) {
          result = property.getValue();
      }
      return result;
  }
  </code></pre>