Skip to content

Commit

Permalink
[#145] Temp test fix
Browse files Browse the repository at this point in the history
  • Loading branch information
susanw1 committed Nov 15, 2024
1 parent 896f9b8 commit 81f1601
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import ch.qos.logback.classic.Level;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
Expand Down Expand Up @@ -105,18 +106,20 @@ public void shouldRegisterFailureOnReadError() throws IOException {
when(cmdStream.read(Mockito.any(byte[].class))).thenReturn(0).thenThrow(new IOException("my test exception"));
makeItRun(cmdStream);
// E3 implies ERROR
assertThat(responseCollector.next()).isPresent().get().isEqualTo("\"LocalChannel\"E3".getBytes(UTF_8));
assertThat(responseCollector.next()).hasValue("\"LocalChannel\"E3".getBytes(UTF_8));
}

@Test
public void shouldRegisterClosureOnEOF() throws IOException {
ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) org.slf4j.LoggerFactory.getLogger("net.zscript");
root.setLevel(Level.TRACE);
// Force the InputStream to fail
final InputStream cmdStream = mock(InputStream.class);
when(cmdStream.read(Mockito.any(byte[].class))).thenReturn(-1);

makeItRun(cmdStream);
// E1 implies CLOSED
assertThat(responseCollector.next()).isPresent().get().isEqualTo("\"LocalChannel\"E1".getBytes(UTF_8));
assertThat(responseCollector.next()).hasValue("\"LocalChannel\"E1".getBytes(UTF_8));
}

private void makeItRun(InputStream cmdStream) throws IOException {
Expand Down Expand Up @@ -149,6 +152,6 @@ public void shouldOutputChannelInfo() {
sequenceOutStream.close();

await().atMost(ofSeconds(5)).until(() -> !responseCollector.isEmpty());
assertThat(responseCollector.next()).isPresent().get().isEqualTo("\"LocalChannel\"E".getBytes(UTF_8));
assertThat(responseCollector.next()).hasValue("\"LocalChannel\"E".getBytes(UTF_8));
}
}

0 comments on commit 81f1601

Please sign in to comment.