lundi 2 octobre 2017

How to mock this class?

I'm a student who really needs help with how to mock this class or any part of it. I've tried the general way but it's not working. I think I'm lacking the knowledge and I need help from anyone who knows how to mock these in any way to help me.
I have no idea how to do it

package IT_chatbot;

import java.util.Properties;
import java.util.Scanner;

import javax.mail.Message;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class request_remark {
private static Scanner scan = new Scanner(System.in);
public static String remark(String studentID){

    String courseCode="";

    System.out.println("Please enter course Code to be remarked:");
    courseCode = scan.nextLine();
    System.out.println("The message is sending...");


    Properties props = new Properties();
    props.put("mail.smtp.host", "smtp.gmail.com");
    props.put("mail.smtp.port", "587");     
    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.starttls.enable", "true");
   Session session = Session.getInstance(props,new javax.mail.Authenticator()
   {
      protected PasswordAuthentication getPasswordAuthentication() 
      {
         return new PasswordAuthentication("kmitl@gmail.com","2016mmm");
      }
  });

  try
  {   
   MimeMessage message = new MimeMessage(session);
      message.setFrom(new InternetAddress("kmitl@gmail.com"));
      message.addRecipient(Message.RecipientType.TO,new InternetAddress("wn1apc@gmail.com"));
      message.setSubject("Request a remark for a recent past of"+studentID);
      StringBuffer emailMessage = new StringBuffer("Dear Hades");
       emailMessage.append("\r\n");
       emailMessage.append("We've recieved the remark request from student number " + studentID+ " subject " + courseCode);
       emailMessage.append("\r\n");
       emailMessage.append("\r\n");
       emailMessage.append("\r\n");
       emailMessage.append("Best regard,");
       emailMessage.append("\r\n");
       emailMessage.append("\r\n");
      message.setText(emailMessage.toString());
      Transport.send(message);


   }
   catch(Exception e)
   {
     e.printStackTrace();
   }
return courseCode;
}
}

Aucun commentaire:

Enregistrer un commentaire