use of com.willwinder.universalgcodesender.connection.Connection in project Universal-G-Code-Sender by winder.
the class BufferedCommunicatorTest method responseMessageOnErrorShouldDispatchPauseEvent.
@Test
public void responseMessageOnErrorShouldDispatchPauseEvent() {
// Given
Connection connection = mock(Connection.class);
instance.setConnection(connection);
SerialCommunicatorListener serialCommunicatorListener = mock(SerialCommunicatorListener.class);
instance.addCommandEventListener(serialCommunicatorListener);
asl.add(new GcodeCommand("G0"));
asl.add(new GcodeCommand("G0"));
instance.streamCommands();
// When
instance.responseMessage("error");
// Then
assertTrue(instance.isPaused());
verify(serialCommunicatorListener, times(1)).communicatorPausedOnError();
}
use of com.willwinder.universalgcodesender.connection.Connection in project Universal-G-Code-Sender by winder.
the class BufferedCommunicatorTest method softResetShouldClearBuffersAndResumeOperation.
@Test
public void softResetShouldClearBuffersAndResumeOperation() {
// Given
Connection connection = mock(Connection.class);
instance.setConnection(connection);
asl.add(new GcodeCommand("G0"));
cb.add("G0");
instance.pauseSend();
assertTrue(instance.isPaused());
assertEquals(1, instance.numActiveCommands());
assertEquals(1, instance.numBufferedCommands());
// When
instance.softReset();
// Then
assertFalse("The communicator should resume operation after a reset", instance.isPaused());
assertEquals("There should be no active commands", 0, instance.numActiveCommands());
assertEquals("There should be no buffered manual commands", 0, instance.numBufferedCommands());
}
use of com.willwinder.universalgcodesender.connection.Connection in project Universal-G-Code-Sender by winder.
the class BufferedCommunicatorTest method responseMessageOnErrorOnLastCommandStreamShouldNotPauseTheCommunicator.
@Test
public void responseMessageOnErrorOnLastCommandStreamShouldNotPauseTheCommunicator() throws IOException, GcodeStreamReader.NotGcodeStreamFile {
// Given
Connection connection = mock(Connection.class);
instance.setConnection(connection);
// Create a gcode file stream
File gcodeFile = new File(tempDir, "gcodeFile");
GcodeStreamWriter gcodeStreamWriter = new GcodeStreamWriter(gcodeFile);
gcodeStreamWriter.addLine("G0", "G0", null, 0);
gcodeStreamWriter.close();
// Stream
instance.queueStreamForComm(new GcodeStreamReader(gcodeFile));
instance.streamCommands();
// When
instance.responseMessage("error");
// Then
assertFalse(instance.isPaused());
}
use of com.willwinder.universalgcodesender.connection.Connection in project Universal-G-Code-Sender by winder.
the class BufferedCommunicatorTest method responseMessageOnErrorOnLastManualCommandShouldNotPauseTheCommunicator.
@Test
public void responseMessageOnErrorOnLastManualCommandShouldNotPauseTheCommunicator() {
// Given
Connection connection = mock(Connection.class);
instance.setConnection(connection);
cb.add("G0");
instance.streamCommands();
// When
instance.responseMessage("error");
// Then
assertFalse(instance.isPaused());
}
use of com.willwinder.universalgcodesender.connection.Connection in project Universal-G-Code-Sender by winder.
the class BufferedCommunicatorTest method testStreamCommandsOrderStringCommandsFirst.
@Test
public void testStreamCommandsOrderStringCommandsFirst() throws Exception {
// Given
Connection connection = mock(Connection.class);
instance.setConnection(connection);
ArgumentCaptor<String> commandCaptor = ArgumentCaptor.forClass(String.class);
doNothing().when(connection).sendStringToComm(commandCaptor.capture());
// Create a gcode file stream
File gcodeFile = new File(tempDir, "gcodeFile");
GcodeStreamWriter gcodeStreamWriter = new GcodeStreamWriter(gcodeFile);
gcodeStreamWriter.addLine("G0", "G0", null, 0);
gcodeStreamWriter.close();
instance.queueStreamForComm(new GcodeStreamReader(gcodeFile));
instance.queueStringForComm("G1");
// When
instance.streamCommands();
// Then
assertEquals(2, commandCaptor.getAllValues().size());
assertEquals("The first command processed should be the string command", "G1\n", commandCaptor.getAllValues().get(0));
assertEquals("The second command should be from the stream", "G0\n", commandCaptor.getAllValues().get(1));
}
Aggregations