Skip to content
Permalink
Browse files

Improved README tests; minor trim fix in Table.parse(..)

  • Loading branch information...
terzerm committed Apr 3, 2017
1 parent 5c4f8e1 commit a5b59c59a27e2ab02790cb984c9bfdc5b02ccb36
@@ -13,51 +13,44 @@ public class UnrollMethodDataTest {
@Test
@Spockito.Unroll({
"| Name |",
"| Test 1 |",
"| Test 2 |"
"| Last Name | First Name |",
"| Jones | David |",
"| Jensen | Astrid |"
})
public void testUnrollSimple(final String name) {
Assert.assertNotNull("name should not be null", name);
Assert.assertTrue("name should start with Test", name.startsWith("Test "));
public void testUnrollNames(String lastName, String firstName) {
Assert.assertTrue("Last Name should start with J", lastName.startsWith("J"));
Assert.assertTrue("First Name should end with id", firstName.endsWith("id"));
}
@Test
@Spockito.Unroll({
"| Index | Name |",
"|-------|----------|",
"| 1 | Test 1 |",
"| 2 | Test 2 |"
"| Name | Year | Birthday |",
"|-------|------|------------|",
"| Henry | 1981 | 1981-11-28 |",
"| Jessy | 1965 | 1965-03-28 |"
})
@Spockito.Name("[{row}]: index={0}, name={1}")
public void testUnrollTwoColumns(int index, String name) {
Assert.assertTrue("index should be greater than 0", index > 0);
Assert.assertNotNull("name should be TestName", name);
Assert.assertTrue("name should start with Test", name.startsWith("Test "));
@Spockito.Name("[{row}]: Name={0}")
public void testUnrollBirthdays(String name, int year, LocalDate birthday) {
Assert.assertEquals("Name should have 5 characters", 5, name.length());
Assert.assertTrue("Year is before 1990", 1990 > year);
Assert.assertEquals("Day is 28th", 28, birthday.getDayOfMonth());
}
@Test
@Spockito.Unroll({
"| Index | TestName |",
"|=======|==========|",
"| 1 | Test 1 |",
"|------ |----------|",
"| 2 | Test 2 |",
"|------ |----------|",
"| 3 | Test 3 |",
"|------ |----------|",
"| 4 | Test 4 |",
"|------ |----------|",
"| Object | Vertices | Angle sum |",
"|==========|==========|===========|",
"| Triangle | 3 | 180 |",
"| Square | 4 | 360 |",
"| Pentagon | 5 | 540 |",
"|----------|----------|-----------|",
})
@Spockito.Name("[{row}]: index={Index}, name={TestName}")
public void testUnrollWithColumnRefs(@Spockito.Ref("TestName") String name,
@Spockito.Ref("Index") int index,
@Spockito.Ref("row") int row) {
Assert.assertTrue("index should be greater than 0", index > 0);
Assert.assertTrue("row should be greated or equal to 0", row >= 0);
Assert.assertTrue("index should be row + 1", index == row + 1);
Assert.assertNotNull("name should be TestName", name);
Assert.assertTrue("name should start with Test", name.startsWith("Test "));
@Spockito.Name("[{Object}]: ({Vertices}-2)*180 = {Angle sum}")
public void testUnrollAngularSums(@Spockito.Ref("Vertices") int n,
@Spockito.Ref("Angle sum") int degrees,
@Spockito.Ref("Object") String name) {
Assert.assertTrue("There should be 3 or more vertices", 3 <= n);
Assert.assertEquals("Angular sum of is wrong for: " + name, degrees, (n-2)*180);
}
}
```
BIN -8.67 KB (89%) ide-run-SpockitoTest.png
Binary file not shown.
@@ -116,7 +116,7 @@ private static TableRow parseRow(final Table table, final int row, final String
if (trimmed.length() < 2 || trimmed.charAt(0) != '|' || trimmed.charAt(trimmed.length() - 1) != '|') {
throw new IllegalArgumentException("Invalid table data: row " + row + " must start and end with '|'");
}
final TableRow tableRow = TableRow.parse(table, rowString);
final TableRow tableRow = TableRow.parse(table, trimmed);
if (row != 0) {
if (tableRow.size() > table.getColumnCount()) {
throw new IllegalArgumentException("Invalid table data: row " + row + " has more columns than header row: " + tableRow.size() + " > " + table.getColumnCount());
@@ -40,9 +40,9 @@
private static final List<String> EXPECTED_TESTS = Arrays.asList(
"oneMore",
"oneMoreUnroll[0]", "oneMoreUnroll[1]",
"testUnrollSimple[0]", "testUnrollSimple[1]",
"testUnrollTwoColumns[0]", "testUnrollTwoColumns[1]",
"testUnrollWithColumnRefs[0]", "testUnrollWithColumnRefs[1]", "testUnrollWithColumnRefs[2]", "testUnrollWithColumnRefs[3]"
"testUnrollAngularSums[Pentagon]", "testUnrollAngularSums[Square]", "testUnrollAngularSums[Triangle]",
"testUnrollBirthdays[0]", "testUnrollBirthdays[1]",
"testUnrollNames[0]", "testUnrollNames[1]"
);

@Rule
@@ -27,55 +27,50 @@
import org.junit.Test;
import org.junit.runner.RunWith;

import java.time.LocalDate;

@RunWith(Spockito.class)
public class UnrollMethodDataTest {

@Test
@Spockito.Unroll({
"| Name |",
"| Test 1 |",
"| Test 2 |"
"| Last Name | First Name |",
"| Jones | David |",
"| Jensen | Astrid |"
})
public void testUnrollSimple(final String name) {
Assert.assertNotNull("name should not be null", name);
Assert.assertTrue("name should start with Test", name.startsWith("Test "));
public void testUnrollNames(String lastName, String firstName) {
Assert.assertTrue("Last Name should start with J", lastName.startsWith("J"));
Assert.assertTrue("First Name should end with id", firstName.endsWith("id"));
}

@Test
@Spockito.Unroll({
"| Index | Name |",
"|-------|----------|",
"| 1 | Test 1 |",
"| 2 | Test 2 |"
"| Name | Year | Birthday |",
"|-------|------|------------|",
"| Henry | 1981 | 1981-11-28 |",
"| Jessy | 1965 | 1965-03-28 |"
})
@Spockito.Name("[{row}]: index={0}, name={1}")
public void testUnrollTwoColumns(int index, String name) {
Assert.assertTrue("index should be greater than 0", index > 0);
Assert.assertNotNull("name should be TestName", name);
Assert.assertTrue("name should start with Test", name.startsWith("Test "));
@Spockito.Name("[{row}]: Name={0}")
public void testUnrollBirthdays(String name, int year, LocalDate birthday) {
Assert.assertEquals("Name should have 5 characters", 5, name.length());
Assert.assertTrue("Year is before 1990", 1990 > year);
Assert.assertEquals("Day is 28th", 28, birthday.getDayOfMonth());
}

@Test
@Spockito.Unroll({
"| Index | TestName |",
"|=======|==========|",
"| 1 | Test 1 |",
"|------ |----------|",
"| 2 | Test 2 |",
"|------ |----------|",
"| 3 | Test 3 |",
"|------ |----------|",
"| 4 | Test 4 |",
"|------ |----------|",
"| Object | Vertices | Angle sum |",
"|==========|==========|===========|",
"| Triangle | 3 | 180 |",
"| Square | 4 | 360 |",
"| Pentagon | 5 | 540 |",
"|----------|----------|-----------|",
})
@Spockito.Name("[{row}]: index={Index}, name={TestName}")
public void testUnrollWithColumnRefs(@Spockito.Ref("TestName") String name,
@Spockito.Ref("Index") int index,
@Spockito.Ref("row") int row) {
Assert.assertTrue("index should be greater than 0", index > 0);
Assert.assertTrue("row should be greated or equal to 0", row >= 0);
Assert.assertTrue("index should be row + 1", index == row + 1);
Assert.assertNotNull("name should be TestName", name);
Assert.assertTrue("name should start with Test", name.startsWith("Test "));
@Spockito.Name("[{Object}]: ({Vertices}-2)*180 = {Angle sum}")
public void testUnrollAngularSums(@Spockito.Ref("Vertices") int n,
@Spockito.Ref("Angle sum") int degrees,
@Spockito.Ref("Object") String name) {
Assert.assertTrue("There should be 3 or more vertices", 3 <= n);
Assert.assertEquals("Angular sum of is wrong for: " + name, degrees, (n-2)*180);
}
}

0 comments on commit a5b59c5

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.