Using data wrapper objects
Injecting a data wrapper object
Data wrapper objects must be injected into a class in order to make the object available to the class's methods.
Data wrapper objects are injected into classes using the following syntax:
@Inject var objName : DataWrapper<objType>
where:
objNameis the object name.objTypeis the object type.
For example:
@Inject
private var _currentUser : DataWrapper<String>
Interacting with a data wrapper object
Once a data wrapper object has been injected into a class, all of the methods can interact with it.
For example, the following method comes from the CucumberStepBase class:
01 protected var _defaultUser : String = "aapplegate"
02
03 property set CurrentUser(username : String) {
04 _currentUser.set(username)
05 }
06
07 property get CurrentUser() : String {
08 if (_currentUser.get() == null) {
09 CurrentUser = _defaultUser
10 }
11 return _currentUser.get() as String
12 }
Line 1 defines a _defaultUser String, which is set to "aapplegate".
Lines 3 to 5 define a setter for the CurrentUser property, which simply sets the
_currentUser object.
Lines 5 through 12 define a getter for the CurrentUser property. The intention of this
getter is to always provide a non-null value. If _currentUser has been set to a non-null
value by some other method, this method returns that value. Otherwise, this method sets
_currentObject to the default user's name (which, based on line 1, is aapplegate) and then
returns that name.
