Sorry if this is an incredibly basic question, but I'm new to Java, as well as to Mockito.
I'm using mockConstruction to mock out ProcessBuilder. What I don't understand is the proper way to configure the behavior of the Process mock that is returned when ProcessBuilder::start() is called.
In code form, I'm trying to do something like this:
void testedFunction() {
String[] cmd = {"foo"};
ProcessBuilder pb = ProcessBuilder("foo");
Process process = pb.start();
// How do I, for example, make `finished == true` here?
boolean finished = process.waitFor(5, TimeUnit.SECONDS))
}
@Test
void test() {
try (MockedConstruction<ProcessBuilder> mocked = mockConstruction(ProcessBuilder.class, withSettings().defaultAnswer(RETURNS_MOCKS))) {
testedFunction();
}
}
This question is applicable to any builder-patterned type, I guess, but I thought it would be better to be specific.