title: unit test for insertion method using mockito
body: <p>I have a problem in  the unit test of the insertion method,although i use a mock object ,the data is inserted to the database ,what's wrong in this please ?</p>
  
  <p>here's the source code of the method</p>
  
  <pre><code>public void InsertPersonalData(PersonalData personaldata) throws SQLException, DAOException, ClassNotFoundException {
          try {
              PreparedStatement psmt = MysqlConnection.getPreparedStatement("INSERT INTO personal_data values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
              psmt.setString(1, personaldata.getiD());
              psmt.setString(2, personaldata.getPatientName());
              psmt.setString(3, personaldata.getBirthDate());
              psmt.setString(4, personaldata.getPlaceOfBirth());
              psmt.setString(5, personaldata.getGender());
              psmt.setString(6, personaldata.getNationality());
              psmt.setString(7, personaldata.getCurrentAddress());
              psmt.setString(8, personaldata.getCityAddress());
              psmt.setString(9, personaldata.getMaritalStatus());
              psmt.setString(10, personaldata.getOffspring());
              psmt.setString(11, personaldata.getAgeOfYoungestOffspring());
              psmt.setString(12, personaldata.getWorkNature());
              psmt.setString(13, personaldata.getPhoneNumber());
              psmt.setString(14, personaldata.geteMail());
  
              psmt.executeUpdate();
  
          } catch (SQLException e) {
              throw new DAOException(e);
  
          }
  </code></pre>
  
  <p>here's how i used mocking</p>
  
  <pre><code>@RunWith(MockitoJUnitRunner.class)
  public class PersonalDataDaoTest {
  
      public PersonalData newpd;
  
      @Mock
      Connection conn;
  
      @Mock
      PreparedStatement psmt;
  
      @InjectMocks
      PersonalDataDao newDAO = new PersonalDataDao();
  </code></pre>
  
  <p>the test code:</p>
  
  <pre><code>@Test
      public void HappyTestForInsert() throws SQLException, DAOException, ClassNotFoundException {
          when(conn.prepareStatement(anyString())).thenReturn(psmt);
          //ArgumentCaptor&lt;Integer&gt; intcaptor = ArgumentCaptor.forClass(int.class);
          ArgumentCaptor&lt;String&gt; stringcaptor = ArgumentCaptor.forClass(String.class);
          String id = "11";
          String patientName = "yara";
          String birthDate = "2001-12-5";
          String placeOfBirth = "cairo";
          String gender = "female";
          String nationality = "egyptian";
          String currentAddress = "cairo";
          String cityAddress = "cairo";
          String maritalStatus = "married";
          String offspring = "1";
          String ageOfYoungestOffspring = "2";
          String workNature = "teacher";
          String phoneNumber = "0324324234";
          String eMail = "yara@hotmail.com";
  
          PersonalData p = new PersonalData(id, patientName, birthDate, placeOfBirth, gender, nationality, currentAddress, cityAddress, maritalStatus, offspring, ageOfYoungestOffspring, workNature, phoneNumber, eMail);
          newDAO.InsertPersonalData(p);
          //verify(psmt, times(1)).setInt(anyInt(), intcaptor.capture());
          verify(psmt, times(14)).setString(anyInt(), stringcaptor.capture());
          Assert.assertTrue(stringcaptor.getAllValues().get(0).equals(id));
          Assert.assertTrue(stringcaptor.getAllValues().get(1).equals(patientName));
          Assert.assertTrue(stringcaptor.getAllValues().get(2).equals(birthDate));
          Assert.assertTrue(stringcaptor.getAllValues().get(3).equals(placeOfBirth));
          Assert.assertTrue(stringcaptor.getAllValues().get(4).equals(gender));
          Assert.assertTrue(stringcaptor.getAllValues().get(5).equals(nationality));
          Assert.assertTrue(stringcaptor.getAllValues().get(6).equals(currentAddress));
          Assert.assertTrue(stringcaptor.getAllValues().get(7).equals(cityAddress));
          Assert.assertTrue(stringcaptor.getAllValues().get(8).equals(maritalStatus));
          Assert.assertTrue(stringcaptor.getAllValues().get(9).equals(offspring));
          Assert.assertTrue(stringcaptor.getAllValues().get(10).equals(ageOfYoungestOffspring));
          Assert.assertTrue(stringcaptor.getAllValues().get(11).equals(workNature));
          Assert.assertTrue(stringcaptor.getAllValues().get(12).equals(phoneNumber));
          Assert.assertTrue(stringcaptor.getAllValues().get(13).equals(eMail));
  
      }
  </code></pre>