You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by sr...@apache.org on 2019/12/18 17:15:48 UTC
[plc4x] branch next-gen-core updated: implemented
DefaultSendRequestContext test
This is an automated email from the ASF dual-hosted git repository.
sruehl pushed a commit to branch next-gen-core
in repository https://gitbox.apache.org/repos/asf/plc4x.git
The following commit(s) were added to refs/heads/next-gen-core by this push:
new 1214920 implemented DefaultSendRequestContext test
1214920 is described below
commit 121492055ae69f0eadf4a49bfe94bf642b627213
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Wed Dec 18 18:15:36 2019 +0100
implemented DefaultSendRequestContext test
---
.../spi/internal/DefaultSendRequestContext.java | 14 +++----
.../internal/DefaultSendRequestContextTest.java | 45 +++++++++++++++++-----
2 files changed, 43 insertions(+), 16 deletions(-)
diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/internal/DefaultSendRequestContext.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/internal/DefaultSendRequestContext.java
index e7acb11..7a4095d 100644
--- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/internal/DefaultSendRequestContext.java
+++ b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/internal/DefaultSendRequestContext.java
@@ -33,23 +33,23 @@ import java.util.function.Predicate;
public class DefaultSendRequestContext<T> implements ConversationContext.SendRequestContext<T> {
- private Deque<Either<Function<?, ?>, Predicate<?>>> commands = new LinkedList<>();
+ protected Deque<Either<Function<?, ?>, Predicate<?>>> commands = new LinkedList<>();
- private final Consumer<FinalContext> finisher;
+ protected final Consumer<FinalContext> finisher;
- private Class<?> expectClazz;
+ protected Class<?> expectClazz;
- private Consumer<?> packetConsumer;
+ protected Consumer<?> packetConsumer;
- private Consumer<TimeoutException> onTimeoutConsumer;
+ protected Consumer<TimeoutException> onTimeoutConsumer;
- private BiConsumer<?, ? extends Throwable> errorConsumer;
+ protected BiConsumer<?, ? extends Throwable> errorConsumer;
public DefaultSendRequestContext(Consumer<FinalContext> finisher) {
this.finisher = finisher;
}
- private DefaultSendRequestContext(Deque<Either<Function<?, ?>, Predicate<?>>> commands, Consumer<FinalContext> finisher, Class<?> expectClazz, Consumer<?> packetConsumer, Consumer<TimeoutException> onTimeoutConsumer, BiConsumer<?, ? extends Throwable> errorConsumer) {
+ protected DefaultSendRequestContext(Deque<Either<Function<?, ?>, Predicate<?>>> commands, Consumer<FinalContext> finisher, Class<?> expectClazz, Consumer<?> packetConsumer, Consumer<TimeoutException> onTimeoutConsumer, BiConsumer<?, ? extends Throwable> errorConsumer) {
this.commands = commands;
this.finisher = finisher;
this.expectClazz = expectClazz;
diff --git a/plc4j/spi/src/test/java/org/apache/plc4x/java/spi/internal/DefaultSendRequestContextTest.java b/plc4j/spi/src/test/java/org/apache/plc4x/java/spi/internal/DefaultSendRequestContextTest.java
index c5d4022..2592768 100644
--- a/plc4j/spi/src/test/java/org/apache/plc4x/java/spi/internal/DefaultSendRequestContextTest.java
+++ b/plc4j/spi/src/test/java/org/apache/plc4x/java/spi/internal/DefaultSendRequestContextTest.java
@@ -19,14 +19,19 @@
package org.apache.plc4x.java.spi.internal;
+import org.apache.plc4x.java.spi.ConversationContext;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
+import java.time.Duration;
import java.util.function.Consumer;
+import static org.hamcrest.Matchers.*;
+import static org.junit.Assert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.verify;
@@ -45,35 +50,57 @@ class DefaultSendRequestContextTest {
@Test
void expectResponse() {
-
+ SUT.expectResponse(Object.class, Duration.ZERO);
+ assertThat(SUT.expectClazz, is(Object.class));
+ assertThat(SUT.commands, hasSize(1));
+ assertThat(SUT.commands.getLast().get(), notNullValue());
+ assertThrows(ConversationContext.PlcWiringException.class, () -> SUT.expectResponse(Object.class, Duration.ZERO));
}
@Test
void check() {
+ SUT.check(o -> true);
+ assertThat(SUT.commands, hasSize(1));
+ assertThat(SUT.commands.getLast().get(), notNullValue());
}
@Test
void handle() {
+ assertThat(SUT.packetConsumer, nullValue());
+ SUT.handle(o -> o.notify());
+ assertThat(SUT.commands, hasSize(0));
+ assertThat(SUT.packetConsumer, notNullValue());
+ assertThrows(ConversationContext.PlcWiringException.class, () -> SUT.handle(o -> o.notify()));
}
@Test
void onTimeout() {
+ SUT.onTimeout(e -> e.printStackTrace());
+ assertThat(SUT.commands, hasSize(0));
+ assertThat(SUT.onTimeoutConsumer, notNullValue());
+ assertThrows(ConversationContext.PlcWiringException.class, () -> SUT.onTimeout(e -> e.printStackTrace()));
}
@Test
void onError() {
- }
-
- @Test
- void onSuccess() {
+ SUT.onError((p, e) -> e.printStackTrace());
+ assertThat(SUT.commands, hasSize(0));
+ assertThat(SUT.errorConsumer, notNullValue());
+ assertThrows(ConversationContext.PlcWiringException.class, () -> SUT.onError((p, e) -> e.printStackTrace()));
}
@Test
void unwrap() {
- }
-
- @Test
- void testUnwrap() {
+ assertThat(SUT.expectClazz, nullValue());
+ assertThat(SUT.onTimeoutConsumer, nullValue());
+ assertThrows(ConversationContext.PlcWiringException.class, () -> SUT.unwrap(o -> o.toString()));
+ SUT.expectResponse(Object.class, null);
+ SUT.onTimeout(e -> e.printStackTrace());
+ ConversationContext.SendRequestContext<String> unwrap = SUT.unwrap(o -> o.toString());
+ assertThat(unwrap, notNullValue());
+ assertThat(SUT.commands, hasSize(2));
+ assertThat(SUT.expectClazz, notNullValue());
+ assertThat(SUT.onTimeoutConsumer, notNullValue());
}
@Test