title: JMockit : How to write tests a unit test for a class which relies on a peristence layer?
body: <p>My requirement is to write unit tests for logic that revolves around a bean that makes calls to a persistence layer.  The calls are mostly StoredProcs, and the goal isn't to validate that the stored procs are correct, but rather that the logic in the class is accurate.</p>
  
  <p>To this extent, I would like to somehow mock the calls to the persistence layer, but haven't found an easy way to do this this.  I suspect it is because it isn't really the ideal/recommended approach (persistence layer classes should theoretically be tested with integration tests).</p>
  
  <p>In this particular instance, however, I am comfortable mocking the persistence layer.  Given the following code snippet:</p>
  
  <pre><code>public boolean isUserDataPresent(String username, PersistenceManager pm) throws IzoneBusinessException {
      // call the last date the data was refreshed
      LastOperation lastOp = getLastOperation(username, pm);
      return username != null &amp;&amp; lastOp!= null &amp;&amp; lastOperation.getActiveMergeDate() != null;
  }
  </code></pre>
  
  <p>wherein <code>getLastOperation()</code> is a private method which access the DB via calls to the <code>PersistenceManager</code> and returns a private inner object <code>LastOperation</code>, how can I safely and effectively test this method?</p>
  
  <pre><code>private LastOperation getLastOperation(String username, PersistenceManager pm)  {
  
      LastOperation lastOperation = null;
          try (CallableStatement cstmt = pm.getConnection().prepareCall("{call GetLastOperation(?)}")) {
              cstmt.setString(1, username);
              if (cstmt.execute()) {
                  ResultSet resultSet = cstmt.getResultSet();
                  if (resultSet.next()) {
                      lastOperation= new LastOperation(resultSet.getTimestamp(1));
                  }
              }
          } catch (SQLException e) {
              throw new RuntimeException(e);
          }
  
      return lastOperation;
  }
  </code></pre>