Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(feat) TableViewMatchers: Add containsRow(). #255

Merged
merged 1 commit into from Mar 15, 2016

Conversation

brcolow
Copy link
Collaborator

@brcolow brcolow commented Mar 14, 2016

This allows for testing that a TableView contains a given row at
a given row index. As an example, consider a Person class that has
three properties, name (StringProperty), age (IntegerProperty) and
birth-date (ObjectProperty):

TableView<Person> peopleTable = new TableView<>();
Person bob = new Person("Bob", 42, Instant.ofEpochSecond(139061613));
Person andy = new Person("Andy", 13, Instant.ofEpochSecond(1061260323));
Person jill = new Person("Jill", 5, Instant.ofEpochSecond(1320430636));
ObservableList<Person> people = FXCollections.observableArrayList(bob, andy, jill);

peopleTable.setItems(people);

// then:

assertThat(peopleTable, containsRow(0, "Bob", 42, Instant.parse("1974-05-29T12:13:33+00:00Z")));
assertThat(peopleTable, containsRow(1, "Andy" 13, Instant.parse("2003-08-19T02:32:03+00:00Z")));
assertThat(peopleTable, containsRow(2, "Jill", 5, Instant.parse("2011-11-04T18:17:16+00:00Z")));

// would all be true

This allows for testing that a TableView contains a given row at
a given row index. As an example, consider a Person class that has
three properties, name (StringProperty), age (IntegerProperty) and
birth-date (ObjectProperty<Instant>):

TableView<Person> peopleTable = new TableView<>();
Person bob = new Person("Bob", 42, Instant.ofEpochSecond(139061613));
Person andy = new Person("Andy", 13, Instant.ofEpochSecond(1061260323));
Person jill = new Person("Jill", 5, Instant.ofEpochSecond(1320430636));
ObservableList<Person> people = FXCollections.observableArrayList(
    bob, andy, jill);

peopleTable.setItems(people);

// then:

assertThat(peopleTable, containsRow(0, "Bob", 42,
Instant.parse("1974-05-29T12:13:33+00:00Z")));
assertThat(peopleTable, containsRow(1, "Andy" 13,
Instant.parse("2003-08-19T02:32:03+00:00Z")));
assertThat(peopleTable, containsRow(2, "Jill", 5,
Instant.parse("2011-11-04T18:17:16+00:00Z")));

// would all be true
@hastebrot
Copy link
Member

An alternative could be

assertThat(from(peopleTable).lookupTableRow(0), 
    hasItems("Bob", 42, Instant.parse("1974-05-29T12:13:33+00:00Z")));

@brcolow
Copy link
Collaborator Author

brcolow commented Mar 14, 2016

Hmmm..I played around trying to implement your suggestion but I am having serious troubles....essentially my problem is that I am not sure how to get the looked up row index from the new hasItems(...) method. To be honest, I am not sure I know how to implement your suggestion. Furthermore I am not sure it really is an improvement over the current approach. Maybe it would be an improvement to name the function: nthRowContains(int n, Object...items)? But to be frank I am in favor of the way it currently is - you let me know how you want to proceed.

@hastebrot
Copy link
Member

So let's merge this. We have tests and can refactor the method later, if this is needed.

My idea was,

  • to implement lookupTableRow(rowIndex) for NodeQuery which queries a javafx.scene.control.TableRow,
  • to let hasItems() accept the TableRow, fetch the cells and compare them with the Object... array.

Another note: hasItems(...) could clash with the meaning of TableView::getItems(); both sound similar. Ah, it's named containsRow().

@brcolow
Copy link
Collaborator Author

brcolow commented Mar 14, 2016

I think merging is the best way forward, maybe with a note on the commit itself or just your note above for history's sake :)

@hastebrot hastebrot changed the title Add containsRow(...) to TableViewMatchers. (feat) TableViewMatchers: Add containsRow(). Mar 15, 2016
hastebrot added a commit that referenced this pull request Mar 15, 2016
(feat) TableViewMatchers: Add containsRow().
@hastebrot hastebrot merged commit af5ec6c into TestFX:master Mar 15, 2016
@brcolow brcolow deleted the table-row-matcher branch March 15, 2016 23:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants