
Brady B. answered 09/27/21
College Graduate with 4 years of Java and Programming Experience
I believe the following code would solve this problem. After the time object has already been created, the first assertEquals() will check to make sure that initial hours of 4 that was given to the time object is correct. If the first assertEquals() statement passes, then you know that the getHours() function and the constructor are working correctly. After that, you should call the mutator setHours(int hours) on the time object with some integer inside. If that mutator works correctly, then the hours of the time object should be updated correctly. The second assertEquals() will check to make sure that the hours were updated.
@Test
public void testSetHours() {
Time time = new Time(4, 14, 43);
assertEquals(time.getHours(), 4);
time.setHours(10);
assertEquals(time.getHours(), 10);
}