@Before public void setUp() { evaluator = mock(Evaluator.class); when(evaluator.name()).thenReturn(Evaluator.DEFAULT_NAME); // Needed for Mouse ;) EvaluatorHolder.register(evaluator); when(evaluator.existComponent(id)).thenReturn(true); when(evaluator.isVisible(any(Component.class))).thenReturn(true); when(evaluator.isEnabled(any(Component.class))).thenReturn(true); }
@Test public void test_window_usage_through_language() { when(evaluator.componentType(id)).thenReturn(Window); Window window = new Window(evaluator, id); when(evaluator.isVisible(any(Component.class))).thenReturn(true); when(evaluator.isEnabled(any(Component.class))).thenReturn(true); when(evaluator.title(window)).thenReturn("windowTitle"); close(window); verify(evaluator, times(1)).close(window); }
@Test public void test_wait_until_with_success() { evaluator = mock(Evaluator.class); when(evaluator.existComponent(id)).thenReturn(true); when(evaluator.isVisible(any(Component.class))) .thenReturn(false, false, false, false, false, false, true); when(evaluator.isEnabled(any(Component.class))).thenReturn(true); Component component = new Component(evaluator, id); waitUntil(component, is(visible()), max(2, TimeUnit.SECONDS), freq(500, TimeUnit.MILLISECONDS)); verify(evaluator, times(7)).isVisible(any(Component.class)); }
@Test public void test_wait_until_with_failure() { evaluator = mock(Evaluator.class); when(evaluator.existComponent(id)).thenReturn(true); when(evaluator.isVisible(any(Component.class))).thenReturn(false); when(evaluator.isEnabled(any(Component.class))).thenReturn(true); Component component = new Component(evaluator, id); try { waitUntil(component, is(visible())); fail(); } catch (Exception e) { assertThat(e.getMessage(), is("Unable to reach the condition in 5 SECONDS")); } }