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() {
|
2017-04-04 15:37:57 -04:00
|
|
|
assertTrue(history.isBeginning());
|
2017-04-04 07:56:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
private void assertAtEnd() {
|
2017-04-04 15:37:57 -04:00
|
|
|
assertTrue(history.isEnd());
|
2017-04-04 07:56:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
2017-04-04 15:37:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void currentLineIsEmpty() {
|
|
|
|
history.addLine("one");
|
|
|
|
history.getPreviousLine();
|
|
|
|
|
|
|
|
assertNext("");
|
2017-04-04 07:56:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@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");
|
2017-04-04 15:37:57 -04:00
|
|
|
assertNext("");
|
2017-04-04 07:56:35 -04:00
|
|
|
assertAtEnd();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2017-04-04 15:37:57 -04:00
|
|
|
public void addedLineGoesAtEndOfHistory() {
|
2017-04-04 07:56:35 -04:00
|
|
|
history.addLine("one");
|
|
|
|
history.addLine("two");
|
2017-04-04 15:37:57 -04:00
|
|
|
history.getPreviousLine();
|
|
|
|
history.getPreviousLine();
|
|
|
|
history.addLine("three");
|
2017-04-04 07:56:35 -04:00
|
|
|
|
2017-04-04 15:37:57 -04:00
|
|
|
assertPrevious("three");
|
2017-04-04 07:56:35 -04:00
|
|
|
assertPrevious("two");
|
|
|
|
assertPrevious("one");
|
|
|
|
assertAtBeginning();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2017-04-04 15:37:57 -04:00
|
|
|
public void currentLineIsUpdated() {
|
|
|
|
history.addLine("one");
|
|
|
|
history.updateCurrentLine("purple");
|
|
|
|
history.getPreviousLine();
|
|
|
|
|
|
|
|
assertNext("purple");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void previousLineIsUpdated() {
|
2017-04-04 07:56:35 -04:00
|
|
|
history.addLine("one");
|
|
|
|
history.addLine("two");
|
|
|
|
history.getPreviousLine();
|
2017-04-04 15:37:57 -04:00
|
|
|
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();
|
2017-04-04 07:56:35 -04:00
|
|
|
history.getPreviousLine();
|
|
|
|
|
|
|
|
assertPrevious("one");
|
2017-04-04 15:37:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void goingPastLastLine_KeepsReturningLastLine() {
|
|
|
|
history.updateCurrentLine("current");
|
|
|
|
history.getNextLine();
|
|
|
|
history.getNextLine();
|
|
|
|
history.getNextLine();
|
|
|
|
history.getNextLine();
|
|
|
|
|
|
|
|
assertNext("current");
|
2017-04-04 07:56:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|