-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hello,
So far, I've been using @WireVariable to inject Spring beans on my controllers and it's known to work perfectly.
@WireVariable("someBean")
private SomeBean someBean;
But here is my question... Is there a way to achieve the same result but with constructor injection? It's a known good practice to inject beans via constructor so it's easy to mock them on unit tests and such. Like this
private final SomeBean somebean;
public MyController(SomeBean someBean) {
this.somebean = someBean;
}
Can this be achieved somehow or I simply cannot unit test a ZK Controller?
@WireVariable doesn't support contructor injection. This doesn't mean you "can't" test your controllers at all. As always you can provide a setter to set the bean from your test cases, or use reflection to access the private field. There are several utils to achieve this easily.
Besides an MVC controller (such as a SelectorComposer) is usually accessing components and their properties to produce a certain output. So your controller won't function anyway without a component tree to manipulate or it doesn't serve it's purpose. (if you are using an MVVM View Model this is different story, however you were talking about Controller as in MVC)
We recommend using Zats to test your controller in combination with your zul file in order to trigger events and verify the changes to the UI.
Asked: 2017-02-13 12:42:46 +0800
Seen: 34 times
Last updated: Feb 24 '17
Zk + Spring Security redirect to strange page after login
ZK Spring webflow and flowScope
Spring security doesn't return user inside event listener
ZK Spring 3.1.1 MVVM Use @Scope/@Component or No?
Upgrading from Spring3.1 to 3.1.1 Maven.. pulls in 3.0.x jars... issues
When would I want to use ThreadLocalListener?
ZKoss with springsecurity using database