Java Reference
In-Depth Information
Other Resources
@SpringBean works to inject dependencies by annotating either a prop-
erty or a setter method. This type of dependency injection is called
setter-based, because the object is first created with a zero-parameter
constructor, and then dependencies are injected on its properties.
Constructor-based DI, on the other hand, injects dependencies via para-
meters of the class's constructor.
Stripes supports only setter-based injection because action beans are
created with a zero-parameter constructor. Stripes-Spring, available at
http://www.silvermindsoftware.com/stripes , is a Stripes plug-in that adds
support for constructor-based dependency injection on action beans.
Constructor-based DI has the following advantages:
• It makes a class's dependencies more obvious because they are
all in the constructor, rather than scattered in properties or setter
methods.
• Once the dependencies have been injected via the constructor,
they can be made immutable by not providing a setter method.
Check out the Stripes-Spring project if you'd like to use constructor-
based DI on action beans.
12.3
Automated Testing with Mock Objects
Have you ever felt uneasy at the thought of making a change to your
code because you were worried about the impact on the rest of the
application? Felt weary of having to retest everything? Felt unsettled
because you might have missed something? Writing automated tests
can help you feel more confident about changing, refactoring, and im-
proving your code. 6
Stripes comes with a set of mock objects that allow you to write auto-
mated tests for the action beans of your web applications. These mocks
simulate most of what happens in a servlet container so that you can
easily exercise the different functionalities that revolve around action
beans, including the following:
• Submitting a form and verifying the results
6. The benefits and methodology of test-driven development are thoroughly discussed in
Kent Beck's Test Driven Development: By Example [ Bec02 ] .
 
 
 
Search WWH ::




Custom Search