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.

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.
advertisement
advertisement

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.

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.
advertisement

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.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.