Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package lapr.project.controller;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.IOException;
- import java.lang.reflect.Constructor;
- import java.lang.reflect.InvocationTargetException;
- import java.lang.reflect.Modifier;
- import java.sql.Timestamp;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.List;
- import java.util.Properties;
- import lapr.project.model.Bicycle;
- import lapr.project.model.Journey;
- import lapr.project.model.Location;
- import lapr.project.model.Route;
- import lapr.project.model.User;
- import org.junit.After;
- import org.junit.AfterClass;
- import org.junit.Before;
- import org.junit.BeforeClass;
- import static org.junit.Assert.*;
- import static org.junit.jupiter.api.Assertions.assertEquals;
- import org.junit.jupiter.api.Test;
- /**
- *
- * @author morei
- */
- public class SendEmailControllerTest {
- List<Route> routes = new ArrayList<>();
- Route r1 = new Route(new Location(1, 0, 0, 0), 1, new Timestamp(10), 1.0f);
- Route r2 = new Route(new Location(1, 0, 0, 0), 1, new Timestamp(10), 1.0f);
- public SendEmailControllerTest() {
- }
- @BeforeClass
- public static void setUpClass() {
- }
- @AfterClass
- public static void tearDownClass() {
- }
- @Before
- public void setUp() throws FileNotFoundException, IOException {
- }
- @After
- public void tearDown() {
- }
- @Test
- public void testConstructorIsPrivate() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
- Constructor<SendEmailController> constructor = SendEmailController.class.getDeclaredConstructor();
- assertEquals(true, Modifier.isPrivate(constructor.getModifiers()));
- constructor.setAccessible(true);
- constructor.newInstance();
- }
- /**
- * Test of send method, of class SendEmailController.
- *
- * @throws java.lang.Exception
- */
- @Test
- public void testSend() throws Exception {
- System.out.println("send");
- Properties props1 = new Properties();
- props1.load(new FileInputStream("src/main/resources/mail.properties"));
- User u = new User("adminbikeshare@isep.ipp.pt", "12345678912", 180.4, 85.6, 0);
- Bicycle b = new Bicycle(1, 1, "y", 12, null);
- routes.add(r1);
- routes.add(r2);
- Journey journey = new Journey(1, u, new Timestamp(2), b, 12, new Date(12), routes);
- boolean send = SendEmailController.send(props1, journey);
- assertEquals(true, send);
- }
- @Test
- public void testSendNull() throws Exception {
- System.out.println("send");
- Properties props1 = new Properties();
- props1.load(new FileInputStream("src/main/resources/mail.properties"));
- User u = new User("", "12345678912", 180.4, 85.6, 0);
- Bicycle b = new Bicycle(1, 1, "y", 12, null);
- routes.add(r1);
- routes.add(r2);
- Journey journey = new Journey(1, u, new Timestamp(2), b, 12, new Date(12), routes);
- boolean send = SendEmailController.send(props1, journey);
- assertEquals(false, send);
- }
- /**
- * Test of getHost method, of class SendEmailController.
- */
- @Test
- public void testGetHost() throws FileNotFoundException, IOException {
- System.out.println("getHost");
- Properties props1 = new Properties();
- props1.load(new FileInputStream("src/main/resources/mail.properties"));
- String expResult = "smtp.gmail.com";
- String result = SendEmailController.getHost(props1);
- assertEquals(expResult, result);
- }
- /**
- * Test of getFrom method, of class SendEmailController.
- */
- @Test
- public void testGetFrom() throws FileNotFoundException, IOException {
- System.out.println("getFrom");
- Properties props1 = new Properties();
- props1.load(new FileInputStream("src/main/resources/mail.properties"));
- String expResult = "bikesharingg44@gmail.com";
- String result = SendEmailController.getFrom(props1);
- assertEquals(expResult, result);
- }
- /**
- * Test of getPass method, of class SendEmailController.
- */
- @Test
- public void testGetPass() throws FileNotFoundException, IOException {
- System.out.println("getPass");
- Properties props1 = new Properties();
- props1.load(new FileInputStream("src/main/resources/mail.properties"));
- String expResult = "12345678=a";
- String result = SendEmailController.getPass(props1);
- assertEquals(expResult, result);
- }
- /**
- * Test of getSubject method, of class SendEmailController.
- */
- @Test
- public void testGetSubject() throws FileNotFoundException, IOException {
- System.out.println("getSubject");
- Properties props1 = new Properties();
- props1.load(new FileInputStream("src/main/resources/mail.properties"));
- String expResult = "Spend hours at journey";
- String result = SendEmailController.getSubject(props1);
- assertEquals(expResult, result);
- }
- /**
- * Test of getMessageText method, of class SendEmailController.
- *
- * @throws java.io.FileNotFoundException
- */
- @Test
- public void testGetMessageText() throws FileNotFoundException, IOException {
- System.out.println("getMessageText");
- Properties props1 = new Properties();
- props1.load(new FileInputStream("src/main/resources/mail.properties"));
- String expResult = "Number of spend hours";
- String result = SendEmailController.getMessageText(props1);
- assertEquals(expResult, result);
- }
- /**
- * Test of getProperties method, of class SendEmailController.
- *
- * @throws java.io.FileNotFoundException
- */
- @Test
- public void testGetProperties() throws FileNotFoundException, IOException {
- System.out.println("getProperties");
- Properties props1 = new Properties();
- props1.load(new FileInputStream("src/main/resources/mail.properties"));
- String host = "smtp.gmail.com";
- String from = "bikesharingg44@gmail.com";
- String pass = "12345678=a";
- Properties expResult = System.getProperties();
- expResult.put("mail.smtp.starttls.enable", "true");
- expResult.put("mail.smtp.host", host);
- expResult.put("mail.smtp.user", from);
- expResult.put("mail.smtp.password", pass);
- expResult.put("mail.smtp.port", "587");
- expResult.put("mail.smtp.auth", "true");
- Properties result = SendEmailController.getProperties(host, from, pass);
- assertEquals(expResult, result);
- }
- @Test
- public void testGetTo() {
- System.out.println("getMessageText");
- User u = new User("adminbikeshare@isep.ipp.pt", "12345678912", 180.4, 85.6, 0);
- Bicycle b = new Bicycle(1, 1, "y", 12, null);
- routes.add(r1);
- routes.add(r2);
- Journey journey = new Journey(1, u, new Timestamp(2), b, 12, new Date(12), routes);
- String exp = "adminbikeshare@isep.ipp.pt";
- assertEquals(exp, SendEmailController.getTo(journey));
- }
- /**
- * Test of getHours method, of class SendEmailController.
- */
- @org.junit.Test
- public void testGetHours() {
- System.out.println("getHours");
- User u = new User("adminbikeshare@isep.ipp.pt", "12345678912", 180.4, 85.6, 0);
- Bicycle b = new Bicycle(1, 1, "y", 12, null);
- routes.add(r1);
- routes.add(r2);
- Journey journey = new Journey(1, u, new Timestamp(2), b, 12, new Date(12), routes);
- int expResult = 1;
- int result = SendEmailController.getHours(journey);
- assertEquals(expResult, result);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement