title: how to write a junit test case for this class
body: <p><strong>UPDATED</strong></p>
  
  <p>I am trying to write a test case for the following code using Mockito and Junit..
  May I know how should i write it.
  As i am new to this language i don't have much idea about it. I have coded test case for patientDao(which is passing) class but i dont know how to do it for SaveServlet</p>
  
  <p>Apologizing for the mistakes in the code.</p>
  
  <p>Note* -  I am not using any frameworks.</p>
  
  <p><strong>Save Servler.java</strong></p>
  
  <pre><code>   package com.consentServlets;
  
      import java.io.IOException;
      import java.io.PrintWriter;
  
      import javax.servlet.ServletException;
      import javax.servlet.annotation.WebServlet;
      import javax.servlet.http.HttpServlet;
      import javax.servlet.http.HttpServletRequest;
      import javax.servlet.http.HttpServletResponse;
      @WebServlet("/SavePolicy")
      public class SavePolicy extends HttpServlet {
          protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
              response.setContentType("text/html");
              PrintWriter out=response.getWriter();
              //Getting the attributes from the UI
              String policy_Name = request.getParameter("policy_name");
              String organization_Name = request.getParameter("orgid");
              String start_Date=request.getParameter("sop");
              String end_Date = request.getParameter("eop");
              //Setting the objects to insert the achieved attributes to corresponding the columns of the table
              policy savePolicy = new policy();
              savePolicy.setPolicyName(policy_Name);
              savePolicy.setOrgName(organization_Name);
              savePolicy.setStartDate(start_Date);
              savePolicy.setEndDate(end_Date);
  
  
              out.print(" &lt;link rel=\"stylesheet\" href=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.css\"&gt;");
              //calling the save function from the patientDao class to execute the query
              DataConnection ds = new DataConnection();
              int status=new policyDao(ds).add(savePolicy);
              if(status&gt;0){
                  out.print("&lt;p&gt;Policy added successfully!&lt;/p&gt;");
                  request.getRequestDispatcher("manage_policy.html").include(request, response);
              }else{
                  out.println("Sorry! failed");
              }
  
              out.close();
          }
  
      }
  </code></pre>
  
  <p><strong>PatientDao.java</strong></p>
  
  <pre><code>package com.consentServlets;
  import java.sql.Connection;
  
  import java.sql.DriverManager;
  import java.sql.PreparedStatement;
  import java.sql.ResultSet;
  import java.util.ArrayList;
  import java.util.List; 
  
  import java.sql.SQLException;
  import javax.sql.DataSource;
  
  
  public class patientDao {
      public DataConnection ds;
      public patientDao(DataConnection ds) {
          this.ds = ds;
      }
      public int save(patient addPatient){  
          int status = 0;  
          //Inserting patient details from UI to Database
          try{                            
              Connection con = ds.getConnection();  
              System.out.println(addPatient.getLastName());
              PreparedStatement ps = con.prepareStatement(  
                      "insert into patient(last_name,first_name,gender,age,dob) values (?,?,?,?,?)");  
              ps.setString(1,addPatient.getLastName());  
              ps.setString(2,addPatient.getFirstName());  
              ps.setString(3,addPatient.getGender());  
              ps.setString(4,addPatient.getAge());
              ps.setString(5,addPatient.getDoB());
  
              status = ps.executeUpdate();
              System.out.println(status);
              con.close();  
          }catch (SQLException e) {
              throw  new RuntimeException(e);}
  
  
          return status;  
      }  
  
      // Fetching all the records from table
      public  List&lt;patient&gt; getAllPatients(){  
          List&lt;patient&gt; list = new ArrayList&lt;patient&gt;();  
  
          try{  
              Connection con = ds.getConnection();  
              PreparedStatement ps = con.prepareStatement("select * from patient");  
              ResultSet rs = ps.executeQuery();  
              while(rs.next()){  
                  patient getAllPatients=new patient();  
                  getAllPatients.setId(rs.getInt(1));  
                  getAllPatients.setFirstName(rs.getString(3));  
                  getAllPatients.setLastName(rs.getString(2));  
                  getAllPatients.setGender(rs.getString(4));  
                  getAllPatients.setAge(rs.getString(5));
                  getAllPatients.setDoB(rs.getString(6));   
                  list.add(getAllPatients);  
              }  
              con.close();  
          }catch(Exception e){e.printStackTrace();}  
  
          return list;  
      }  
  }  
  </code></pre>
  
  <p><strong>patient.java</strong></p>
  
  <pre><code>package com.consentServlets;
  import java.util.List;
  //creating objects for patient class which will help to store the patient details
  public class patient {  
      private int id;  
      private String first_Name,last_Name,gender,age,dob;  
      public int getId() {  
          return id;  
      }  
      public void setId(int id) {  
          this.id = id;  
      }  
      public String getFirstName() {   
          return first_Name;  
      }  
      public void setFirstName(String first_Name) {  
          this.first_Name = first_Name;  
      }  
      public String getLastName() {  
          return last_Name;  
      }  
      public void setLastName(String last_Name) {  
          this.last_Name = last_Name;  
      }  
      public String getGender() {  
          return gender;  
      }  
      public void setGender(String Gender) {  
          this.gender = Gender;  
      }  
      public String getAge() {  
          return age;  
      }  
      public void setAge(String Age) {  
          this.age = Age;  
      }  
      public String getDoB() {  
          return dob;  
      }  
      public void setDoB(String DOB) {  
          this.dob = DOB;  
      }
  }  
  </code></pre>