Jice is an (excellent) lightweight dependency injection framework now embedded into JTestCase.
Using Jice it is possible to bulk load into JTestCase arbitrary graphs of Java objects.
This section explains how with a specific example, using the class java.text.SimpleDateFormat .
I'd recommend to read further about Jice on the jice site, even independently of JTestCase !.
In this example we will load an SimpleDateFormat object in a JTestCase test.
SimpleDateFormat is a JDK class in the package java.text
It has two methods, toPattern()
and toLocalizedPattern()
, that return
the date formatting pattern with which the instance object has been initialized.
In our case, a SimpleDateFormat will be instantiated in the jtestcase xml file using jice element , with the date pattern dd.MM.yyyy HH:mm:ss z.
When SimpleDateFormat is instantiated, it is passed another embedded class , java.util.Locale , specifying the finnish locale FI, and finnish language fi.
The toPattern()
method will be tested to return the following string dd.MM.yyyy HH:mm:ss z
The toLocalizedPattern()
method will be tested to return the string jj.nn.aaaa HH:mm:ss z .
<method name="testGetJice" test-case="standard"> <params> <param name="jice" type="" use-jice="yes"> <jice> <dateFormat xmlns="http://www.jicengine.org/jic/2.0" class="java.text.SimpleDateFormat" args="pattern,locale"> <pattern>dd.MM.yyyy HH:mm:ss z /pattern> <locale class="java.util.Locale" args="language,country"> <language>fi </language> <country>FI </country> </locale> </dateFormat> </jice> </param> </params> </method>
/**
|