f.Implement exporting the configuration value to the test environment.

One of the goals of the interview is to export the configuration value to the test environment. Each question has an export() method that is used for this purpose.

The following code in the SampleInterview example exports the value to the test environment.

StringQuestion first = new StringQuestion(this, "hello") { public void export(Map map) {

map.put("sample.string.value", String.valueOf(value));

}

}

An alternative is to use the setExporter() method to export the value. The following code is an example of using the setExporter() method.

first = new StringQuestion(this, "hello"); first.setExporter( Exporters.getStringValueExporter("sample.string.value"));

g.Implement error checking for the question answer.

If the user provides an invalid answer to a question, the interview cannot proceed. For most questions, error conditions are handled by returning null, which causes the Configuration Editor to display an invalid response message in red at the bottom of the question pane. Alternatively, if the Framework’s interview extension library is used, it’s possible to implement validation without subclassing the question via Question.setValidator(). For detailed information, see the com.sun.tck.j2me.interview.lib package API documentation.

The following code in the SampleInterview example implements error checking.

StringQuestion first = new StringQuestion(this, "hello") { public boolean isValueValid() {

return value != null && value != "";

}

public void export(Map map) { map.put("sample.string.value", String.valueOf(value));

}

}

Chapter 3 Test Suite Construction 33

Page 53
Image 53
Sun Microsystems 1.2 manual Implement error checking for the question answer