JUnit Questions and Answers – The Controller Component

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”.
a) Master
b) RequestHandler
c) Controller
d) Class
View Answer

Answer: c
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
b) JUnit
c) Java
d) Php
View Answer

Answer: a
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
View Answer

Answer: b
Explanation: The flow of control is from the Request interface to the Response interface to the RequestHandler interface finally to the Controller Interface.
advertisement
advertisement

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);
View Answer

Answer: a
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
View Answer

Answer: c
Explanation: Inversion of Control focuses on separating what to do from when to do.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

6. Inversion of Control is used to increase __________ of the code.
a) Functionality
b) Cleanliness
c) Effectiveness
d) Modularity
View Answer

Answer: d
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
View Answer

Answer: b
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.
advertisement

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
View Answer

Answer: a
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
View Answer

Answer: b
Explanation: Since there has to be at least one argument, Constructor-based DI is preferred for Mandatory dependencies.
advertisement

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
View Answer

Answer: c
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.

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.