Package org.fest.swing.fixture

Examples of org.fest.swing.fixture.FrameFixture


        Probability defaultValue = new Probability(0.75d);
        ProbabilityParameterControl control = new ProbabilityParameterControl(defaultValue);

        JFrame frame = new JFrame();
        frame.add(control.getControl(), BorderLayout.CENTER);
        FrameFixture frameFixture = new FrameFixture(robot, frame);
        frame.setSize(300, 50);
        frame.validate();
        frame.setVisible(true);

        JSlider slider = frameFixture.slider().component();
        frameFixture.slider().slideTo(80); // 80 ticks is a probability of 0.8.

        control.reset();
        assert control.getNumberGenerator().nextValue().equals(defaultValue) : "NumberGenerator reset failed.";
        assert slider.getValue() == 75 : "JSlider reset failed.";

        String displayedValue = frameFixture.label().text();
        assert displayedValue.equals("0.75") : "Wrong value displayed: " + displayedValue;
    }
View Full Code Here


    {
        Robot robot = BasicRobot.robotWithNewAwtHierarchy();
        final SwingConsole swingConsole = new SwingConsole();
        JFrame frame = new JFrame();
        frame.add(swingConsole, BorderLayout.CENTER);
        FrameFixture frameFixture = new FrameFixture(robot, frame);
        frame.setSize(300, 100);
        frame.validate();
        frame.setVisible(true);

        final List<JLabel> labels = Arrays.asList(new JLabel("Zero"),
                                                  new JLabel("One"),
                                                  new JLabel("Two"));

        final int[] selection = new int[1];
        new Thread(new Runnable()
        {
            public void run()
            {
                // This method blocks so we can't run it on the test thread.
                selection[0] = swingConsole.select(labels);
            }
        }).start();
        Thread.sleep(250)// TO DO: Come up with a proper solution to this race condition.
        frameFixture.button("Selection-1").click();

        assert selection[0] == 1
                : "Second item (index 1) should have been selected, selection index was " + selection[0];

        robot.cleanUp();
View Full Code Here

    public void testDisplayPuzzle()
    {
        SudokuView view = new SudokuView();
        JFrame frame = new JFrame();
        frame.add(view, BorderLayout.CENTER);
        FrameFixture frameFixture = new FrameFixture(robot, frame);
        frame.setSize(400, 400);
        frame.validate();

        frameFixture.show();
        view.setPuzzle(TEST_PUZZLE);

        // Check a non-empty cell.
        JTableCellFixture cell1 = frameFixture.table().cell(TableCell.row(0).column(0));
        cell1.requireEditable();
        cell1.requireValue("4");

        // And an empty cell.
        JTableCellFixture cell2 = frameFixture.table().cell(TableCell.row(0).column(1));
        cell2.requireEditable();
        cell2.requireValue("");
    }
View Full Code Here

    public void testDisplaySolution()
    {
        SudokuView view = new SudokuView();
        JFrame frame = new JFrame();
        frame.add(view, BorderLayout.CENTER);
        FrameFixture frameFixture = new FrameFixture(robot, frame);
        frame.setSize(400, 400);
        frame.validate();

        frameFixture.show();
        Sudoku sudoku = SudokuTestUtils.createSudoku(new int[][]
        {
            {1, 2, 8, 5, 4, 3, 9, 6, 7},
            {7, 6, 4, 9, 2, 8, 5, 1, 3},
            {3, 9, 5, 7, 6, 1, 2, 4, 8},
            {6, 1, 9, 4, 8, 5, 7, 3, 2},
            {5, 8, 3, 6, 7, 2, 1, 9, 4},
            {4, 7, 2, 3, 1, 9, 8, 5, 6},
            {8, 5, 1, 2, 3, 6, 4, 7, 9},
            {9, 4, 6, 8, 5, 7, 3, 2, 1},
            {2, 3, 7, 1, 9, 4, 6, 8, 5}
        });
        view.setSolution(sudoku);

        JTableCellFixture cell1 = frameFixture.table().cell(TableCell.row(0).column(0));
        cell1.requireNotEditable();
        cell1.requireValue("1");
    }
View Full Code Here

    public void testSelectAll()
    {
        ItineraryPanel itineraryPanel = new ItineraryPanel(CITIES.getKnownCities());
        JFrame frame = new JFrame();
        frame.add(itineraryPanel, BorderLayout.CENTER);
        FrameFixture frameFixture = new FrameFixture(robot, frame);
        frame.setSize(100, 300);
        frame.validate();
        frame.setVisible(true);
        assert itineraryPanel.getSelectedCities().isEmpty() : "Should be no cities selected initially.";
        frameFixture.button("All").click();
        Collection<String> selectedCities = itineraryPanel.getSelectedCities();
        assert selectedCities.size() == CITIES.getKnownCities().size()
            : "All cities should be selected after button click.";
    }
View Full Code Here

    public void testSelectNone()
    {
        ItineraryPanel itineraryPanel = new ItineraryPanel(CITIES.getKnownCities());
        JFrame frame = new JFrame();
        frame.add(itineraryPanel, BorderLayout.CENTER);
        FrameFixture frameFixture = new FrameFixture(robot, frame);
        frame.setSize(100, 300);
        frame.validate();
        frame.setVisible(true);
        frameFixture.button("All").click();
        Collection<String> selectedCities = itineraryPanel.getSelectedCities();
        assert selectedCities.size() == CITIES.getKnownCities().size()
            : "All cities should be selected after all button click.";
        frameFixture.button("None").click();
        assert itineraryPanel.getSelectedCities().isEmpty()
            : "No cities should be selected after clear button is clicked.";
    }
View Full Code Here

    public void testBruteForceOption()
    {
        StrategyPanel strategyPanel = new StrategyPanel(CITIES);
        JFrame frame = new JFrame();
        frame.add(strategyPanel, BorderLayout.CENTER);
        FrameFixture frameFixture = new FrameFixture(robot, frame);
        frame.setSize(500, 300);
        frame.validate();
        frame.setVisible(true);
        robot.waitForIdle();

        // Evolution controls should be enabled by default.
        frameFixture.panel("EvolutionPanel").requireEnabled();

        frameFixture.radioButton("BruteForceOption").click();

        // Evolution controls should be disabled when brute force option is selected.
        frameFixture.panel("EvolutionPanel").requireDisabled();

        TravellingSalesmanStrategy strategy = strategyPanel.getStrategy();
        assert strategy instanceof BruteForceTravellingSalesman : "Wrong strategy class: " + strategy.getClass();
    }
View Full Code Here

    public void testEvolutionOption()
    {
        StrategyPanel strategyPanel = new StrategyPanel(CITIES);
        JFrame frame = new JFrame();
        frame.add(strategyPanel, BorderLayout.CENTER);
        FrameFixture frameFixture = new FrameFixture(robot, frame);
        frame.setSize(500, 300);
        frame.validate();
        frame.setVisible(true);
        robot.waitForIdle();

        frameFixture.radioButton("EvolutionOption").click();
        TravellingSalesmanStrategy strategy = strategyPanel.getStrategy();
        assert strategy instanceof EvolutionaryTravellingSalesman : "Wrong strategy class: " + strategy.getClass();
    }
View Full Code Here

    public void testDisablePanel()
    {
        StrategyPanel strategyPanel = new StrategyPanel(CITIES);
        JFrame frame = new JFrame();
        frame.add(strategyPanel, BorderLayout.CENTER);
        FrameFixture frameFixture = new FrameFixture(robot, frame);
        frame.setSize(500, 300);
        frame.validate();
        frame.setVisible(true);
        robot.waitForIdle();

        // Components should be enabled initially.
        frameFixture.radioButton("EvolutionOption").requireEnabled();
        frameFixture.panel("EvolutionPanel").requireEnabled();
        frameFixture.radioButton("BruteForceOption").requireEnabled();

        strategyPanel.setEnabled(false);
        frameFixture.radioButton("EvolutionOption").requireDisabled();
        frameFixture.panel("EvolutionPanel").requireDisabled();
        frameFixture.radioButton("BruteForceOption").requireDisabled();       
    }
View Full Code Here

        robot.waitForIdle();
        // There ought to be a visible frame containing the example GUI.
        JFrame frame = (JFrame) robot.finder().find(FrameMatcher.withTitle("ExampleFrame").andShowing());
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

        FrameFixture frameFixture = new FrameFixture(robot, frame);
        assert frameFixture.label("Test").component().isShowing() : "GUI not displayed correctly.";       
        frameFixture.close();
    }
View Full Code Here

TOP

Related Classes of org.fest.swing.fixture.FrameFixture

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.