Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
todo-list-example
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IT1901
todo-list-example
Commits
c0ef8575
Commit
c0ef8575
authored
Oct 2, 2020
by
Hallvard Trætteberg
Browse files
Options
Downloads
Patches
Plain Diff
Cleaned up test code
parent
4d8863d8
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
todolist/fxui/src/test/java/todolist/ui/TodoListControllerTest.java
+39
-25
39 additions, 25 deletions
...xui/src/test/java/todolist/ui/TodoListControllerTest.java
with
39 additions
and
25 deletions
todolist/fxui/src/test/java/todolist/ui/TodoListControllerTest.java
+
39
−
25
View file @
c0ef8575
...
...
@@ -2,8 +2,9 @@ package todolist.ui;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
import
java.util.Collection
;
import
java.util.Iterator
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeoutException
;
import
java.util.function.Predicate
;
import
javafx.fxml.FXMLLoader
;
import
javafx.scene.Node
;
...
...
@@ -18,6 +19,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.testfx.framework.junit5.ApplicationTest
;
import
org.testfx.util.WaitForAsyncUtils
;
import
todolist.core.TodoItem
;
import
todolist.core.TodoList
;
import
todolist.core.TodoModel
;
...
...
@@ -53,11 +55,6 @@ public class TodoListControllerTest extends ApplicationTest {
assertTrue
(
todoModel
.
iterator
().
hasNext
());
this
.
todoList
=
todoModel
.
iterator
().
next
();
this
.
controller
.
setTodoList
(
this
.
todoList
);
try
{
Thread
.
sleep
(
100
);
}
catch
(
InterruptedException
e
)
{
// ignore
}
// same as in test-todomodel.json
Iterator
<
TodoItem
>
todoItems
=
todoList
.
iterator
();
item1
=
new
TodoItem
().
as
(
todoItems
.
next
());
...
...
@@ -97,9 +94,7 @@ public class TodoListControllerTest extends ApplicationTest {
public
void
testDeleteTodoItem
()
{
// final ListView<TodoItem> todoListView = lookup("#todoItemsView").query();
// todoListView.getSelectionModel().select(1);
TodoItemListCell
todoItemListCell
=
findTodoItemListCell
(
1
);
clickOn
(
todoItemListCell
.
lookup
(
".label"
));
clickOn
(
findTodoItemListCellNode
(
cell
->
true
,
".label"
,
1
));
clickOn
(
"#deleteTodoItemButton"
);
// item2 is removed, only item1 is left
checkTodoListItems
(
item1
);
...
...
@@ -111,8 +106,7 @@ public class TodoListControllerTest extends ApplicationTest {
@Test
public
void
testCheckTodoItemListCell
()
{
TodoItemListCell
todoItemListCell
=
findTodoItemListCell
(
cell
->
!
cell
.
getItem
().
isChecked
());
clickOn
(
todoItemListCell
.
lookup
(
".check-box"
));
clickOn
(
findTodoItemListCellNode
(
cell
->
!
cell
.
getItem
().
isChecked
(),
".check-box"
,
0
));
TodoItem
newItem2
=
item2
.
withChecked
(
true
);
// item is changed
checkTodoListItems
(
item1
,
newItem2
);
...
...
@@ -137,22 +131,42 @@ public class TodoListControllerTest extends ApplicationTest {
return
findTodoItemListCell
(
cell
->
true
,
num
);
}
private
TodoItemListCell
findTodoItemListCell
(
Predicate
<
TodoItemListCell
>
test
)
{
return
findTodoItemListCell
(
test
,
0
);
private
Node
findNode
(
Predicate
<
Node
>
nodeTest
,
int
num
)
{
int
count
=
0
;
for
(
Node
node
:
lookup
(
nodeTest
).
queryAll
())
{
if
(
nodeTest
.
test
(
node
)
&&
count
++
==
num
)
{
return
node
;
}
}
return
null
;
}
private
TodoItemListCell
findTodoItemListCell
(
Predicate
<
TodoItemListCell
>
test
,
int
num
)
{
Collection
<
Node
>
nodes
=
lookup
(
node
->
node
instanceof
TodoItemListCell
).
queryAll
();
// ".list-cell").queryAll();
for
(
Node
node
:
nodes
)
{
if
(
node
instanceof
TodoItemListCell
)
{
TodoItemListCell
todoItemListCell
=
(
TodoItemListCell
)
node
;
if
(
test
.
test
(
todoItemListCell
)
&&
num
--
==
0
)
{
return
todoItemListCell
;
private
Node
waitForNode
(
Predicate
<
Node
>
nodeTest
,
int
num
)
{
Node
[]
nodes
=
new
Node
[
1
];
try
{
WaitForAsyncUtils
.
waitFor
(
500
,
TimeUnit
.
MILLISECONDS
,
()
->
{
while
(
true
)
{
if
((
nodes
[
0
]
=
findNode
(
nodeTest
,
num
))
!=
null
)
{
return
true
;
}
Thread
.
sleep
(
10
);
}
}
fail
(
"Didn't find TodoItemListCell #"
+
num
+
" in "
+
nodes
);
return
null
;
);
}
catch
(
TimeoutException
e
)
{
fail
(
"No appropriate node available"
);
}
return
nodes
[
0
];
}
private
TodoItemListCell
findTodoItemListCell
(
Predicate
<
TodoItemListCell
>
test
,
int
num
)
{
return
(
TodoItemListCell
)
waitForNode
(
node
->
node
instanceof
TodoItemListCell
&&
test
.
test
((
TodoItemListCell
)
node
),
num
);
}
private
Node
findTodoItemListCellNode
(
Predicate
<
TodoItemListCell
>
test
,
String
selector
,
int
num
)
{
Node
listCell
=
waitForNode
(
node
->
node
instanceof
TodoItemListCell
&&
(
selector
==
null
||
node
.
lookup
(
selector
)
!=
null
)
&&
test
.
test
((
TodoItemListCell
)
node
),
num
);
return
listCell
.
lookup
(
selector
);
}
private
void
checkTodoItem
(
TodoItem
item
,
Boolean
checked
,
String
text
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment