2016-12-10 12:00:32 -05:00
|
|
|
package file;
|
2016-12-10 11:57:49 -05:00
|
|
|
|
|
|
|
import static org.junit.Assert.assertTrue;
|
|
|
|
|
2016-12-15 11:19:03 -05:00
|
|
|
import java.util.Objects;
|
|
|
|
|
2017-02-06 13:44:35 -05:00
|
|
|
import org.junit.*;
|
2016-12-10 11:57:49 -05:00
|
|
|
|
|
|
|
public class FilePositionTrackerTester {
|
|
|
|
|
2016-12-12 14:57:34 -05:00
|
|
|
public static final String FILE_NAME = "testFile";
|
2016-12-10 11:57:49 -05:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-12-15 11:19:03 -05:00
|
|
|
private void assertTrackerPositionEquals(FilePosition expectedPosition) {
|
|
|
|
assertTrue(arePositionsEqual(expectedPosition, trackerUnderTest.getCurrentPosition()));
|
2016-12-10 11:57:49 -05:00
|
|
|
}
|
|
|
|
|
2016-12-15 11:19:03 -05:00
|
|
|
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());
|
2016-12-10 11:57:49 -05:00
|
|
|
}
|
|
|
|
|
2016-12-15 11:19:03 -05:00
|
|
|
@Before
|
|
|
|
public void setUp() throws Exception {
|
|
|
|
trackerUnderTest = new FilePositionTracker(FILE_NAME);
|
2016-12-10 11:57:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void noMovement_ReturnsInitialPosition() {
|
2016-12-15 11:19:03 -05:00
|
|
|
assertTrackerPositionEquals(createFilePosition(1, 0));
|
2016-12-10 11:57:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void advanceOneColumn_ReturnsCorrectPosition() {
|
|
|
|
trackerUnderTest.incrementColumn();
|
|
|
|
|
2016-12-15 11:19:03 -05:00
|
|
|
assertTrackerPositionEquals(createFilePosition(1, 1));
|
2016-12-10 11:57:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void advanceOneLine_ReturnsCorrectPosition() {
|
|
|
|
trackerUnderTest.incrementLine();
|
|
|
|
|
2016-12-15 11:19:03 -05:00
|
|
|
assertTrackerPositionEquals(createFilePosition(2, 0));
|
2016-12-10 11:57:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void advanceOneLine_ResetsColumn() {
|
|
|
|
trackerUnderTest.incrementColumn();
|
|
|
|
trackerUnderTest.incrementLine();
|
|
|
|
|
2016-12-15 11:19:03 -05:00
|
|
|
assertTrackerPositionEquals(createFilePosition(2, 0));
|
2016-12-10 11:57:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|