WindowMatchers.java
01 /*
02  * Copyright 2008-2016 the original author or authors.
03  *
04  * Licensed under the Apache License, Version 2.0 (the "License");
05  * you may not use this file except in compliance with the License.
06  * You may obtain a copy of the License at
07  *
08  *     http://www.apache.org/licenses/LICENSE-2.0
09  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package griffon.javafx.test;
17 
18 import com.google.common.base.Predicate;
19 import javafx.stage.Window;
20 import org.hamcrest.Factory;
21 import org.hamcrest.Matcher;
22 
23 import javax.annotation.Nullable;
24 
25 import static org.testfx.matcher.base.GeneralMatchers.baseMatcher;
26 
27 /**
28  * TestFX matchers for {@code javafx.stage.Window}.
29  *
30  @author Andres Almiray
31  @since 2.6.0
32  */
33 public class WindowMatchers {
34     //---------------------------------------------------------------------------------------------
35     // STATIC METHODS.
36     //---------------------------------------------------------------------------------------------
37 
38     @Factory
39     public static Matcher<Window> isShowing() {
40         return baseMatcher("Window is showing"new Predicate<Window>() {
41             @Override
42             public boolean apply(@Nullable Window window) {
43                 return isShowing(window);
44             }
45         });
46     }
47 
48     @Factory
49     public static Matcher<Window> isNotShowing() {
50         return baseMatcher("Window is not showing"new Predicate<Window>() {
51             @Override
52             public boolean apply(@Nullable Window window) {
53                 return !isShowing(window);
54             }
55         });
56     }
57 
58     @Factory
59     public static Matcher<Window> isFocused() {
60         return baseMatcher("Window is focused"new Predicate<Window>() {
61             @Override
62             public boolean apply(@Nullable Window window) {
63                 return isFocused(window);
64             }
65         });
66     }
67 
68     @Factory
69     public static Matcher<Window> isNotFocused() {
70         return baseMatcher("Window is not focused"new Predicate<Window>() {
71             @Override
72             public boolean apply(@Nullable Window window) {
73                 return !isFocused(window);
74             }
75         });
76     }
77 
78     //---------------------------------------------------------------------------------------------
79     // PRIVATE STATIC METHODS.
80     //---------------------------------------------------------------------------------------------
81 
82     private static boolean isShowing(Window window) {
83         return window.isShowing();
84     }
85 
86     private static boolean isFocused(Window window) {
87         return window.isFocused();
88     }
89 }