Please help, write the code for the test cases:   public class JunitTest_RideRequestTest {       public Timeout globalTimeout = Timeout.seconds(1);             @Test     public void test_0_0_StaticFields() {         try {             List<Field> fields = Arrays.asList(RideRequest.class.getDeclaredFields());             int nStatic = 0;             for (Field f : fields) {                 int mod = f.getModifiers();                 if (Modifier.isStatic(mod)) {                     nStatic++;                 }             }             assertTrue("there should be three static field", nStatic == 3);         } catch (Exception x) {             fail("exception occurred trying to get the fields of this class");         }     }             @Test     public void test_0_1_NumberofFields() {         Field[] allFields = RideRequest.class.getDeclaredFields();         assertEquals("The total number of data field should be 7", 7, allFields.length);     }     // Test default constructor     @Test     public void test_1_0() {         RideRequest rideRequest = new RideRequest();         RideRequest.setTaxrate(0.1); // Assuming 10% tax rate         RideRequest.setDiscount(0.2); // Assuming 20% discount rate         assertNotNull("RideRequest object should not be null", rideRequest);         assertEquals("Default customer name should be empty", "", rideRequest.getCustomerName());         assertEquals("Default ride details should be empty", "", rideRequest.getRideDetails());         assertEquals(0.0, rideRequest.getRidePrice(), 0.0);         assertFalse("Default hasDiscount should be false", rideRequest.isHasDiscount());     }         // Test parameterized constructor with valid input     @Test     public void test_1_1() {         RideRequest request = new RideRequest("John  , Downtown   , 50.0   , Y  ");         String errorMsg = String.format(                 "\n Test constructor failed. Returned  CustomerName (%s) " + "but correct CustomerName is (%s)",                 request.getCustomerName(), "John");                 assertEquals(errorMsg,"John", request.getCustomerName());         errorMsg = String.format(                 "\n Test constructor failed. Returned  RideDetails (%s) " + "but correct RideDetails is (%s)",                 request.getRideDetails(), "Downtown");                 assertEquals(errorMsg, "Downtown", request.getRideDetails());         assertEquals("Error: The constructor failed to set the ride price.",50.0, request.getRidePrice(), 0.0);         assertTrue("Error: The constructor failed to set the ride discount.",request.isHasDiscount());     }             @Test     public void test_1_2() {         RideRequest request = new RideRequest("  Jack  , North York   , 9.99   , Y  ");         String errorMsg = String.format(                 "\n Test constructor failed. Returned  CustomerName (%s) " + "but correct CustomerName is (%s)",                 request.getCustomerName(), "Jack");                 assertEquals(errorMsg,"Jack", request.getCustomerName());         errorMsg = String.format(                 "\n Test constructor failed. Returned  RideDetails (%s) " + "but correct RideDetails is (%s)",                 request.getRideDetails(), "North York");                 assertEquals(errorMsg, "North York", request.getRideDetails());         assertEquals("Error: The constructor failed to set the ride price.",9.99, request.getRidePrice(), 0.0);         assertTrue("Error: The constructor failed to set the ride discount.",request.isHasDiscount());     }

Microsoft Visual C#
7th Edition
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Joyce, Farrell.
Chapter7: Using Methods
Section: Chapter Questions
Problem 20RQ
icon
Related questions
Question

Please help, write the code for the test cases:

 
public class JunitTest_RideRequestTest {

 
    public Timeout globalTimeout = Timeout.seconds(1);
   
   
    @Test
    public void test_0_0_StaticFields() {
        try {
            List<Field> fields = Arrays.asList(RideRequest.class.getDeclaredFields());

            int nStatic = 0;
            for (Field f : fields) {
                int mod = f.getModifiers();
                if (Modifier.isStatic(mod)) {
                    nStatic++;
                }
            }
            assertTrue("there should be three static field", nStatic == 3);
        } catch (Exception x) {
            fail("exception occurred trying to get the fields of this class");
        }
    }
   
   
    @Test
    public void test_0_1_NumberofFields() {
        Field[] allFields = RideRequest.class.getDeclaredFields();
        assertEquals("The total number of data field should be 7", 7, allFields.length);
    }
    // Test default constructor
    @Test
    public void test_1_0() {
        RideRequest rideRequest = new RideRequest();
        RideRequest.setTaxrate(0.1); // Assuming 10% tax rate
        RideRequest.setDiscount(0.2); // Assuming 20% discount rate
        assertNotNull("RideRequest object should not be null", rideRequest);
        assertEquals("Default customer name should be empty", "", rideRequest.getCustomerName());
        assertEquals("Default ride details should be empty", "", rideRequest.getRideDetails());
        assertEquals(0.0, rideRequest.getRidePrice(), 0.0);
        assertFalse("Default hasDiscount should be false", rideRequest.isHasDiscount());
    }
   
    // Test parameterized constructor with valid input
    @Test
    public void test_1_1() {
        RideRequest request = new RideRequest("John  , Downtown   , 50.0   , Y  ");
        String errorMsg = String.format(
                "\n Test constructor failed. Returned  CustomerName (%s) " + "but correct CustomerName is (%s)",
                request.getCustomerName(), "John");
       
        assertEquals(errorMsg,"John", request.getCustomerName());
        errorMsg = String.format(
                "\n Test constructor failed. Returned  RideDetails (%s) " + "but correct RideDetails is (%s)",
                request.getRideDetails(), "Downtown");
       
        assertEquals(errorMsg, "Downtown", request.getRideDetails());
        assertEquals("Error: The constructor failed to set the ride price.",50.0, request.getRidePrice(), 0.0);
        assertTrue("Error: The constructor failed to set the ride discount.",request.isHasDiscount());
    }
   
   
    @Test
    public void test_1_2() {
        RideRequest request = new RideRequest("  Jack  , North York   , 9.99   , Y  ");
        String errorMsg = String.format(
                "\n Test constructor failed. Returned  CustomerName (%s) " + "but correct CustomerName is (%s)",
                request.getCustomerName(), "Jack");
       
        assertEquals(errorMsg,"Jack", request.getCustomerName());
        errorMsg = String.format(
                "\n Test constructor failed. Returned  RideDetails (%s) " + "but correct RideDetails is (%s)",
                request.getRideDetails(), "North York");
       
        assertEquals(errorMsg, "North York", request.getRideDetails());
        assertEquals("Error: The constructor failed to set the ride price.",9.99, request.getRidePrice(), 0.0);
        assertTrue("Error: The constructor failed to set the ride discount.",request.isHasDiscount());
    }
   
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Programming with Microsoft Visual Basic 2017
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning