Advertisement
Guest User

Untitled

a guest
May 6th, 2018
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.75 KB | None | 0 0
  1. import static org.junit.Assert.*;
  2.  
  3. import org.junit.After;
  4. import org.junit.Before;
  5. import org.junit.Test;
  6. import org.junit.runner.JUnitCore;
  7. import org.junit.runner.Result;
  8. import org.junit.runner.notification.Failure;
  9.  
  10. /**
  11.  *
  12.  */
  13.  
  14. public class TestRunner {
  15.     public static void main(String[] args) {
  16.         Result result = JUnitCore.runClasses(AppointmentTest.class);
  17.        
  18.         for (Failure failure : result.getFailures()) {
  19.             System.out.println(failure.toString());
  20.         }
  21.        
  22.         System.out.println(result.wasSuccessful());
  23.     }
  24. }
  25. /**
  26.  * @author Allen Thomas
  27.  * Unit test cases for the appointment class
  28.  *
  29.  * This will ensure stability between the API's and verify that the internals
  30.  * of the class are functioning as expected.
  31.  *
  32.  */
  33. public class AppointmentTest {
  34.  
  35.     // Internal appointment class used for testing
  36.     private Appointment m_Appointment;
  37.    
  38.     /**
  39.      * @throws java.lang.Exception
  40.      * Initializes the test suite
  41.      */
  42.     @Before
  43.     public void setUp() throws Exception {
  44.         m_Appointment = new Appointment();
  45.     }
  46.  
  47.     /**
  48.      * @throws java.lang.Exception
  49.      * Uninitializes the test suite
  50.      */
  51.     @After
  52.     public void tearDown() throws Exception {
  53.     }
  54.  
  55.     /**
  56.      * Test that the default constructor is functioning properly
  57.      */
  58.     @Test
  59.     public void TestNoConstructor() {
  60.         m_Appointment = new Appointment();
  61.        
  62.         if (m_Appointment.getId() != 0)
  63.             fail("default appointment id set to non-zero.");
  64.        
  65.         if (m_Appointment.getFirstName() != "")
  66.             fail("default first name is not clear.");
  67.        
  68.         if (m_Appointment.getLastName() != "")
  69.             fail("default last name is not clear.");
  70.        
  71.         if (m_Appointment.getEmail() != "")
  72.             fail("default email is not clear.");
  73.        
  74.         System.out.println("TestNoConstructor test succeeded.");
  75.     }
  76.    
  77.     /**
  78.      * Test that the supplied arguments constructor is functioning properly
  79.      */
  80.     @Test
  81.     public void TestSuppliedConstructor() {
  82.         m_Appointment = new Appointment(1, "FirstName", "LastName", "FirstName@LastName.com");
  83.        
  84.         if (m_Appointment.getId() == 0)
  85.             fail("default appointment id set to zero.");
  86.        
  87.         if (m_Appointment.getFirstName() == "")
  88.             fail("default first name is clear.");
  89.        
  90.         if (m_Appointment.getLastName() == "")
  91.             fail("default last name is clear.");
  92.        
  93.         if (m_Appointment.getEmail() == "")
  94.             fail("default email is not clear.");
  95.        
  96.         System.out.println("TestSuppliedConstructor test succeeded.");
  97.     }
  98.    
  99.     /**
  100.      * Test the id functionality works
  101.      */
  102.     @Test
  103.     public void TestId() {
  104.         m_Appointment = new Appointment(1, "A", "B", "A@B.C");
  105.        
  106.         if (m_Appointment.getId() != 1)
  107.             fail("getId fail.");
  108.        
  109.         m_Appointment.setId(2);
  110.        
  111.         if (m_Appointment.getId() != 2)
  112.             fail("getId setId fail.");
  113.        
  114.         System.out.println("TestId test succeeded.");
  115.     }
  116.    
  117.     /**
  118.      * Test the name functionality works
  119.      */
  120.     @Test
  121.     public void TestName() {
  122.         m_Appointment = new Appointment(1, "A", "B", "A@B.C");
  123.        
  124.         if (m_Appointment.getFirstName() != "A")
  125.             fail("getFirstName fail.");
  126.        
  127.         m_Appointment.setFirstName("AA");
  128.        
  129.         if (m_Appointment.getFirstName() != "AA")
  130.             fail("getFirstName setFirstName fail.");
  131.        
  132.         if (m_Appointment.getLastName() != "B")
  133.             fail("getLastName fail.");
  134.        
  135.         m_Appointment.setLastName("BB");
  136.        
  137.         if (m_Appointment.getLastName() != "BB")
  138.             fail("getLastName setLastName fail.");
  139.        
  140.         System.out.println("TestName test succeeded.");
  141.     }
  142.    
  143.     /**
  144.      * Test the email functionality works
  145.      */
  146.     @Test
  147.     public void TestEmail() {
  148.         m_Appointment = new Appointment(1, "A", "B", "A@B.C");
  149.        
  150.         if (m_Appointment.getEmail() != "A@B.C")
  151.             fail("email construct fail.");
  152.        
  153.         m_Appointment.setEmail("AA@BB.CC");
  154.        
  155.         if (m_Appointment.getEmail() != "AA@BB.CC")
  156.             fail("email fail.");
  157.        
  158.         System.out.println("TestEmail test succeeded.");
  159.     }
  160.  
  161. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement