Defining Objects By Default Constructor and Bean Definitions

<objs><obj id="myId" type="my.class.Type" hint="bean">...</obj><objs>

To define bean objects you need to know the naming of the field setter method (without set prefix) and the datatype of the argument used for this method.
To use this functionality could be interesting in the context of providing special validation processing or calculation inside of the setter methods.
The structure looks like this:

... 
<test id="myFirstTestCase">
  <objs>
    <obj id="myObj" type="junitx.ddtunit.resources.SimpleVO" hint="bean">
      <doubleValue>12.4</doubleValue>
      <integerValue>4711</integerValue> 
    </obj>
  </objs>
</test> 
...
where object obj@id="myObj" reflects a Java object definition like the following for example
public class SimpleVO {
  private Integer integerValue; 
  private String stringValue; 
  private Double doubleValue;

  /** 
   * Default constructor. 
   */ 
  public SimpleVO() { 
    // no special initialization neccessary 
  }

  public void setDoubleValue(Double arg){ 
    // whatever check or calculation you like to process ... 
    this.doubleValue = arg; 
  }

  public void setIntegerValue(Integer arg){ 
    // whatever check or calculation you like to process ... 
    this.integerValue = arg; 
  } 
...

If you are using an empty object description

<obj id="myObj" type="junitx.ddtunit.resources.SimpleVO" hint="bean"/>
you will get the specified object as long as the default constructor is accessible (public). This is the same behavior like for hint="fields".

To specify a "null" assignment use the explizit description

<obj id="myObj" type="junitx.ddtunit.resources.SimpleVO" hint="bean">!NULL!<obj>
sf logo