コード例 #1
0
  @Test
  public void should_handle_light_scenes() {
    // given
    LightSceneDevice lightSceneDevice =
        new LightSceneDevice() {
          @Override
          public List<String> getInternalDeviceGroupOrGroupAttributes(Context context) {
            return Lists.newArrayList("group");
          }
        };
    lightSceneDevice.setXmlListDevice(new XmlListDevice("dummy"));
    lightSceneDevice.getXmlListDevice().setInternal("NAME", "device");
    lightSceneDevice.getSetList().parse("scene:off,on");
    RoomDeviceList deviceList = new RoomDeviceList("").addDevice(lightSceneDevice, context);
    doReturn(deviceList)
        .when(roomListService)
        .getAllRoomsDeviceList(Optional.<String>absent(), context);

    // when
    Optional<VoiceResult> result = service.resultFor("set device on", context);

    // then
    assertThat(result).contains(new VoiceResult.Success("device", "scene on"));

    // when
    result = service.resultFor("set device off", context);

    // then
    assertThat(result).contains(new VoiceResult.Success("device", "scene off"));
  }
コード例 #2
0
  @Test
  public void should_return_error_if_no_device_matches_a_command() {
    // given
    TestDummy device = new TestDummy("lampe1");
    device.getSetList().parse("on off");
    RoomDeviceList deviceList = new RoomDeviceList("").addDevice(device, context);
    doReturn(deviceList)
        .when(roomListService)
        .getAllRoomsDeviceList(Optional.<String>absent(), context);

    // when
    Optional<VoiceResult> result = service.resultFor("schalte lampe 1", context);

    // then
    assertThat(result).contains(new VoiceResult.Error(VoiceResult.ErrorType.NO_DEVICE_MATCHED));
  }
コード例 #3
0
  @Test
  public void should_ignore_devices_not_containing_the_target_state_in_the_setlist() {
    // given
    TestDummy device = new TestDummy("lampe");
    device.getSetList().parse("off");
    RoomDeviceList deviceList = new RoomDeviceList("").addDevice(device, context);
    doReturn(deviceList)
        .when(roomListService)
        .getAllRoomsDeviceList(Optional.<String>absent(), context);

    // when
    Optional<VoiceResult> result = service.resultFor("schalte lampe on", context);

    // then
    assertThat(result).contains(new VoiceResult.Error(VoiceResult.ErrorType.NO_DEVICE_MATCHED));
  }
コード例 #4
0
  @Test
  public void should_handle_event_maps() {
    // given
    TestDummy device = new TestDummy("lampe");
    device.getSetList().parse("on off");
    device.setEventmap("on:hallo");
    RoomDeviceList deviceList = new RoomDeviceList("").addDevice(device, context);
    doReturn(deviceList)
        .when(roomListService)
        .getAllRoomsDeviceList(Optional.<String>absent(), context);

    // when
    Optional<VoiceResult> result = service.resultFor("schalte lampe hallo", context);

    // then
    assertThat(result).contains(new VoiceResult.Success("lampe", "on"));
  }
コード例 #5
0
  @Test
  @UseDataProvider("voiceCommandsForDevice")
  public void should_find_out_correct_voice_result(CommandTestCase testCase) {
    // given
    TestDummy device = new TestDummy(testCase.deviceName);
    device.getSetList().parse("on off");
    RoomDeviceList deviceList = new RoomDeviceList("").addDevice(device, context);
    doReturn(deviceList)
        .when(roomListService)
        .getAllRoomsDeviceList(Optional.<String>absent(), context);

    // when
    Optional<VoiceResult> result = service.resultFor(testCase.command, context);

    // then
    assertThat(result).contains(testCase.voiceResult);
  }
コード例 #6
0
  @UseDataProvider("pronunciation")
  @Test
  public void should_treat_voice_pronunciation_attribute(String pronunciation) {
    // given
    TestDummy device = new TestDummy("lampe");
    device.getSetList().parse("on off");
    device.setPronunciation(pronunciation);
    RoomDeviceList deviceList = new RoomDeviceList("").addDevice(device, context);
    doReturn(deviceList)
        .when(roomListService)
        .getAllRoomsDeviceList(Optional.<String>absent(), context);

    // when
    Optional<VoiceResult> result = service.resultFor("set " + pronunciation + " on", context);

    // then
    assertThat(result).contains(new VoiceResult.Success("lampe", "on"));
  }
コード例 #7
0
  @Test
  @UseDataProvider("shortcutCommandsForDevice")
  public void should_handle_shortcuts(CommandTestCase commandTestCase) {
    // given
    TestDummy device = new TestDummy(commandTestCase.deviceName);
    device.setPronunciation("garten leuchte");
    device.getSetList().parse("on off");
    RoomDeviceList deviceList = new RoomDeviceList("").addDevice(device, context);
    doReturn(deviceList)
        .when(roomListService)
        .getAllRoomsDeviceList(Optional.<String>absent(), context);

    // when
    Optional<VoiceResult> result = service.resultFor(commandTestCase.command, context);

    // then
    assertThat(result).contains(commandTestCase.voiceResult);
  }