|
3 | 3 | #include "mocks/FakeWaterPumpSchedulerAPI.h"
|
4 | 4 | #include "mocks/FakeEnvironment.h"
|
5 | 5 |
|
| 6 | +const auto INVALID_TIME_ERROR_MESSAGE = "{ \"error\": \"invalid milliseconds value\" }"; |
6 | 7 | // test that pour_tea() method returns error message if milliseconds:
|
7 | 8 | // - greater than threshold
|
8 | 9 | // - less than 0
|
9 | 10 | // - empty string
|
10 | 11 | // - not a number
|
11 | 12 | TEST(CommandProcessor, pour_tea_invalid_milliseconds) {
|
12 |
| - const auto EXPECTED_ERROR_MESSAGE = "{ \"error\": \"invalid milliseconds value\" }"; |
13 | 13 | CommandProcessor commandProcessor(123, nullptr, nullptr);
|
| 14 | + ASSERT_EQ(commandProcessor.pour_tea("1234"), INVALID_TIME_ERROR_MESSAGE); |
| 15 | + ASSERT_EQ(commandProcessor.pour_tea("-1"), INVALID_TIME_ERROR_MESSAGE); |
| 16 | + ASSERT_EQ(commandProcessor.pour_tea(""), INVALID_TIME_ERROR_MESSAGE); |
| 17 | + ASSERT_EQ(commandProcessor.pour_tea("abc"), INVALID_TIME_ERROR_MESSAGE); |
| 18 | +} |
| 19 | + |
| 20 | +// for simplicity of the UI, we should accept as valid 0 and exactly threshold value |
| 21 | +TEST(CommandProcessor, pour_tea_valid_boundary_values) { |
| 22 | + auto env = std::make_shared<FakeEnvironment>(); |
| 23 | + auto waterPump = std::make_shared<FakeWaterPumpSchedulerAPI>(); |
| 24 | + CommandProcessor commandProcessor(123, env, waterPump); |
14 | 25 |
|
15 |
| - // array of invalid parameters |
16 |
| - const char *PARAMS[] = { "1234", "-1", "", "abc" }; |
17 |
| - for (auto param : PARAMS) { |
18 |
| - const auto response = commandProcessor.pour_tea(param); |
19 |
| - ASSERT_EQ(response, EXPECTED_ERROR_MESSAGE); |
20 |
| - } |
| 26 | + ASSERT_NE(commandProcessor.pour_tea("0"), INVALID_TIME_ERROR_MESSAGE); |
| 27 | + ASSERT_NE(commandProcessor.pour_tea("123"), INVALID_TIME_ERROR_MESSAGE); |
21 | 28 | }
|
22 | 29 |
|
23 | 30 | // test that start pouring tea by calling pour_tea() method and its stops after T milliseconds
|
|
0 commit comments