Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

need help with this lab in java, using the starting code that is given at the bo

ID: 3788072 • Letter: N

Question

need help with this lab in java, using the starting code that is given at the bottom:

Your task for this lab is to develop a comprehensive set of unit tests for the getEarlier method in the Clock class.

This method is designed to accept to Clock objects and return the one set to the time that is earlier in the day.

If both instances are set to the same time, the method returns the first instance.

Your tests should cover all (or at least most) execution paths through the method to ensure that they work correctly.

Try to think of boundary cases and develop tests to ensure the method performs appropriately in those cases.

output example below:

Clock c1 = new Clock(12, 00, "a.m.");

Clock c2 = new Clock(12, 00, "p.m.");

Clock result = Clock.getEarlier(c1, c2);

assertEquals(result, c1);

here is the starting code:

***blahblahblah**** driver class**

import java.util.Scanner;

public class blahblahblah {

static Scanner input = new Scanner(System.in);
  
public static void main(String[] args) {
  
Clock appointmentTime = new Clock(12, 30, "p.m.");
Clock userTime = new Clock(getUserHours(), getUserMinutes(),
getUserMeridian());
  
if (Clock.getEarlier(userTime, appointmentTime) == userTime) {
System.out.println("You're not late!");
} else {
System.out.println("You're late!");
}
  
}
  
  
public static int getUserHours() {
System.out.print("What hour should the clock be set to? ");
int hours = input.nextInt();
input.nextLine(); // consumes the trailing newline
return hours;
}
  
public static int getUserMinutes() {
System.out.print("What minute should the clock be set to? ");
int hours = input.nextInt();
input.nextLine(); // consumes the trailing newline
return hours;
}
  
public static String getUserMeridian() {
System.out.print("Is it a.m. (a) or p.m. (p)? " );
String answer = input.nextLine();
if (answer.toLowerCase().startsWith("a")) {
return "a.m.";
} else {
return "p.m.";
}
}

}

***end of blahblahblah driver class*****

********clock.java************

package blahblahblah;

public class Clock {
  
private int hours;
private int minutes;
private String meridian;
  
public Clock() {
hours = 12;
minutes = 0;
meridian = "a.m.";
}
  
public Clock(int hours, int minutes, String meridian) {
this.hours = hours;
this.minutes = minutes;
this.meridian = meridian;
}
  
@Override
public String toString() {
String time = hours + ":";
if (minutes < 10) {
time += "0";
}
time += minutes + " " + meridian;
return time;
}
  
public static Clock getEarlier(Clock c1, Clock c2) {
if (c1.meridian.equals("a.m.") && c2.meridian.equals("p.m.")) {
return c1;
} else if (c1.meridian.equals("p.m.") && c2.meridian.equals("a.m.")) {
return c2;
} else {
// there is a special case if it is 12-something a.m. or p.m. on one
// but not both of the clocks (i.e. 12:00 a.m. is before 1:00 a.m.)
if (c1.hours == 12 && c2.hours != 12) {
return c1;
} else if (c2.hours == 12 && c1.hours != 12) {
return c2;
} else {
if (c1.hours < c2.hours) {
return c1;
} else if (c2.hours < c1.hours) {
return c2;
} else {
if (c1.minutes < c2.minutes) {
return c1;
} else if (c2.minutes < c1.minutes) {
return c2;
} else {
// the clocks have the same time
assert c1.toString().equals(c2.toString()):
c1.toString() + " " + c2.toString();
// we will arbitrarily return the first one
return c1;
}
}
}
}
}
}

Explanation / Answer

public class FinalInvoiceStepTestMocked { private FinalInvoiceStep finalInvoiceStep = null; private Customer customer = null; private Invoice invoice = null; private PrinterService printerService = null; private EmailService emailService =null; @Before public void beforeEachTest() { printerService = Mockito.mock(PrinterService.class); emailService = Mockito.mock(EmailService.class); customer = new Customer(); finalInvoiceStep = new FinalInvoiceStep(printerService, emailService); invoice = new Invoice(); } @Test public void normalCustomer() { customer.wantsEmail(true); finalInvoiceStep.handleInvoice(invoice, customer); //Nothing should be printed Mockito.verifyZeroInteractions(printerService); //Something must be emailed Mockito.verify(emailService).sendInvoice(invoice, customer.getEmail()); } @Test public void customerWithPrintedInvoice() { customer.wantsEmail(false); finalInvoiceStep.handleInvoice(invoice, customer); //Nothing should be emailed Mockito.verifyZeroInteractions(emailService); //The invoice must be printed Mockito.verify(printerService).printInvoice(invoice); } }