Rework ThingActions (#8755)

* Remove duplication by making use of default Java generated exceptions
* Make ThingActions labels/descriptions more consistent

Signed-off-by: Wouter Born <github@maindrain.net>
This commit is contained in:
Wouter Born
2020-10-15 10:53:53 +02:00
committed by GitHub
parent aef1d10f40
commit 978e122e00
40 changed files with 305 additions and 785 deletions

View File

@@ -111,75 +111,39 @@ public class Enigma2Actions implements ThingActions {
}
// delegation methods for "legacy" rule support
public static void sendRcCommand(@Nullable ThingActions actions, String rcButton) {
if (actions instanceof Enigma2Actions) {
((Enigma2Actions) actions).sendRcCommand(rcButton);
} else {
throw new IllegalArgumentException("Actions is not an instance of Enigma2Actions");
}
public static void sendRcCommand(ThingActions actions, String rcButton) {
((Enigma2Actions) actions).sendRcCommand(rcButton);
}
public static void sendInfo(@Nullable ThingActions actions, String info) {
if (actions instanceof Enigma2Actions) {
((Enigma2Actions) actions).sendInfo(info);
} else {
throw new IllegalArgumentException("Actions is not an instance of Enigma2Actions");
}
public static void sendInfo(ThingActions actions, String info) {
((Enigma2Actions) actions).sendInfo(info);
}
public static void sendInfo(@Nullable ThingActions actions, String info, int timeout) {
if (actions instanceof Enigma2Actions) {
((Enigma2Actions) actions).sendInfo(info, timeout);
} else {
throw new IllegalArgumentException("Actions is not an instance of Enigma2Actions");
}
public static void sendInfo(ThingActions actions, String info, int timeout) {
((Enigma2Actions) actions).sendInfo(info, timeout);
}
public static void sendWarning(@Nullable ThingActions actions, String warning) {
if (actions instanceof Enigma2Actions) {
((Enigma2Actions) actions).sendWarning(warning);
} else {
throw new IllegalArgumentException("Actions is not an instance of Enigma2Actions");
}
public static void sendWarning(ThingActions actions, String warning) {
((Enigma2Actions) actions).sendWarning(warning);
}
public static void sendWarning(@Nullable ThingActions actions, String warning, int timeout) {
if (actions instanceof Enigma2Actions) {
((Enigma2Actions) actions).sendWarning(warning, timeout);
} else {
throw new IllegalArgumentException("Actions is not an instance of Enigma2Actions");
}
public static void sendWarning(ThingActions actions, String warning, int timeout) {
((Enigma2Actions) actions).sendWarning(warning, timeout);
}
public static void sendError(@Nullable ThingActions actions, String error) {
if (actions instanceof Enigma2Actions) {
((Enigma2Actions) actions).sendError(error);
} else {
throw new IllegalArgumentException("Actions is not an instance of Enigma2Actions");
}
public static void sendError(ThingActions actions, String error) {
((Enigma2Actions) actions).sendError(error);
}
public static void sendError(@Nullable ThingActions actions, String error, int timeout) {
if (actions instanceof Enigma2Actions) {
((Enigma2Actions) actions).sendError(error, timeout);
} else {
throw new IllegalArgumentException("Actions is not an instance of Enigma2Actions");
}
public static void sendError(ThingActions actions, String error, int timeout) {
((Enigma2Actions) actions).sendError(error, timeout);
}
public static void sendQuestion(@Nullable ThingActions actions, String text) {
if (actions instanceof Enigma2Actions) {
((Enigma2Actions) actions).sendQuestion(text);
} else {
throw new IllegalArgumentException("Actions is not an instance of Enigma2Actions");
}
public static void sendQuestion(ThingActions actions, String text) {
((Enigma2Actions) actions).sendQuestion(text);
}
public static void sendQuestion(@Nullable ThingActions actions, String text, int timeout) {
if (actions instanceof Enigma2Actions) {
((Enigma2Actions) actions).sendQuestion(text, timeout);
} else {
throw new IllegalArgumentException("Actions is not an instance of Enigma2Actions");
}
public static void sendQuestion(ThingActions actions, String text, int timeout) {
((Enigma2Actions) actions).sendQuestion(text, timeout);
}
}

View File

@@ -17,19 +17,19 @@ channel-type.enigma2.power.label = Power
channel-type.enigma2.power.description = Setting the power to on/off.
# actions
action.enigma2.send-rc-button.label=sendRcCommand
action.enigma2.send-rc-button.description=Send an Remote Control Command
action-input.enigma2.rc-button.label=rcButton
action-input.enigma2.rc-button.description=The Remote Control Button
action.enigma2.send-rc-button.label=send a remote control command
action.enigma2.send-rc-button.description=Send a remote control command.
action-input.enigma2.rc-button.label=Button
action-input.enigma2.rc-button.description=The remote control button
action.enigma2.send-info.label=sendInfo
action.enigma2.send-info.description=Send an info message to the TV screen
action.enigma2.send-warning.label=sendWarning
action.enigma2.send-warning.description=Send an warning message to the TV screen
action.enigma2.send-error.label=sendError
action.enigma2.send-error.description=Send an error message to the TV screen
action.enigma2.send-question.label=sendQuestion
action.enigma2.send-question.description=Send a question message to the TV screen
action.enigma2.send-info.label=send an info message
action.enigma2.send-info.description=Send an info message to the TV screen.
action.enigma2.send-warning.label=send a warning message
action.enigma2.send-warning.description=Send a warning message to the TV screen.
action.enigma2.send-error.label=send an error message
action.enigma2.send-error.description=Send an error message to the TV screen.
action.enigma2.send-question.label=send a question message
action.enigma2.send-question.description=Send a question message to the TV screen.
action-input.enigma2.text.label=text
action-input.enigma2.text.description=The message text
action-input.enigma2.timeout.label=timeout

View File

@@ -14,11 +14,9 @@ package org.openhab.binding.enigma2.internal.actions;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.*;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openhab.binding.enigma2.internal.Enigma2BindingConstants;
@@ -29,13 +27,10 @@ import org.openhab.binding.enigma2.internal.handler.Enigma2Handler;
*
* @author Guido Dolfen - Initial contribution
*/
@SuppressWarnings("null")
@NonNullByDefault
public class Enigma2ActionsTest {
@Nullable
private Enigma2Actions enigma2Actions;
@Nullable
private Enigma2Handler enigma2Handler;
private @NonNullByDefault({}) Enigma2Actions enigma2Actions;
private @NonNullByDefault({}) Enigma2Handler enigma2Handler;
public static final String SOME_TEXT = "some Text";
@BeforeEach
@@ -110,11 +105,6 @@ public class Enigma2ActionsTest {
verify(enigma2Handler).sendRcCommand("KEY_1");
}
@Test
public void testSendRcCommandStaticWithException() {
assertThrows(IllegalArgumentException.class, () -> Enigma2Actions.sendRcCommand(null, "KEY_1"));
}
@Test
public void testSendInfoStatic() {
Enigma2Actions.sendInfo(enigma2Actions, SOME_TEXT);
@@ -127,11 +117,6 @@ public class Enigma2ActionsTest {
verify(enigma2Handler).sendInfo(10, SOME_TEXT);
}
@Test
public void testSendInfoStaticWithException() {
assertThrows(IllegalArgumentException.class, () -> Enigma2Actions.sendInfo(null, SOME_TEXT));
}
@Test
public void testSendErrorStatic() {
Enigma2Actions.sendError(enigma2Actions, SOME_TEXT);
@@ -144,11 +129,6 @@ public class Enigma2ActionsTest {
verify(enigma2Handler).sendError(10, SOME_TEXT);
}
@Test
public void testSendErrorStaticWithException() {
assertThrows(IllegalArgumentException.class, () -> Enigma2Actions.sendError(null, SOME_TEXT));
}
@Test
public void testSendWarningStatic() {
Enigma2Actions.sendWarning(enigma2Actions, SOME_TEXT);
@@ -161,11 +141,6 @@ public class Enigma2ActionsTest {
verify(enigma2Handler).sendWarning(10, SOME_TEXT);
}
@Test
public void testSendWarningStaticWithException() {
assertThrows(IllegalArgumentException.class, () -> Enigma2Actions.sendWarning(null, SOME_TEXT));
}
@Test
public void testSendQuestionStatic() {
Enigma2Actions.sendQuestion(enigma2Actions, SOME_TEXT);
@@ -177,9 +152,4 @@ public class Enigma2ActionsTest {
Enigma2Actions.sendQuestion(enigma2Actions, SOME_TEXT, 10);
verify(enigma2Handler).sendQuestion(10, SOME_TEXT);
}
@Test
public void testSendQuestionStaticWithException() {
assertThrows(IllegalArgumentException.class, () -> Enigma2Actions.sendQuestion(null, SOME_TEXT));
}
}