Monday, May 4, 2009

DDTUnit snippet to represent a HashMap containing complex objects

As a big fan of DDTUnit for Java unit testing, this gets me every time. I often need a java.util.HashMap object with complex values. Here it is for posterity (and later lookup) :

    <obj id="masterResults" type="java.util.HashMap" 
hint="map" keytype="string" valuetype="com.company.project.LogFileResult">
<item>
        <key type="java.lang.String">
            data/com.com.company.project.custom/config/Lotus/Domino/nl/example.log
</key>
            <value type="com.company.project.LogFileResult" hint="call"
                   method="constructor">
</value>

        </item>
    </obj>






The Java code to retrieve it inside the DDTUnit fixture:







    HashMap masterResults = (HashMap) getObject("masterResults");

No comments:

Post a Comment