I'm learning Java Test-Driven Development, with JUnit 4. I have been given a test scenarios, and have to write the implementation code, to get the tests to pass.
This is the test scenario:
package java;
import static org.junit.jupiter.api.Assertions.assertFalse;
import java.time.LocalDateTime;
import org.junit.jupiter.api.Test;
class CallCenterTests {
private final CallCenter callCenter = new CallCenter();
private final LocalDateTime currentTime = LocalDateTime.of(2021, 1, 12, 17, 24);
@Test
public void testWillNotAcceptOutOfHours() {
assertFalse(callCenter.willAcceptCallback(currentTime, LocalDateTime.of(2021, 1, 12, 20, 15)));
}
@Test
public void testWillNotAcceptLessThanTwoHoursInFuture() {
assertFalse(callCenter.willAcceptCallback(currentTime, LocalDateTime.of(2021, 1, 12, 18, 26)));
}
@Test
public void testWillNotAcceptMoreThanSixWorkingDaysInFuture() {
assertFalse(callCenter.willAcceptCallback(currentTime, LocalDateTime.of(2021, 1, 18, 12, 1)));
}
}
This is what I know looking at the test scenarios:
There has to be written a class called CallCenter, where callCenter is the object reference.
We are using the LocalDateTime class, with a object reference called currentTime, which has parameter values of todays date and time.
There is a willAcceptCallBack method for the CallCenter class.
I am really new to Test-Driven Development, how would I write the method for this to get the tests to pass?
public boolean willAcceptCallBack(currentTime, LocalDateTime())
{
// Potential scenarios:
// 1st write a scenario that will not accept out of hours calls
// 2nd write a scenario that will not accept calls less than 2 hours in the future
// 3rd write a scenario that will accept calls more than 6 days in the future
}
Thanks in advance
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…