transcendental-lisp/test/terminal/TerminalHistoryTest.java

104 lines
2.1 KiB
Java
Raw Normal View History

2017-04-04 07:56:35 -04:00
package terminal;
import static org.junit.Assert.*;
import org.junit.*;
public class TerminalHistoryTest {
private TerminalHistory history;
private void assertAtBeginning() {
assertNull(history.getPreviousLine());
}
private void assertAtEnd() {
assertNull(history.getNextLine());
}
private void assertPrevious(String expected) {
assertEquals(expected, history.getPreviousLine());
}
private void assertNext(String expected) {
assertEquals(expected, history.getNextLine());
}
@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();
assertAtEnd();
}
@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");
assertAtEnd();
}
@Test
public void moveBackAndForth() {
history.addLine("one");
history.addLine("two");
assertAtEnd();
assertPrevious("two");
assertAtEnd();
assertPrevious("one");
assertAtBeginning();
assertNext("two");
assertAtEnd();
assertPrevious("one");
assertAtBeginning();
assertNext("two");
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();
}
}