This set of JUnit Multiple Choice Questions & Answers (MCQs) focuses on “The Controller Component”.
1. The ______ is a component that “interacts with a client, controlling and managing the handling of each request”.
Explanation: A controller is a component that “interacts with a client, controlling and managing the handling of each request,” and tells that it is used in both presentation-tier and business-tier patterns.
2. An example of a web controller is __________
a) Apache Struts Framework
Explanation: Apache Struts Framework is an open source framework for building Servlet/JSP based web applications which is an example of a web controller.
3. What are the object(s) which make the core of the description of a controller component?
a) The Request, the Response
b) The Request, the Response, the RequestHandler, and the Controller
c) The Request
d) The RequestHandler
Explanation: The flow of control is from the Request interface to the Response interface to the RequestHandler interface finally to the Controller Interface.
4. What is the signature of the addHandler method of the Controller interface?
a) void addHandler(Request request, RequestHandler requestHandler)
b) void addHandler(RequestHandler requestHandler);
c) void addHandler(RequestHandler requestHandler);
d) void addHandler(Request request, Request requestHandler);
Explanation: The addHandler method takes a Request and then a RequestHandler to handle that request as parameters.
5. The principle of “Hollywood Principle: Don’t call us, we’ll call you” is commonly known as _____________
a) Calling Principle
b) Control Call
c) Inversion of Control
d) No-Show Principle
Explanation: Inversion of Control focuses on separating what to do from when to do.
6. Inversion of Control is used to increase __________ of the code.
Explanation: Inversion of control makes the code more extensible resulting in more modular code.
7. When the container calls setter methods after invoking a constructor with no arguments it is known as ________________
a) Constructor-based dependency injection
b) Setter-based dependency injection
c) Setter-Seller dependency injection
d) No-Constructor dependency injection
Explanation: Setter-based DI is accomplished by the container calling setter methods on your beans after invoking a no-argument constructor or no-argument static factory method.
8. Constructor-based DI is accomplished when the container invokes a class constructor with ____________
a) A number of arguments
b) No argument
c) Just one argument
d) Null objects
Explanation: Each argument represents a dependency on some other class.
9. Constructor-based DI is preferred for ___________
a) Optional dependencies
b) Mandatory dependencies
c) All dependencies
d) No dependency
Explanation: Since there has to be at least one argument, Constructor-based DI is preferred for Mandatory dependencies.
10. In the context of unit testing, the term ___________ is used to contrast and compare the objects you use in your application with the objects that you use to test your application (test objects).
a) Mock Object
b) Dummy Object
c) Domain Object
d) Real Object
Explanation: Any object under test is considered a domain object.
Sanfoundry Global Education & Learning Series – JUnit.
To practice all areas of Junit, here is complete set of 1000+ Multiple Choice Questions and Answers.