JUnit Questions and Answers – Batching Tests

«
»

This set of JUnit Multiple Choice Questions & Answers (MCQs) focuses on “Batching Tests”.

1. ________ submits a value-returning task for execution and returns a Future representing the pending results of the task.
a) submit(Callable<T> task)
b) awaitTermination
c) submit(Runnable task, T result)
d) invokeAll()
View Answer

Answer: a
Explanation: The Future’s get method will return the task’s result upon successful completion.
advertisement

2. ____________ submits a Runnable task for execution and returns a Future representing that task.
a) submit(Callable<T> task)
b) awaitTermination
c) submit(Runnable task, T result)
d) invokeAll()
View Answer

Answer: c
Explanation: The function takes as parameters the task to submit and the result to return.

3. _____________ returns true if all tasks have completed following shut down.
a) submit(Callable<T> task)
b) isTerminated
c) submit(Runnable task, T result)
d) invokeAll()
View Answer

Answer: b
Explanation: isTerminated is never true unless either shutdown or shutdownNow was called first.

4. _____________ returns true if this executor has been shut down.
a) isShutdown
b) isTerminated
c) submit(Runnable task, T result)
d) invokeAll()
View Answer

Answer: a
Explanation: The isShutdown() method is used to check whether the executor has been shut down.
advertisement

5. _______________ is used for the execution of the given tasks, returning a list of Futures holding their status and results after completion.
a) isShutdown
b) isTerminated
c) invokeAll(Collection<? extends Callable<T>> tasks)
d) invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
View Answer

Answer: c
Explanation: Future.isDone() is true for each element of the returned list.

6. ______________ executes the given tasks, returning the result of one that has completed successfully.
a) isShutdown
b) invokeAny(Collection<? extends Callable<T>> tasks)
c) invokeAll(Collection<? extends Callable<T>> tasks)
d) invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
View Answer

Answer: b
Explanation: Upon normal or exceptional return, tasks that have not completed are cancelled.

7. _____________ exception is thrown while invokeAll() is interrupted while waiting.
a) InterruptedException
b) NullPointerException
c) RejectedExecutionException
d) ArrayIndexOutOfBoundsException
View Answer

Answer: a
Explanation: If the exception is thrown, the unfinished tasks are cancelled.
advertisement

8. NullPointerException is thrown if tasks or any of its elements are null.
a) True
b) False
View Answer

Answer: a
Explanation: If any of the tasks or elements are null, the methods throws a NullPointerException.

9. InterruptedException is thrown if any task cannot be scheduled for execution.
a) True
b) False
View Answer

Answer: b
Explanation: RejectedExecutionException is thrown if any task cannot be scheduled for execution.

10. ________________ initiates an orderly shutdown in which previously submitted tasks are executed.
a) Shutdown
b) invokeAny(Collection<? extends Callable<T>> tasks)
c) invokeAll(Collection<? extends Callable<T>> tasks)
d) invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
View Answer

Answer: a
Explanation: No new tasks will be accepted after calling Shutdown().

Sanfoundry Global Education & Learning Series – JUnit.
To practice all areas of Junit, here is complete set of 1000+ Multiple Choice Questions and Answers.

advertisement
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn