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()); }
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()); }
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Concept explainers
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
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
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps
Knowledge Booster
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
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education