Complete the code to assert that the method finishes within 1 second.
assertTimeout(Duration.ofSeconds([1]), () -> methodToTest());The assertTimeout method checks that methodToTest() completes within the given duration. Here, Duration.ofSeconds(1) means 1 second.
Complete the code to assert that the lambda expression finishes within 500 milliseconds.
assertTimeout(Duration.ofMillis([1]), () -> someFunction());Duration.ofSeconds() instead.Using Duration.ofMillis(500) sets the timeout to 500 milliseconds, ensuring someFunction() completes quickly.
Fix the error in the code by completing the blank with the correct import for Duration.
import [1]; assertTimeout(Duration.ofSeconds(2), () -> processData());
The Duration class is in the java.time package, so the correct import is java.time.Duration.
Fill both blanks to assert that the method finishes within 3 seconds and returns the expected value.
String result = assertTimeout(Duration.ofSeconds([1]), () -> [2]); assertEquals("success", result);
The timeout is set to 3 seconds with Duration.ofSeconds(3). The lambda calls performTask() which returns the result to check.
Fill all three blanks to assert that the method finishes within 200 milliseconds, returns a non-null value, and the result equals "done".
var result = assertTimeout(Duration.ofMillis([1]), () -> [2]); assertNotNull(result); assertEquals([3], result);
The timeout is 200 milliseconds. The method runProcess() is called inside the lambda. The test checks that the result is not null and equals "done".