官术网_书友最值得收藏!

Time for action – running the test set

Implement your runSelectedTest method. This method will be called when the user presses the Time it! button:

public void runSelectedTest() {
  Long times = Long.parseLong(textField.getValue());
  Collection<String> results = TestSetExecutor.execute(
      (TestSet) combo.getValue(), times);
  showResults(results);
}

What just happened?

Here, we're converting the string stored in the text field to a Long number using Long.parseLong (a potential exception, NumberFormatException, pokes its head).

Once we have the Long value, we execute the results using a helper class in the biz package (TestSetExecutor). This helper class has an execute method that expects the TestSet to execute and the number of iterations to perform for each test in the TestSet. The execute method returns all the results as a collection of strings that we can proudly show to the user. As proudly as Susan when she presented her code.

Have a go hero – add a validation to Time It

When converting the value in textField, the method parseLong will throw an evil NumberFormatException if the string to parse is not a number. Try it! Use "Time It" and type a wrong numeric expression in the text field. Now try making "Time It" a production-ready application by adding the missing validation (inside the isValid method) to show a proper error message when incorrect input is given for the textField component.

主站蜘蛛池模板: 涡阳县| 绵竹市| 资溪县| 阿拉善右旗| 鸡东县| 彭山县| 西和县| 顺平县| 唐河县| 罗源县| 美姑县| 洪泽县| 天柱县| 乌拉特后旗| 稻城县| 江源县| 攀枝花市| 阿图什市| 武川县| 东兰县| 宜昌市| 家居| 绥芬河市| 永登县| 临西县| 象州县| 光泽县| 府谷县| 博野县| 佳木斯市| 武鸣县| 共和县| 琼海市| 莎车县| 石首市| 延安市| 高碑店市| 谷城县| 蒲城县| 临汾市| 安泽县|