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

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.

主站蜘蛛池模板: 兴化市| 泌阳县| 滨海县| 霸州市| 仙桃市| 黄陵县| 峨山| 双流县| 芦山县| 泰来县| 漳浦县| 阆中市| 丹寨县| 洛隆县| 洛浦县| 南部县| 建湖县| 密山市| 连云港市| 凤阳县| 武乡县| 尉犁县| 偃师市| 启东市| 连云港市| 兴海县| 平塘县| 遂昌县| 福贡县| 利川市| 邯郸市| 肃宁县| 丁青县| 平和县| 威信县| 松原市| 龙陵县| 邯郸市| 沂源县| 曲周县| 翼城县|