Convert a few terminal tests to kotlin
This commit is contained in:
parent
1901b7f251
commit
d902328a56
|
@ -1,39 +0,0 @@
|
|||
package terminal;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import stream.LispIOException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PipedInputStream;
|
||||
import java.io.PipedOutputStream;
|
||||
|
||||
public class TerminalConfigurationTest {
|
||||
|
||||
TerminalConfiguration configuration;
|
||||
|
||||
private PipedOutputStream createIOExceptionThrowingPipedOutputStream() {
|
||||
return new PipedOutputStream() {
|
||||
|
||||
@Override
|
||||
public void connect(PipedInputStream inputStream) throws IOException {
|
||||
throw new IOException();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
configuration = new TerminalConfiguration();
|
||||
}
|
||||
|
||||
@Test(expected = LispIOException.class)
|
||||
public void setInputPairThrowsUncheckedException() {
|
||||
configuration.setInputPair(createIOExceptionThrowingPipedOutputStream(), new PipedInputStream());
|
||||
}
|
||||
|
||||
@Test(expected = LispIOException.class)
|
||||
public void setOutputPairThrowsUncheckedException() {
|
||||
configuration.setOutputPair(createIOExceptionThrowingPipedOutputStream(), new PipedInputStream());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package terminal
|
||||
|
||||
import org.junit.jupiter.api.Assertions.assertThrows
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Test
|
||||
import stream.LispIOException
|
||||
import java.io.IOException
|
||||
import java.io.PipedInputStream
|
||||
import java.io.PipedOutputStream
|
||||
|
||||
class TerminalConfigurationTest {
|
||||
|
||||
private lateinit var configuration: TerminalConfiguration
|
||||
|
||||
private fun createIOExceptionThrowingPipedOutputStream() = object : PipedOutputStream() {
|
||||
override fun connect(inputStream: PipedInputStream) = throw IOException()
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
fun setUp() {
|
||||
configuration = TerminalConfiguration()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun setInputPairThrowsUncheckedException() {
|
||||
assertThrows(LispIOException::class.java) {
|
||||
configuration.setInputPair(createIOExceptionThrowingPipedOutputStream(), PipedInputStream())
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun setOutputPairThrowsUncheckedException() {
|
||||
assertThrows(LispIOException::class.java) {
|
||||
configuration.setOutputPair(createIOExceptionThrowingPipedOutputStream(), PipedInputStream())
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,139 +0,0 @@
|
|||
package terminal;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
public class TerminalHistoryTest {
|
||||
|
||||
private TerminalHistory history;
|
||||
|
||||
private void assertAtBeginning() {
|
||||
assertThat(history.isBeginning(), is(true));
|
||||
}
|
||||
|
||||
private void assertAtEnd() {
|
||||
assertThat(history.isEnd(), is(true));
|
||||
}
|
||||
|
||||
private void assertPrevious(String expected) {
|
||||
assertThat(history.getPreviousLine(), is(expected));
|
||||
}
|
||||
|
||||
private void assertNext(String expected) {
|
||||
assertThat(history.getNextLine(), is(expected));
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
history = new TerminalHistory();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {}
|
||||
|
||||
@Test
|
||||
public void historyStartsWithNoLines() {
|
||||
assertAtBeginning();
|
||||
assertAtEnd();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addOneLineToHistory() {
|
||||
history.addLine("test line");
|
||||
|
||||
assertPrevious("test line");
|
||||
assertAtBeginning();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void currentLineIsEmpty() {
|
||||
history.addLine("one");
|
||||
history.getPreviousLine();
|
||||
|
||||
assertNext("");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void moveBackwards() {
|
||||
history.addLine("one");
|
||||
history.addLine("two");
|
||||
|
||||
assertPrevious("two");
|
||||
assertPrevious("one");
|
||||
assertAtBeginning();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void moveForwards() {
|
||||
history.addLine("one");
|
||||
history.addLine("two");
|
||||
history.getPreviousLine();
|
||||
history.getPreviousLine();
|
||||
|
||||
assertNext("two");
|
||||
assertNext("");
|
||||
assertAtEnd();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addedLineGoesAtEndOfHistory() {
|
||||
history.addLine("one");
|
||||
history.addLine("two");
|
||||
history.getPreviousLine();
|
||||
history.getPreviousLine();
|
||||
history.addLine("three");
|
||||
|
||||
assertPrevious("three");
|
||||
assertPrevious("two");
|
||||
assertPrevious("one");
|
||||
assertAtBeginning();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void currentLineIsUpdated() {
|
||||
history.addLine("one");
|
||||
history.updateCurrentLine("purple");
|
||||
history.getPreviousLine();
|
||||
|
||||
assertNext("purple");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void previousLineIsUpdated() {
|
||||
history.addLine("one");
|
||||
history.addLine("two");
|
||||
history.getPreviousLine();
|
||||
history.updateCurrentLine("purple");
|
||||
history.getPreviousLine();
|
||||
|
||||
assertNext("purple");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void goingPastFirstLine_KeepsReturningFirstLine() {
|
||||
history.addLine("one");
|
||||
history.addLine("two");
|
||||
history.getPreviousLine();
|
||||
history.getPreviousLine();
|
||||
history.getPreviousLine();
|
||||
history.getPreviousLine();
|
||||
history.getPreviousLine();
|
||||
|
||||
assertPrevious("one");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void goingPastLastLine_KeepsReturningLastLine() {
|
||||
history.updateCurrentLine("current");
|
||||
history.getNextLine();
|
||||
history.getNextLine();
|
||||
history.getNextLine();
|
||||
history.getNextLine();
|
||||
|
||||
assertNext("current");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,133 @@
|
|||
package terminal
|
||||
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
class TerminalHistoryTest {
|
||||
|
||||
private lateinit var history: TerminalHistory
|
||||
|
||||
private fun assertAtBeginning() {
|
||||
assertThat(history.isBeginning()).isTrue()
|
||||
}
|
||||
|
||||
private fun assertAtEnd() {
|
||||
assertThat(history.isEnd()).isTrue()
|
||||
}
|
||||
|
||||
private fun assertPrevious(expected: String) {
|
||||
assertThat(history.getPreviousLine()).isEqualTo(expected)
|
||||
}
|
||||
|
||||
private fun assertNext(expected: String) {
|
||||
assertThat(history.getNextLine()).isEqualTo(expected)
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
fun setUp() {
|
||||
history = TerminalHistory()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `history starts with no lines`() {
|
||||
assertAtBeginning()
|
||||
assertAtEnd()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `add one line to the history`() {
|
||||
history.addLine("test line")
|
||||
|
||||
assertPrevious("test line")
|
||||
assertAtBeginning()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `current line is empty`() {
|
||||
history.addLine("one")
|
||||
history.getPreviousLine()
|
||||
|
||||
assertNext("")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `move backwards`() {
|
||||
history.addLine("one")
|
||||
history.addLine("two")
|
||||
|
||||
assertPrevious("two")
|
||||
assertPrevious("one")
|
||||
assertAtBeginning()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `move forwards`() {
|
||||
history.addLine("one")
|
||||
history.addLine("two")
|
||||
history.getPreviousLine()
|
||||
history.getPreviousLine()
|
||||
|
||||
assertNext("two")
|
||||
assertNext("")
|
||||
assertAtEnd()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `added line goes to the end of the history`() {
|
||||
history.addLine("one")
|
||||
history.addLine("two")
|
||||
history.getPreviousLine()
|
||||
history.getPreviousLine()
|
||||
history.addLine("three")
|
||||
|
||||
assertPrevious("three")
|
||||
assertPrevious("two")
|
||||
assertPrevious("one")
|
||||
assertAtBeginning()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `current line is updated`() {
|
||||
history.addLine("one")
|
||||
history.updateCurrentLine("purple")
|
||||
history.getPreviousLine()
|
||||
|
||||
assertNext("purple")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `previous line is updated`() {
|
||||
history.addLine("one")
|
||||
history.addLine("two")
|
||||
history.getPreviousLine()
|
||||
history.updateCurrentLine("purple")
|
||||
history.getPreviousLine()
|
||||
|
||||
assertNext("purple")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `going past the first line keeps returning the first line`() {
|
||||
history.addLine("one")
|
||||
history.addLine("two")
|
||||
history.getPreviousLine()
|
||||
history.getPreviousLine()
|
||||
history.getPreviousLine()
|
||||
history.getPreviousLine()
|
||||
history.getPreviousLine()
|
||||
|
||||
assertPrevious("one")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `going past the last line keeps returning the last line`() {
|
||||
history.updateCurrentLine("current")
|
||||
history.getNextLine()
|
||||
history.getNextLine()
|
||||
history.getNextLine()
|
||||
history.getNextLine()
|
||||
|
||||
assertNext("current")
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue