Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (C) 2008 Ovea <dev@testatoo.org> Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 
 package org.testatoo.core.matcher.mock;
 
 
 import java.util.List;
 
 import static org.mockito.Mockito.*;
 import static org.testatoo.core.ComponentType.*;
 
 public class MockFactory {
 
     private static String id = "myId";
 
     public static Component enabledComponent() {
         Evaluator evaluator = mock(Evaluator.class);
 
         when(evaluator.existComponent()).thenReturn(true);
         when(evaluator.isVisible(any(Component.class))).thenReturn(true);
         when(evaluator.isEnabled(any(Component.class))).thenReturn(true);
 
         return new Component(evaluator);
     }
 
     public static Component disabledComponent() {
         Evaluator evaluator = mock(Evaluator.class);
 
         when(evaluator.existComponent()).thenReturn(true);
         when(evaluator.isVisible(any(Component.class))).thenReturn(true);
         when(evaluator.isEnabled(any(Component.class))).thenReturn(false);
 
         return new Component(evaluator);
     }
 
     public static Component visibleComponent() {
         Evaluator evaluator = mock(Evaluator.class);
 
         when(evaluator.existComponent()).thenReturn(true);
         when(evaluator.isVisible(any(Component.class))).thenReturn(true);
         when(evaluator.isEnabled(any(Component.class))).thenReturn(true);
 
         return new Component(evaluator);
     }
 
     public static Component invisibleComponent() {
         Evaluator evaluator = mock(Evaluator.class);
 
         when(evaluator.existComponent()).thenReturn(true);
         when(evaluator.isVisible(any(Component.class))).thenReturn(false);
         when(evaluator.isEnabled(any(Component.class))).thenReturn(true);
 
         return new Component(evaluator);
     }
 
     public static CheckBox checkedCheckBox() {
         Evaluator evaluator = mock(Evaluator.class);
 
         when(evaluator.existComponent()).thenReturn(true);
         when(evaluator.componentType()).thenReturn();
         when(evaluator.isVisible(any(Component.class))).thenReturn(true);
         when(evaluator.isEnabled(any(Component.class))).thenReturn(true);
         when(evaluator.label(any(CheckBox.class))).thenReturn("label");
         when(evaluator.isChecked(any(CheckBox.class))).thenReturn(true);
 
         return new CheckBox(evaluator);
     }
 
     public static CheckBox unCheckedCheckBox() {
         Evaluator evaluator = mock(Evaluator.class);
 
         when(evaluator.existComponent()).thenReturn(true);
         when(evaluator.componentType()).thenReturn();
         when(evaluator.isVisible(any(Component.class))).thenReturn(true);
         when(evaluator.isEnabled(any(Component.class))).thenReturn(true);
         when(evaluator.label(any(CheckBox.class))).thenReturn("label");
         when(evaluator.isChecked(any(CheckBox.class))).thenReturn(false);
 
        return new CheckBox(evaluator);
    }
    public static Radio checkedRadio() {
        Evaluator evaluator = mock(Evaluator.class);
        when(evaluator.existComponent()).thenReturn(true);
        when(evaluator.componentType()).thenReturn();
        when(evaluator.isVisible(any(Component.class))).thenReturn(true);
        when(evaluator.isEnabled(any(Component.class))).thenReturn(true);
        when(evaluator.label(any(Radio.class))).thenReturn("label");
        when(evaluator.isChecked(any(Radio.class))).thenReturn(true);
        return new Radio(evaluator);
    }
    public static Radio unCheckedRadio() {
        Evaluator evaluator = mock(Evaluator.class);
        when(evaluator.existComponent()).thenReturn(true);
        when(evaluator.componentType()).thenReturn();
        when(evaluator.isVisible(any(Component.class))).thenReturn(true);
        when(evaluator.isEnabled(any(Component.class))).thenReturn(true);
        when(evaluator.label(any(Radio.class))).thenReturn("label");
        when(evaluator.isChecked(any(Radio.class))).thenReturn(false);
        return new Radio(evaluator);
    }
    public static Field field(final String value) {
        Evaluator evaluator = mock(Evaluator.class);
        when(evaluator.existComponent()).thenReturn(true);
        when(evaluator.isVisible(any(Component.class))).thenReturn(true);
        when(evaluator.isEnabled(any(Component.class))).thenReturn(true);
        when(evaluator.label(any(Field.class))).thenReturn("label");
        when(evaluator.value(any(Field.class))).thenReturn(value);
        return new FieldImpl(evaluator);
    }
    public static ComboBox comboBox() {
        Evaluator evaluator = mock(Evaluator.class);
        List<StringselectedValues = new ArrayList<String>();
        selectedValues.add("Canada");
        when(evaluator.existComponent()).thenReturn(true);
        when(evaluator.componentType()).thenReturn();
        when(evaluator.isVisible(any(Component.class))).thenReturn(true);
        when(evaluator.isEnabled(any(Component.class))).thenReturn(true);
        when(evaluator.label(any(LabelSupport.class))).thenReturn("label");
        when(evaluator.values(any(ComboBox.class))).thenReturn(countries());
        when(evaluator.selectedValues(any(ComboBox.class))).thenReturn(selectedValues);
        return new ComboBox(evaluator);
    }
    public static ListBox listBox() {
        Evaluator evaluator = mock(Evaluator.class);
        List<StringselectedValues = new ArrayList<String>();
        selectedValues.add("Canada");
        selectedValues.add("Spain");
        when(evaluator.existComponent()).thenReturn(true);
        when(evaluator.componentType()).thenReturn();
        when(evaluator.isVisible(any(Component.class))).thenReturn(true);
        when(evaluator.isEnabled(any(Component.class))).thenReturn(true);
        when(evaluator.label(any(LabelSupport.class))).thenReturn("label");
        when(evaluator.values(any(ListBox.class))).thenReturn(countries());
        when(evaluator.selectedValues(any(ListBox.class))).thenReturn(selectedValues);
        return new ListBox(evaluator);
    }
    public static ListBox listBoxWithoutSelectedValue() {
        Evaluator evaluator = mock(Evaluator.class);
        when(evaluator.existComponent()).thenReturn(true);
        when(evaluator.componentType()).thenReturn();
        when(evaluator.isVisible(any(Component.class))).thenReturn(true);
        when(evaluator.isEnabled(any(Component.class))).thenReturn(true);
        when(evaluator.values(any(ListBox.class))).thenReturn(countries());
        when(evaluator.selectedValues(any(ListBox.class))).thenReturn(new ArrayList<String>());
        return new ListBox(evaluator);
    }
    public static CheckBox checkBoxWithoutLabel() {
        Evaluator evaluator = mock(Evaluator.class);
        when(evaluator.existComponent()).thenReturn(true);
        when(evaluator.componentType()).thenReturn();
        when(evaluator.isVisible(any(Component.class))).thenReturn(true);
        when(evaluator.isEnabled(any(Component.class))).thenReturn(true);
        when(evaluator.isChecked(any(CheckBox.class))).thenReturn(true);
        when(evaluator.label(any(CheckBox.class))).thenReturn("");
        return new CheckBox(evaluator);
    }
    public static CheckBox checkBoxWithLabel(final String label) {
        Evaluator evaluator = mock(Evaluator.class);
        when(evaluator.existComponent()).thenReturn(true);
        when(evaluator.componentType()).thenReturn();
        when(evaluator.isVisible(any(Component.class))).thenReturn(true);
        when(evaluator.isEnabled(any(Component.class))).thenReturn(true);
        when(evaluator.isChecked(any(CheckBox.class))).thenReturn(true);
        when(evaluator.label(any(CheckBox.class))).thenReturn(label);
        return new CheckBox(evaluator);
    }
    public static Button button() {
        Evaluator evaluator = mock(Evaluator.class);
        when(evaluator.existComponent()).thenReturn(true);
        when(evaluator.componentType()).thenReturn();
        when(evaluator.isVisible(any(Component.class))).thenReturn(true);
        when(evaluator.isEnabled(any(Component.class))).thenReturn(true);
        when(evaluator.icon(any(Button.class))).thenReturn("");
        when(evaluator.text(any(Button.class))).thenReturn("buttonText");
        return new Button(evaluator);
    }
    public static TextField textFieldWithMaxLength(final int maxLength) {
        Evaluator evaluator = mock(Evaluator.class);
        when(evaluator.existComponent()).thenReturn(true);
        when(evaluator.componentType()).thenReturn();
        when(evaluator.isVisible(any(Component.class))).thenReturn(true);
        when(evaluator.isEnabled(any(Component.class))).thenReturn(true);
        when(evaluator.label(any(TextField.class))).thenReturn("label");
        when(evaluator.value(any(TextField.class))).thenReturn("textFieldValue");
        when(evaluator.maxLength(any(TextField.class))).thenReturn(maxLength);
        return new TextField(evaluator);
    }
    public static TextField simpleTextFieldWithText(final String text) {
        Evaluator evaluator = mock(Evaluator.class);
        when(evaluator.existComponent()).thenReturn(true);
        when(evaluator.componentType()).thenReturn();
        when(evaluator.isVisible(any(Component.class))).thenReturn(true);
        when(evaluator.isEnabled(any(Component.class))).thenReturn(true);
        when(evaluator.label(any(TextField.class))).thenReturn("label");
        when(evaluator.value(any(TextField.class))).thenReturn(text);
        when(evaluator.maxLength(any(TextField.class))).thenReturn(50);
        return new TextField(evaluator);
    }
    public static DataGrid dataGrid() {
        Evaluator evaluator = mock(Evaluator.class);
        when(evaluator.existComponent(any(String.class))).thenReturn(true);
        when(evaluator.componentType("cell_1")).thenReturn();
        when(evaluator.componentType("cell_2")).thenReturn();
        when(evaluator.componentType("cell_3")).thenReturn();
        when(evaluator.componentType("cell_4")).thenReturn();
        when(evaluator.componentType("cell_5")).thenReturn();
        when(evaluator.componentType("cell_6")).thenReturn();
        Cell cell_1 = new Cell(evaluator"cell_1");
        Cell cell_2 = new Cell(evaluator"cell_2");
        when(evaluator.value(cell_1)).thenReturn("A");
        when(evaluator.value(cell_2)).thenReturn("B");
        List<CellcellList_1 = new ArrayList<Cell>();
        cellList_1.add(cell_1);
        cellList_1.add(cell_2);
        Cell cell_3 = new Cell(evaluator"cell_3");
        Cell cell_4 = new Cell(evaluator"cell_4");
        when(evaluator.value(cell_3)).thenReturn("C");
        when(evaluator.value(cell_4)).thenReturn("D");
        List<CellcellList_2 = new ArrayList<Cell>();
        cellList_2.add(cell_3);
        cellList_2.add(cell_4);
        Cell cell_5 = new Cell(evaluator"cell_5");
        Cell cell_6 = new Cell(evaluator"cell_6");
        when(evaluator.value(cell_5)).thenReturn("E");
        when(evaluator.value(cell_6)).thenReturn("F");
        List<CellcellList_3 = new ArrayList<Cell>();
        cellList_3.add(cell_5);
        cellList_3.add(cell_6);
        List<Columncolumns = new ArrayList<Column>();
        when(evaluator.componentType("col_1")).thenReturn();
        when(evaluator.componentType("col_2")).thenReturn();
        when(evaluator.componentType("col_3")).thenReturn();
        Column column_1 = new Column(evaluator"col_1");
        Column column_2 = new Column(evaluator"col_2");
        Column column_3 = new Column(evaluator"col_3");
        columns.add(column_1);
        columns.add(column_2);
        columns.add(column_3);
        when(evaluator.title(column_1)).thenReturn("Column 1");
        when(evaluator.title(column_2)).thenReturn("Column 2");
        when(evaluator.title(column_3)).thenReturn("Column 3");
        when(evaluator.cells(column_1)).thenReturn(cellList_1);
        when(evaluator.cells(column_2)).thenReturn(cellList_2);
        when(evaluator.cells(column_3)).thenReturn(cellList_3);
        when(evaluator.existComponent()).thenReturn(true);
        when(evaluator.componentType()).thenReturn();
        when(evaluator.isVisible(any(Component.class))).thenReturn(true);
        when(evaluator.isEnabled(any(Component.class))).thenReturn(true);
        DataGrid dataGrid = new DataGrid(evaluator);
        when(evaluator.columns(dataGrid)).thenReturn(columns);
        when(evaluator.componentType("row_1")).thenReturn();
        List<Rowrows = new ArrayList<Row>();
        Row row = new Row(evaluator"row_1");
        rows.add(row);
        when(evaluator.rows(dataGrid)).thenReturn(rows);
        when(evaluator.cells(row)).thenReturn(cellList_1);
        return dataGrid;
    }
    public static Panel panel() {
        Evaluator evaluator = mock(Evaluator.class);
        when(evaluator.existComponent()).thenReturn(true);
        when(evaluator.isVisible(any(Component.class))).thenReturn(true);
        when(evaluator.isEnabled(any(Component.class))).thenReturn(true);
        when(evaluator.componentType()).thenReturn();
        when(evaluator.title(any(Panel.class))).thenReturn("myPanelTitle");
        return new Panel(evaluator);
    }
    private static List<Stringcountries() {
        List<Stringcountries = new ArrayList<String>();
        countries.add("France");
        countries.add("Canada");
        countries.add("Germany");
        countries.add("Italy");
        countries.add("Spain");
        return countries;
    }
New to GrepCode? Check out our FAQ X