Skip to content

Commit

Permalink
Rename parameter of ChannelHandler
Browse files Browse the repository at this point in the history
Signed-off-by: Jimmy Tanagra <[email protected]>
  • Loading branch information
jimtng committed Aug 23, 2024
1 parent b8e0f94 commit 143c415
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public interface ChannelHandler {
@FunctionalInterface
interface Factory {
ChannelHandler create(Consumer<State> updateState, Consumer<Command> postCommand,
@Nullable Consumer<String> sendHttpValue, ChannelTransformation stateTransformations,
@Nullable Consumer<String> sendValue, ChannelTransformation stateTransformations,
ChannelTransformation commandTransformations, ChannelValueConverterConfig channelConfig);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ public void process(@Nullable ChannelHandlerContent content) {

@Override
public void send(Command command) {
Consumer<String> sendHttpValue = this.sendValue;
if (sendHttpValue != null && channelConfig.mode != ChannelMode.READONLY) {
commandTransformations.apply(toString(command)).ifPresent(sendHttpValue);
Consumer<String> sendValue = this.sendValue;
if (sendValue != null && channelConfig.mode != ChannelMode.READONLY) {
commandTransformations.apply(toString(command)).ifPresent(sendValue);
} else {
throw new IllegalStateException("Read-only channel");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
public class AbstractTransformingItemConverterTest {

@Mock
private @NonNullByDefault({}) Consumer<String> sendHttpValue;
private @NonNullByDefault({}) Consumer<String> sendValue;

@Mock
private @NonNullByDefault({}) Consumer<State> updateState;
Expand Down Expand Up @@ -76,15 +76,15 @@ public void close() throws Exception {

@Test
public void undefOnNullContentTest() {
TestChannelHandler realConverter = new TestChannelHandler(updateState, postCommand, sendHttpValue,
TestChannelHandler realConverter = new TestChannelHandler(updateState, postCommand, sendValue,
stateChannelTransformation, commandChannelTransformation, false);
TestChannelHandler converter = spy(realConverter);

converter.process(null);
// make sure UNDEF is send as state update
verify(updateState, only()).accept(UnDefType.UNDEF);
verify(postCommand, never()).accept(any());
verify(sendHttpValue, never()).accept(any());
verify(sendValue, never()).accept(any());

// make sure no other processing applies
verify(converter, never()).toState(any());
Expand All @@ -94,7 +94,7 @@ public void undefOnNullContentTest() {

@Test
public void commandIsPostedAsCommand() {
TestChannelHandler converter = new TestChannelHandler(updateState, postCommand, sendHttpValue,
TestChannelHandler converter = new TestChannelHandler(updateState, postCommand, sendValue,
stateChannelTransformation, commandChannelTransformation, true);

converter.process(new ChannelHandlerContent("TEST".getBytes(StandardCharsets.UTF_8), "", null));
Expand All @@ -106,12 +106,12 @@ public void commandIsPostedAsCommand() {
// check only postCommand is applied
verify(updateState, never()).accept(any());
verify(postCommand, only()).accept(new StringType("TEST"));
verify(sendHttpValue, never()).accept(any());
verify(sendValue, never()).accept(any());
}

@Test
public void updateIsPostedAsUpdate() {
TestChannelHandler converter = new TestChannelHandler(updateState, postCommand, sendHttpValue,
TestChannelHandler converter = new TestChannelHandler(updateState, postCommand, sendValue,
stateChannelTransformation, commandChannelTransformation, false);

converter.process(new ChannelHandlerContent("TEST".getBytes(StandardCharsets.UTF_8), "", null));
Expand All @@ -123,12 +123,12 @@ public void updateIsPostedAsUpdate() {
// check only updateState is called
verify(updateState, only()).accept(new StringType("TEST"));
verify(postCommand, never()).accept(any());
verify(sendHttpValue, never()).accept(any());
verify(sendValue, never()).accept(any());
}

@Test
public void sendCommandSendsCommand() {
TestChannelHandler converter = new TestChannelHandler(updateState, postCommand, sendHttpValue,
TestChannelHandler converter = new TestChannelHandler(updateState, postCommand, sendValue,
stateChannelTransformation, commandChannelTransformation, false);

converter.send(new StringType("TEST"));
Expand All @@ -137,10 +137,10 @@ public void sendCommandSendsCommand() {
verify(stateChannelTransformation, never()).apply(any());
verify(commandChannelTransformation).apply(any());

// check only sendHttpValue is applied
// check only sendValue is applied
verify(updateState, never()).accept(any());
verify(postCommand, never()).accept(any());
verify(sendHttpValue, only()).accept("TEST");
verify(sendValue, only()).accept("TEST");
}

private static class TestChannelHandler extends AbstractTransformingChannelHandler {
Expand Down

0 comments on commit 143c415

Please sign in to comment.