2016-12-10 12:00:32 -05:00
|
|
|
package file;
|
2016-12-10 11:57:49 -05:00
|
|
|
|
|
|
|
import static org.junit.Assert.assertFalse;
|
|
|
|
import static org.junit.Assert.assertTrue;
|
|
|
|
|
|
|
|
import org.junit.Before;
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
public class FilePositionTrackerTester {
|
|
|
|
|
|
|
|
public static final String FILE_NAME = "testFileName";
|
|
|
|
|
|
|
|
private FilePositionTracker trackerUnderTest;
|
|
|
|
|
|
|
|
@Before
|
|
|
|
public void setUp() throws Exception {
|
|
|
|
trackerUnderTest = new FilePositionTracker(FILE_NAME);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void filePositionEquality_CorrectlyReturnsTrue() {
|
2016-12-11 10:12:59 -05:00
|
|
|
FilePosition positionOne = createFilePosition(5, 9);
|
|
|
|
FilePosition positionTwo = createFilePosition(5, 9);
|
2016-12-10 11:57:49 -05:00
|
|
|
|
|
|
|
assertTrue(positionOne.isEqual(positionTwo));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void filePositionEquality_CorrectlyReturnsFalseWithDifferentLine() {
|
2016-12-11 10:12:59 -05:00
|
|
|
FilePosition positionOne = createFilePosition(5, 9);
|
|
|
|
FilePosition positionTwo = createFilePosition(8, 9);
|
2016-12-10 11:57:49 -05:00
|
|
|
|
|
|
|
assertFalse(positionOne.isEqual(positionTwo));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void filePositionEquality_CorrectlyReturnsFalseWithDifferentColumn() {
|
2016-12-11 10:12:59 -05:00
|
|
|
FilePosition positionOne = createFilePosition(5, 9);
|
|
|
|
FilePosition positionTwo = createFilePosition(5, 10);
|
2016-12-10 11:57:49 -05:00
|
|
|
|
|
|
|
assertFalse(positionOne.isEqual(positionTwo));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void filePositionEquality_CorrectlyReturnsFalseWithDifferentFileName() {
|
|
|
|
FilePosition positionOne = new FilePosition("FileOne");
|
|
|
|
positionOne.setLineNumber(5);
|
|
|
|
positionOne.setColumnNumber(9);
|
|
|
|
|
|
|
|
FilePosition positionTwo = new FilePosition("FileTwo");
|
|
|
|
positionTwo.setLineNumber(5);
|
|
|
|
positionTwo.setColumnNumber(9);
|
|
|
|
|
|
|
|
assertFalse(positionOne.isEqual(positionTwo));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void noMovement_ReturnsInitialPosition() {
|
2016-12-11 10:12:59 -05:00
|
|
|
FilePosition expectedPosition = createFilePosition(1, 0);
|
2016-12-10 11:57:49 -05:00
|
|
|
|
|
|
|
assertTrue(expectedPosition.isEqual(trackerUnderTest.getCurrentPosition()));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void advanceOneColumn_ReturnsCorrectPosition() {
|
2016-12-11 10:12:59 -05:00
|
|
|
FilePosition expectedPosition = createFilePosition(1, 1);
|
2016-12-10 11:57:49 -05:00
|
|
|
|
|
|
|
trackerUnderTest.incrementColumn();
|
|
|
|
|
|
|
|
assertTrue(expectedPosition.isEqual(trackerUnderTest.getCurrentPosition()));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void advanceOneLine_ReturnsCorrectPosition() {
|
2016-12-11 10:12:59 -05:00
|
|
|
FilePosition expectedPosition = createFilePosition(2, 0);
|
2016-12-10 11:57:49 -05:00
|
|
|
|
|
|
|
trackerUnderTest.incrementLine();
|
|
|
|
|
|
|
|
assertTrue(expectedPosition.isEqual(trackerUnderTest.getCurrentPosition()));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void advanceOneLine_ResetsColumn() {
|
2016-12-11 10:12:59 -05:00
|
|
|
FilePosition expectedPosition = createFilePosition(2, 0);
|
2016-12-10 11:57:49 -05:00
|
|
|
|
|
|
|
trackerUnderTest.incrementColumn();
|
|
|
|
trackerUnderTest.incrementLine();
|
|
|
|
|
|
|
|
assertTrue(expectedPosition.isEqual(trackerUnderTest.getCurrentPosition()));
|
|
|
|
}
|
|
|
|
|
2016-12-11 10:12:59 -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-10 11:57:49 -05:00
|
|
|
}
|