Search in sources :

Example 1 with CommandDescriptionService

use of org.eclipse.smarthome.core.service.CommandDescriptionService in project smarthome by eclipse.

the class GenericItemTest method testCommandDescriptionWithLocale.

@Test
public void testCommandDescriptionWithLocale() {
    TestItem item = new TestItem("test");
    CommandDescriptionService commandDescriptionService = mock(CommandDescriptionService.class);
    when(commandDescriptionService.getCommandDescription(eq("test"), any(Locale.class))).thenReturn(new CommandDescription() {

        @Override
        @NonNull
        public List<@NonNull CommandOption> getCommandOptions() {
            return Arrays.asList(new CommandOption("C1", "Command 1"), new CommandOption("C2", "Command 2"), new CommandOption("C3", "Command 3"));
        }
    });
    item.setCommandDescriptionService(commandDescriptionService);
    assertThat(item.getCommandDescription(Locale.getDefault()).getCommandOptions(), hasSize(3));
}
Also used : Locale(java.util.Locale) CommandDescriptionService(org.eclipse.smarthome.core.service.CommandDescriptionService) CommandOption(org.eclipse.smarthome.core.types.CommandOption) CommandDescription(org.eclipse.smarthome.core.types.CommandDescription) NonNull(org.eclipse.jdt.annotation.NonNull) List(java.util.List) Test(org.junit.Test)

Example 2 with CommandDescriptionService

use of org.eclipse.smarthome.core.service.CommandDescriptionService in project smarthome by eclipse.

the class GenericItemTest method testCommandDescription.

@Test
public void testCommandDescription() {
    TestItem item = new TestItem("test");
    CommandDescriptionService commandDescriptionService = mock(CommandDescriptionService.class);
    when(commandDescriptionService.getCommandDescription("test", null)).thenReturn(new CommandDescription() {

        @Override
        @NonNull
        public List<@NonNull CommandOption> getCommandOptions() {
            return Arrays.asList(new CommandOption("ALERT", "Alert"), new CommandOption("REBOOT", "Reboot"));
        }
    });
    item.setCommandDescriptionService(commandDescriptionService);
    assertThat(item.getCommandDescription().getCommandOptions(), hasSize(2));
}
Also used : CommandDescriptionService(org.eclipse.smarthome.core.service.CommandDescriptionService) CommandOption(org.eclipse.smarthome.core.types.CommandOption) CommandDescription(org.eclipse.smarthome.core.types.CommandDescription) NonNull(org.eclipse.jdt.annotation.NonNull) List(java.util.List) Test(org.junit.Test)

Example 3 with CommandDescriptionService

use of org.eclipse.smarthome.core.service.CommandDescriptionService in project smarthome by eclipse.

the class ItemRegistryImplTest method assertCommandDescriptionServiceGetsRemoved.

@Test
public void assertCommandDescriptionServiceGetsRemoved() {
    CommandDescriptionService commandDescriptionService = mock(CommandDescriptionService.class);
    ((ItemRegistryImpl) itemRegistry).setCommandDescriptionService(commandDescriptionService);
    GenericItem item = spy(new SwitchItem("Item1"));
    itemProvider.add(item);
    verify(item).setCommandDescriptionService(any(CommandDescriptionService.class));
    ((ItemRegistryImpl) itemRegistry).unsetCommandDescriptionService(commandDescriptionService);
    verify(item).setCommandDescriptionService(null);
}
Also used : CommandDescriptionService(org.eclipse.smarthome.core.service.CommandDescriptionService) ItemRegistryImpl(org.eclipse.smarthome.core.internal.items.ItemRegistryImpl) SwitchItem(org.eclipse.smarthome.core.library.items.SwitchItem) Test(org.junit.Test) JavaTest(org.eclipse.smarthome.test.java.JavaTest)

Aggregations

CommandDescriptionService (org.eclipse.smarthome.core.service.CommandDescriptionService)3 Test (org.junit.Test)3 List (java.util.List)2 NonNull (org.eclipse.jdt.annotation.NonNull)2 CommandDescription (org.eclipse.smarthome.core.types.CommandDescription)2 CommandOption (org.eclipse.smarthome.core.types.CommandOption)2 Locale (java.util.Locale)1 ItemRegistryImpl (org.eclipse.smarthome.core.internal.items.ItemRegistryImpl)1 SwitchItem (org.eclipse.smarthome.core.library.items.SwitchItem)1 JavaTest (org.eclipse.smarthome.test.java.JavaTest)1