@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_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")); } }
@Test public void test_dataGrid_usage() { when(evaluator.componentType(id)).thenReturn(DataGrid); final DataGrid dataGrid = new DataGrid(evaluator, id); when(evaluator.existComponent("1")).thenReturn(true); when(evaluator.componentType("1")).thenReturn(Row); when(evaluator.existComponent("2")).thenReturn(true); when(evaluator.componentType("2")).thenReturn(Row); when(evaluator.existComponent("3")).thenReturn(true); when(evaluator.componentType("3")).thenReturn(Row); when(evaluator.existComponent("4")).thenReturn(true); when(evaluator.componentType("4")).thenReturn(Row); when(evaluator.existComponent("5")).thenReturn(true); when(evaluator.componentType("5")).thenReturn(Row); when(evaluator.existComponent("6")).thenReturn(true); when(evaluator.componentType("6")).thenReturn(Row); when(evaluator.existComponent("7")).thenReturn(true); when(evaluator.componentType("7")).thenReturn(Row); Row row_1 = new Row(evaluator, "1"); Row row_2 = new Row(evaluator, "2"); Row row_3 = new Row(evaluator, "3"); Row row_4 = new Row(evaluator, "4"); Row row_5 = new Row(evaluator, "5"); Row row_6 = new Row(evaluator, "6"); Row row_7 = new Row(evaluator, "7"); Selection<Row> rows = ListSelection.of(row_1, row_2, row_3, row_4, row_5, row_6, row_7); when(evaluator.rows(dataGrid)).thenReturn(rows); when(evaluator.cells(any(Row.class))).thenReturn(ListSelection.empty()); assertThat(first(dataGrid.rows()).id(), is(dataGrid.row(1).id())); assertThat(last(dataGrid.rows()).id(), is(dataGrid.row(dataGrid.rows().size()).id())); }