transcendental-lisp/test/file/FilePositionTrackerTester.java

66 lines
1.9 KiB
Java
Raw Normal View History

package file;
import static org.junit.Assert.assertTrue;
import java.util.Objects;
2017-02-06 13:44:35 -05:00
import org.junit.*;
public class FilePositionTrackerTester {
2016-12-12 14:57:34 -05:00
public static final String FILE_NAME = "testFile";
private FilePositionTracker trackerUnderTest;
2016-12-12 14:57:34 -05:00
private FilePosition createFilePosition(int lineNumber, int columnNumber) {
FilePosition position = new FilePosition(FILE_NAME);
position.setLineNumber(lineNumber);
position.setColumnNumber(columnNumber);
return position;
}
private void assertTrackerPositionEquals(FilePosition expectedPosition) {
assertTrue(arePositionsEqual(expectedPosition, trackerUnderTest.getCurrentPosition()));
}
private boolean arePositionsEqual(FilePosition position1, FilePosition position2) {
return Objects.equals(position1.getFileName(), position2.getFileName())
&& Objects.equals(position1.getLineNumber(), position2.getLineNumber())
&& Objects.equals(position1.getColumnNumber(), position2.getColumnNumber());
}
@Before
public void setUp() throws Exception {
trackerUnderTest = new FilePositionTracker(FILE_NAME);
}
@Test
public void noMovement_ReturnsInitialPosition() {
assertTrackerPositionEquals(createFilePosition(1, 0));
}
@Test
public void advanceOneColumn_ReturnsCorrectPosition() {
trackerUnderTest.incrementColumn();
assertTrackerPositionEquals(createFilePosition(1, 1));
}
@Test
public void advanceOneLine_ReturnsCorrectPosition() {
trackerUnderTest.incrementLine();
assertTrackerPositionEquals(createFilePosition(2, 0));
}
@Test
public void advanceOneLine_ResetsColumn() {
trackerUnderTest.incrementColumn();
trackerUnderTest.incrementLine();
assertTrackerPositionEquals(createFilePosition(2, 0));
}
}