All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
fit.decorator.util.TableTest Maven / Gradle / Ivy
Go to download
The fully integrated standalone wiki, and acceptance testing framework.
package fit.decorator.util;
import static org.junit.Assert.assertEquals;
import fit.Parse;
import fit.decorator.exceptions.InvalidInputException;
import org.junit.Before;
import org.junit.Test;
public class TableTest {
private String fitPage = "eg.Division "
+ "numerator denominator quotient() "
+ "10 2 5
";
private Table table;
@Before
public void setUp() throws Exception {
table = new Table(fitPage);
}
@Test
public void testToStringShouldParseTableWithMultipleRowsAndColumns() throws Exception {
assertTable(fitPage);
}
@Test
public void testConstructorShouldBuildTableFromParseObject() throws Exception {
String expectedTableContents = "fit.decorator.MaxTime 10 ";
Parse parse = new Parse(expectedTableContents, new String[]
{"tr", "td"});
table = new Table(parse);
assertTable(expectedTableContents);
}
@Test
public void testCopyAndAppendLastRow() throws Exception {
table.copyAndAppendLastRow(1);
String expectedTableContents = "eg.Division "
+ "numerator denominator quotient() "
+ "10 2 5 " + "10 2 5
";
assertTable(expectedTableContents);
}
@Test
public void testCopyAndAppendLastRowMultipleTimes() throws Exception {
table.copyAndAppendLastRow(3);
String expectedTableContents = "eg.Division "
+ "numerator denominator quotient() "
+ "10 2 5 10 2 5 "
+ "10 2 5 " + "10 2 5
";
assertTable(expectedTableContents);
}
@Test
public void testCopyAndAppendLastRowZeroTime() throws Exception {
table.copyAndAppendLastRow(0);
assertTable(fitPage);
}
@Test
public void testIncrementColumnValueThrowsInvalidInputExceptionIfColumnNameIsNotFound() throws Exception {
try {
table.incrementColumnValues(1, "invalidColumnName", null);
} catch (InvalidInputException e) {
assertEquals("'invalidColumnName' was not found in the table " + fitPage, e.getMessage());
}
}
@Test
public void testIncrementColumnValueShouldAddTheGivenDeltaToAllRowsOfTheGivenColumn() throws Exception {
table.incrementColumnValues("denominator", new Delta("int", "1"), 1);
assertTable(fitPage);
}
@Test
public void testIncrementColumnValueShouldIncrementallyAddTheGivenDeltaMultipleTimes() throws Exception {
table.incrementColumnValues(3, "denominator", new Delta("int", "1"));
String expectedFitPage = "eg.Division "
+ "numerator denominator quotient() "
+ "10 2 5 10 3 5 "
+ "10 4 5
";
assertTable(expectedFitPage);
}
@Test
public void testInsertAsFirstRow() throws Exception {
Parse firstRow = new Parse("first row ", new String[]
{"tr", "td"});
table.insertAsFirstRow(firstRow);
String expectedTableContents = "first row eg.Division "
+ "numerator denominator quotient() "
+ "10 2 5
";
assertTable(expectedTableContents);
}
@Test
public void testStripFirstRow() throws Exception {
table.stripFirstRow();
String expectedTableContents = "" + "numerator denominator quotient() "
+ "10 2 5
";
assertTable(expectedTableContents);
}
@Test
public void testColumnNumberShouldReturnColumnNumberForTheGivenColumnName() throws Exception {
assertEquals(0, table.columnNumberContainingText("numerator", 1));
assertEquals(1, table.columnNumberContainingText("denominator", 1));
assertEquals(2, table.columnNumberContainingText("quotient()", 1));
}
@Test
public void testColumnNumberShouldThrowsInvalidInputExceptionIfColumnNameIsNotFound() throws Exception {
try {
table.columnNumberContainingText("invalidColumnName", 1);
} catch (InvalidInputException e) {
assertEquals("'invalidColumnName' was not found in the table " + fitPage, e.getMessage());
}
}
@Test
public void testColumnValueShouldReturnColumnValueForTheGivenColumnNumber() throws Exception {
assertEquals("10", table.columnValue(2, 0));
assertEquals("2", table.columnValue(2, 1));
assertEquals("5", table.columnValue(2, 2));
}
@Test
public void testGetLastRow() throws Exception {
Parse lastRow = table.lastRow();
String expectedLastRow = "10 2 5 ";
assertParseObject(expectedLastRow, lastRow);
}
@Test
public void testGetSecondLastRow() throws Exception {
String fitPage = "eg.Division "
+ "numerator denominator quotient() "
+ "10 2 5 " + "5 1 5
";
table = new Table(fitPage);
Parse secondLastRow = table.secondLastRow(table.lastRow());
String expectedSecondLastRow = "10 2 5 ";
assertParseObject(expectedSecondLastRow, secondLastRow);
}
@Test
public void testRowNumberContainingTextShouldReturnIndexOfTheRowContainingTheText() throws Exception {
assertEquals(0, table.rowNumberContainingText("eg.Division"));
assertEquals(1, table.rowNumberContainingText("numerator"));
assertEquals(1, table.rowNumberContainingText("denominator"));
}
@Test
public void testRowNumberContainingTextShouldThrowInvalidInputExceptionIfSearchTextIsNotFound() throws Exception {
try {
table.rowNumberContainingText("invalidColumnName");
} catch (InvalidInputException e) {
assertEquals("'invalidColumnName' was not found in the table " + fitPage, e.getMessage());
}
}
@Test
public void testCopyAndAppendLastRowShouldLeaveTheTableAsItIsIfTotalRowsAreLessThanThree() throws Exception {
String fitPage = "eg.Division "
+ "numerator denominator quotient()
";
table = new Table(fitPage);
table.copyAndAppendLastRow(4);
assertTable(fitPage);
}
private void assertTable(String expectedTableContents) {
assertEquals(expectedTableContents, table.toString());
}
private void assertParseObject(String expectedTableContents, Parse parse) {
assertEquals(expectedTableContents, new Table(parse).toString());
}
}