Skip to content

Commit 1abb22d

Browse files
committed
Rearrange ConvenienceKeyword unit tests
- Changed test directory structure to keywords/AdditionalKeywordsTests/ConvenienceKeywords - Renamed ConvenienceKeywordsTest to DeprecatedFindKeywordsTest - Added unit tests for waitForEventsInFxApplicationThread
1 parent dfa3455 commit 1abb22d

File tree

2 files changed

+86
-17
lines changed

2 files changed

+86
-17
lines changed

src/test/java/javafxlibrary/keywords/AdditionalKeywords/ConvenienceKeywordsTest.java renamed to src/test/java/javafxlibrary/keywords/AdditionalKeywordsTests/ConvenienceKeywords/DeprecatedFindKeywordsTest.java

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,36 @@
1515
* limitations under the License.
1616
*/
1717

18-
package javafxlibrary.keywords.AdditionalKeywords;
18+
package javafxlibrary.keywords.AdditionalKeywordsTests.ConvenienceKeywords;
1919

2020
import java.util.List;
2121
import com.google.common.collect.ImmutableSet;
2222
import javafx.css.PseudoClass;
2323
import javafx.scene.control.Button;
2424
import javafxlibrary.TestFxAdapterTest;
25-
import javafxlibrary.exceptions.JavaFXLibraryNonFatalException;
25+
import javafxlibrary.keywords.AdditionalKeywords.ConvenienceKeywords;
2626
import javafxlibrary.utils.HelperFunctions;
2727
import mockit.Expectations;
2828
import mockit.Mocked;
2929
import org.junit.Assert;
3030
import org.junit.Before;
31+
import org.junit.BeforeClass;
3132
import org.junit.Test;
3233
import org.testfx.service.query.NodeQuery;
3334

34-
public class ConvenienceKeywordsTest extends TestFxAdapterTest {
35+
public class DeprecatedFindKeywordsTest extends TestFxAdapterTest {
3536

3637
@Mocked
3738
NodeQuery rootQuery;
3839

3940
private Button button;
4041
private Button button2;
41-
private ConvenienceKeywords keywords = new ConvenienceKeywords();
42+
private static ConvenienceKeywords keywords;
43+
44+
@BeforeClass
45+
public static void setupAllTests() {
46+
keywords = new ConvenienceKeywords();
47+
}
4248

4349
@Before
4450
public void setup() {
@@ -57,20 +63,15 @@ public void setup() {
5763
@Test
5864
public void findAllWithPseudoClass() {
5965
expectTwoButtonsFromNodeQuery();
60-
6166
List<Object> allWithPseudoClass = keywords.findAllWithPseudoClass("rootId", "selected");
6267
Assert.assertEquals(HelperFunctions.mapObject(button), allWithPseudoClass.get(0));
6368
}
6469

6570
@Test
6671
public void findNoPseudoClasses() {
6772
expectTwoButtonsFromNodeQuery();
68-
try {
69-
List<Object> hits = keywords.findAllWithPseudoClass("rootId", "something");
70-
Assert.assertEquals(0, hits.size());
71-
} catch (JavaFXLibraryNonFatalException e) {
72-
73-
}
73+
List<Object> hits = keywords.findAllWithPseudoClass("rootId", "something");
74+
Assert.assertEquals(0, hits.size());
7475
}
7576

7677
@Test
@@ -81,12 +82,8 @@ public void findNoNodes() {
8182
result = ImmutableSet.of();
8283
}
8384
};
84-
try {
85-
List<Object> hits = keywords.findAllWithPseudoClass("rootId", "something");
86-
Assert.assertEquals(0, hits.size());
87-
} catch (JavaFXLibraryNonFatalException e) {
88-
89-
}
85+
List<Object> hits = keywords.findAllWithPseudoClass("rootId", "something");
86+
Assert.assertEquals(0, hits.size());
9087
}
9188

9289
private void expectTwoButtonsFromNodeQuery() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Copyright 2017-2018 Eficode Oy
3+
* Copyright 2018- Robot Framework Foundation
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package javafxlibrary.keywords.AdditionalKeywordsTests.ConvenienceKeywords;
19+
20+
import javafx.application.Platform;
21+
import javafx.scene.control.Button;
22+
import javafxlibrary.TestFxAdapterTest;
23+
import javafxlibrary.exceptions.JavaFXLibraryNonFatalException;
24+
import javafxlibrary.keywords.AdditionalKeywords.ConvenienceKeywords;
25+
import org.junit.Assert;
26+
import org.junit.BeforeClass;
27+
import org.junit.Rule;
28+
import org.junit.Test;
29+
import org.junit.rules.ExpectedException;
30+
31+
public class WaitForEventsInFxApplicationThreadTest extends TestFxAdapterTest {
32+
33+
@Rule
34+
public ExpectedException thrown = ExpectedException.none();
35+
36+
private static ConvenienceKeywords keywords;
37+
38+
@BeforeClass
39+
public static void setupTests() {
40+
keywords = new ConvenienceKeywords();
41+
}
42+
43+
@Test
44+
public void waitForEventsInFxApplicationThread() {
45+
Button b = createDelayedButton(2000);
46+
Platform.runLater(() -> b.fire());
47+
keywords.waitForEventsInFxApplicationThread(2);
48+
Assert.assertEquals("ChangedText", b.getText());
49+
}
50+
51+
@Test
52+
public void waitForEventsInFxApplicationThread_TimeoutExceeded() {
53+
thrown.expect(JavaFXLibraryNonFatalException.class);
54+
thrown.expectMessage("Events did not finish within the given timeout of 1 seconds.");
55+
Button b = createDelayedButton(3000);
56+
Platform.runLater(() -> b.fire());
57+
keywords.waitForEventsInFxApplicationThread(1);
58+
}
59+
60+
private Button createDelayedButton(int timeout) {
61+
Button b = new Button("OriginalText");
62+
b.setOnAction((e) -> {
63+
try {
64+
Thread.sleep(timeout);
65+
b.setText("ChangedText");
66+
} catch (InterruptedException ie) {
67+
ie.printStackTrace();
68+
}
69+
});
70+
return b;
71+
}
72+
}

0 commit comments

Comments
 (0)