Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 408c708

Browse files
committed
Add JavaFXLibraryQueryException
Tests failed when used as a remote library because Querys constructor threw a JavaFXLibraryFatalException and terminated the whole acceptance suite. Constructor now throws a JavaFXLibraryQueryException, which is a subclass of JavaFXLibraryNonFatalException. NonFatalExceptions are used to handle null values in find keywords, so QueryExceptions must be catched before them.
1 parent c5bf3af commit 408c708

File tree

5 files changed

+42
-17
lines changed

5 files changed

+42
-17
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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.exceptions;
19+
20+
public class JavaFXLibraryQueryException extends JavaFXLibraryNonFatalException {
21+
public JavaFXLibraryQueryException() {
22+
super();
23+
}
24+
25+
public JavaFXLibraryQueryException(String message) {
26+
super(message);
27+
}
28+
}

src/main/java/javafxlibrary/keywords/AdditionalKeywords/Find.java

+10-12
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package javafxlibrary.keywords.AdditionalKeywords;
22

33
import javafx.scene.Parent;
4-
import javafxlibrary.exceptions.JavaFXLibraryFatalException;
54
import javafxlibrary.exceptions.JavaFXLibraryNonFatalException;
5+
import javafxlibrary.exceptions.JavaFXLibraryQueryException;
66
import javafxlibrary.utils.finder.Finder;
77
import javafxlibrary.utils.RobotLog;
88
import org.robotframework.javalib.annotation.ArgumentNames;
@@ -46,13 +46,12 @@ public Object find(String query, boolean failIfNotFound, Parent root) {
4646
failIfNotFound + "\", root= \"" + root + "\"");
4747
try {
4848
return mapObject(new Finder().find(query, root));
49-
49+
} catch (JavaFXLibraryQueryException e) {
50+
throw e;
5051
} catch (JavaFXLibraryNonFatalException e) {
5152
if (failIfNotFound)
5253
throw new JavaFXLibraryNonFatalException("Unable to find anything with query: \"" + query + "\"");
5354
return "";
54-
} catch (JavaFXLibraryFatalException e) {
55-
throw e;
5655
} catch (Exception e) {
5756
throw new JavaFXLibraryNonFatalException("Find operation failed for query: \"" + query + "\"", e);
5857
}
@@ -65,13 +64,12 @@ public Object find(String query, boolean failIfNotFound) {
6564
failIfNotFound + "\"");
6665
try {
6766
return mapObject(new Finder().find(query));
68-
69-
} catch (JavaFXLibraryNonFatalException e){
67+
} catch (JavaFXLibraryQueryException e) {
68+
throw e;
69+
} catch (JavaFXLibraryNonFatalException e) {
7070
if (failIfNotFound)
7171
throw new JavaFXLibraryNonFatalException("Unable to find anything with query: \"" + query + "\"");
7272
return "";
73-
} catch (JavaFXLibraryFatalException e) {
74-
throw e;
7573
} catch (Exception e) {
7674
throw new JavaFXLibraryNonFatalException("Find operation failed for query: \"" + query + "\"", e);
7775
}
@@ -94,12 +92,12 @@ public Object find(String query) {
9492
public List<Object> findAll(String query, boolean failIfNotFound, Parent root) {
9593
try {
9694
return mapObjects(new Finder().findAll(query, root));
95+
} catch (JavaFXLibraryQueryException e) {
96+
throw e;
9797
} catch (JavaFXLibraryNonFatalException e) {
9898
if (failIfNotFound)
9999
throw new JavaFXLibraryNonFatalException("Unable to find anything with query: \"" + query + "\"");
100100
return new ArrayList<>();
101-
} catch (JavaFXLibraryFatalException e) {
102-
throw e;
103101
} catch (Exception e) {
104102
throw new JavaFXLibraryNonFatalException("Find operation failed for query: \"" + query + "\"", e);
105103
}
@@ -110,12 +108,12 @@ public List<Object> findAll(String query, boolean failIfNotFound, Parent root) {
110108
public List<Object> findAll(String query, boolean failIfNotFound) {
111109
try {
112110
return mapObjects(new Finder().findAll(query));
111+
} catch (JavaFXLibraryQueryException e) {
112+
throw e;
113113
} catch (JavaFXLibraryNonFatalException e) {
114114
if (failIfNotFound)
115115
throw new JavaFXLibraryNonFatalException("Unable to find anything with query: \"" + query + "\"");
116116
return new ArrayList<>();
117-
} catch (JavaFXLibraryFatalException e) {
118-
throw e;
119117
} catch (Exception e) {
120118
throw new JavaFXLibraryNonFatalException("Find operation failed for query: \"" + query + "\"", e);
121119
}

src/main/java/javafxlibrary/utils/finder/FindOperation.java

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import javafx.scene.Parent;
2424
import javafxlibrary.exceptions.JavaFXLibraryNonFatalException;
2525
import javafxlibrary.matchers.InstanceOfMatcher;
26-
import javafxlibrary.utils.RobotLog;
2726
import javafxlibrary.utils.TestFxAdapter;
2827
import org.testfx.api.FxRobotInterface;
2928
import org.testfx.matcher.control.LabeledMatchers;

src/main/java/javafxlibrary/utils/finder/Query.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
package javafxlibrary.utils.finder;
1919

20-
import javafxlibrary.exceptions.JavaFXLibraryFatalException;
20+
import javafxlibrary.exceptions.JavaFXLibraryQueryException;
2121

2222
public class Query {
2323

@@ -31,7 +31,7 @@ public Query(String query) {
3131
if (this.prefix != FindPrefix.XPATH && QueryParser.containsIndex(query)) {
3232
this.index = QueryParser.getQueryIndex(query);
3333
if (this.index < 0) {
34-
throw new JavaFXLibraryFatalException("Invalid query \"" + query + "\": Minimum index value is 1!");
34+
throw new JavaFXLibraryQueryException("Invalid query \"" + query + "\": Minimum index value is 1!");
3535
}
3636
query = QueryParser.removeQueryIndex(query);
3737
}

src/test/java/javafxlibrary/utils/finder/QueryTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package javafxlibrary.utils.finder;
22

3-
import javafxlibrary.exceptions.JavaFXLibraryFatalException;
3+
import javafxlibrary.exceptions.JavaFXLibraryQueryException;
44
import org.junit.Assert;
55
import org.junit.Rule;
66
import org.junit.Test;
@@ -31,7 +31,7 @@ public void validQuery_noIndex() {
3131

3232
@Test
3333
public void invalidQueryIndex() {
34-
thrown.expect(JavaFXLibraryFatalException.class);
34+
thrown.expect(JavaFXLibraryQueryException.class);
3535
thrown.expectMessage("Invalid query \"css=VBox[0]\": Minimum index value is 1!");
3636
new Query("css=VBox[0]");
3737
}

0 commit comments

Comments
 (0)