org.fest.swing.fixture
Class JFileChooserFixture

java.lang.Object
  extended by org.fest.swing.fixture.ComponentFixture<JFileChooser>
      extended by org.fest.swing.fixture.JFileChooserFixture
All Implemented Interfaces:
CommonComponentFixture, FocusableComponentFixture, KeyboardInputSimulationFixture, MouseInputSimulationFixture, StateVerificationFixture

public class JFileChooserFixture
extends ComponentFixture<JFileChooser>
implements CommonComponentFixture

Understands functional testing of JFileChoosers:

Author:
Yvonne Wang, Alex Ruiz

Field Summary
 
Fields inherited from class org.fest.swing.fixture.ComponentFixture
BACKGROUND_PROPERTY, FONT_PROPERTY, FOREGROUND_PROPERTY, robot, target
 
Constructor Summary
JFileChooserFixture(Robot robot)
          Creates a new JFileChooserFixture.
JFileChooserFixture(Robot robot, JFileChooser target)
          Creates a new JFileChooserFixture.
JFileChooserFixture(Robot robot, String fileChooserName)
          Creates a new JFileChooserFixture.
 
Method Summary
 void approve()
          Simulates a user pressing the "Approve" button in this fixture's JFileChooser.
 JButtonFixture approveButton()
          Finds the "Approve" button in this fixture's JFileChooser.
 void cancel()
          Simulates a user pressing the "Cancel" button in this fixture's JFileChooser.
 JButtonFixture cancelButton()
          Finds the "Cancel" button in this fixture's JFileChooser.
 JFileChooserFixture click()
          Simulates a user clicking this fixture's JFileChooser.
 JFileChooserFixture click(MouseButton button)
          Simulates a user clicking this fixture's JFileChooser.
 JFileChooserFixture click(MouseClickInfo mouseClickInfo)
          Simulates a user clicking this fixture's JFileChooser.
 JFileChooserFixture doubleClick()
          Simulates a user double-clicking this fixture's JFileChooser.
protected  void driver(JFileChooserDriver newDriver)
          Sets the JFileChooserDriver to be used by this fixture.
 JTextComponentFixture fileNameTextBox()
          Returns a fixture that manages the field where the user can enter the name of the file to select in this fixture's JFileChooser.
 JFileChooserFixture focus()
          Gives input focus to this fixture's JFileChooser.
 JFileChooserFixture pressAndReleaseKey(KeyPressInfo keyPressInfo)
          Simulates a user pressing given key with the given modifiers on this fixture's JFileChooser.
 JFileChooserFixture pressAndReleaseKeys(int... keyCodes)
          Simulates a user pressing and releasing the given keys on the JFileChooser managed by this fixture.
 JFileChooserFixture pressKey(int keyCode)
          Simulates a user pressing the given key on this fixture's JFileChooser.
 JFileChooserFixture releaseKey(int keyCode)
          Simulates a user releasing the given key on this fixture's JFileChooser.
 JFileChooserFixture requireDisabled()
          Asserts that this fixture's JFileChooser is disabled.
 JFileChooserFixture requireEnabled()
          Asserts that this fixture's JFileChooser is enabled.
 JFileChooserFixture requireEnabled(Timeout timeout)
          Asserts that this fixture's JFileChooser is enabled.
 JFileChooserFixture requireFocused()
          Asserts that this fixture's JFileChooser has input focus.
 JFileChooserFixture requireNotVisible()
          Asserts that this fixture's JFileChooser is not visible.
 JFileChooserFixture requireVisible()
          Asserts that this fixture's JFileChooser is visible.
 JFileChooserFixture rightClick()
          Simulates a user right-clicking this fixture's JFileChooser.
 JFileChooserFixture selectFile(File file)
          Selects the given file in this fixture's JFileChooser.
 JFileChooserFixture selectFiles(File... files)
          Selects the given files in this fixture's JFileChooser.
 JFileChooserFixture setCurrentDirectory(File dir)
          Sets the current directory of this fixture's JFileChooser to the given one.
 
Methods inherited from class org.fest.swing.fixture.ComponentFixture
background, component, font, foreground, requireShowing, targetCastedTo, validateNotNull
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JFileChooserFixture

public JFileChooserFixture(Robot robot)
Creates a new JFileChooserFixture.

Parameters:
robot - performs simulation of user events on a JFileChooser.
Throws:
NullPointerException - if robot is null.
ComponentLookupException - if a matching JFileChooser could not be found.
ComponentLookupException - if more than one matching JFileChooser is found.

JFileChooserFixture

public JFileChooserFixture(Robot robot,
                           JFileChooser target)
Creates a new JFileChooserFixture.

Parameters:
robot - performs simulation of user events on the given JFileChooser.
target - the JFileChooser to be managed by this fixture.
Throws:
NullPointerException - if robot is null.
NullPointerException - if target is null.

JFileChooserFixture

public JFileChooserFixture(Robot robot,
                           String fileChooserName)
Creates a new JFileChooserFixture.

Parameters:
robot - performs simulation of user events on a JFileChooser.
fileChooserName - the name of the JFileChooser to find using the given RobotFixture.
Throws:
NullPointerException - if robot is null.
ComponentLookupException - if a matching JFileChooser could not be found.
ComponentLookupException - if more than one matching JFileChooser is found.
Method Detail

driver

protected final void driver(JFileChooserDriver newDriver)
Sets the JFileChooserDriver to be used by this fixture.

Parameters:
newDriver - the new JFileChooserDriver.
Throws:
NullPointerException - if the given driver is null.

approve

public void approve()
Simulates a user pressing the "Approve" button in this fixture's JFileChooser.

Throws:
ComponentLookupException - if the "Approve" button cannot be found.
IllegalStateException - if the "Approve" button is disabled.
IllegalStateException - if the "Approve" button is not showing on the screen.

approveButton

public JButtonFixture approveButton()
Finds the "Approve" button in this fixture's JFileChooser.

Returns:
the found "Approve" button.
Throws:
ComponentLookupException - if the "Approve" button cannot be found.

cancel

public void cancel()
Simulates a user pressing the "Cancel" button in this fixture's JFileChooser.

Throws:
ComponentLookupException - if the "Cancel" button cannot be found.
IllegalStateException - if the "Cancel" button is disabled.
IllegalStateException - if the "Cancel" button is not showing on the screen.

cancelButton

public JButtonFixture cancelButton()
Finds the "Cancel" button in this fixture's JFileChooser.

Returns:
the found "Cancel" button.
Throws:
ComponentLookupException - if the "Cancel" button cannot be found.

fileNameTextBox

public JTextComponentFixture fileNameTextBox()
Returns a fixture that manages the field where the user can enter the name of the file to select in this fixture's JFileChooser.

Returns:
the created fixture.
Throws:
ComponentLookupException - if a matching textToMatch field could not be found.

selectFile

public JFileChooserFixture selectFile(File file)
Selects the given file in this fixture's JFileChooser.

Parameters:
file - the file to select.
Returns:
this fixture.
Throws:
NullPointerException - if the given file is null.
IllegalStateException - if this fixture's JFileChooser is disabled.
IllegalStateException - if this fixture's JFileChooser is not showing on the screen.
IllegalArgumentException - if this fixture's JFileChooser can select directories only and the file to select is not a directory.
IllegalArgumentException - if this fixture's JFileChooser cannot select directories and the file to select is a directory.

selectFiles

public JFileChooserFixture selectFiles(File... files)
Selects the given files in this fixture's JFileChooser.

Parameters:
files - the files to select.
Returns:
this fixture.
Throws:
NullPointerException - if the given array of files is null.
IllegalArgumentException - if the given array of files is empty.
IllegalStateException - if this fixture's JFileChooser is disabled.
IllegalStateException - if this fixture's JFileChooser is not showing on the screen.
IllegalStateException - if this fixture's JFileChooser does not support multiple selection and there is more than one file to select.
IllegalArgumentException - if this fixture's JFileChooser can select directories only and any of the files to select is not a directory.
IllegalArgumentException - if this fixture's JFileChooser cannot select directories and any of the files to select is a directory.

setCurrentDirectory

public JFileChooserFixture setCurrentDirectory(File dir)
Sets the current directory of this fixture's JFileChooser to the given one.

Parameters:
dir - the directory to set as current.
Returns:
this fixture.
Throws:
IllegalStateException - if this fixture's JFileChooser is disabled.
IllegalStateException - if this fixture's JFileChooser is not showing on the screen.

click

public JFileChooserFixture click()
Simulates a user clicking this fixture's JFileChooser.

Specified by:
click in interface MouseInputSimulationFixture
Returns:
this fixture.
Throws:
IllegalStateException - if this fixture's JFileChooser is disabled.
IllegalStateException - if this fixture's JFileChooser is not showing on the screen.

click

public JFileChooserFixture click(MouseButton button)
Simulates a user clicking this fixture's JFileChooser.

Specified by:
click in interface MouseInputSimulationFixture
Parameters:
button - the button to click.
Returns:
this fixture.
Throws:
NullPointerException - if the given MouseButton is null.
IllegalStateException - if this fixture's JFileChooser is disabled.
IllegalStateException - if this fixture's JFileChooser is not showing on the screen.

click

public JFileChooserFixture click(MouseClickInfo mouseClickInfo)
Simulates a user clicking this fixture's JFileChooser.

Specified by:
click in interface MouseInputSimulationFixture
Parameters:
mouseClickInfo - specifies the button to click and the times the button should be clicked.
Returns:
this fixture.
Throws:
NullPointerException - if the given MouseClickInfo is null.
IllegalStateException - if this fixture's JFileChooser is disabled.
IllegalStateException - if this fixture's JFileChooser is not showing on the screen.

doubleClick

public JFileChooserFixture doubleClick()
Simulates a user double-clicking this fixture's JFileChooser.

Specified by:
doubleClick in interface MouseInputSimulationFixture
Returns:
this fixture.
Throws:
IllegalStateException - if this fixture's JFileChooser is disabled.
IllegalStateException - if this fixture's JFileChooser is not showing on the screen.

rightClick

public JFileChooserFixture rightClick()
Simulates a user right-clicking this fixture's JFileChooser.

Specified by:
rightClick in interface MouseInputSimulationFixture
Returns:
this fixture.
Throws:
IllegalStateException - if this fixture's JFileChooser is disabled.
IllegalStateException - if this fixture's JFileChooser is not showing on the screen.

focus

public JFileChooserFixture focus()
Gives input focus to this fixture's JFileChooser.

Specified by:
focus in interface FocusableComponentFixture
Returns:
this fixture.
Throws:
IllegalStateException - if this fixture's JFileChooser is disabled.
IllegalStateException - if this fixture's JFileChooser is not showing on the screen.

pressAndReleaseKey

public JFileChooserFixture pressAndReleaseKey(KeyPressInfo keyPressInfo)
Simulates a user pressing given key with the given modifiers on this fixture's JFileChooser. Modifiers is a mask from the available InputEvent masks.

Specified by:
pressAndReleaseKey in interface KeyboardInputSimulationFixture
Parameters:
keyPressInfo - specifies the key and modifiers to press.
Returns:
this fixture.
Throws:
NullPointerException - if the given KeyPressInfo is null.
IllegalArgumentException - if the given code is not a valid key code.
IllegalStateException - if this fixture's JFileChooser is disabled.
IllegalStateException - if this fixture's JFileChooser is not showing on the screen.
See Also:
KeyPressInfo

pressAndReleaseKeys

public JFileChooserFixture pressAndReleaseKeys(int... keyCodes)
Simulates a user pressing and releasing the given keys on the JFileChooser managed by this fixture.

Specified by:
pressAndReleaseKeys in interface KeyboardInputSimulationFixture
Parameters:
keyCodes - one or more codes of the keys to press.
Returns:
this fixture.
Throws:
NullPointerException - if the given array of codes is null.
IllegalArgumentException - if any of the given code is not a valid key code.
IllegalStateException - if this fixture's JFileChooser is disabled.
IllegalStateException - if this fixture's JFileChooser is not showing on the screen.
See Also:
KeyEvent

pressKey

public JFileChooserFixture pressKey(int keyCode)
Simulates a user pressing the given key on this fixture's JFileChooser.

Specified by:
pressKey in interface KeyboardInputSimulationFixture
Parameters:
keyCode - the code of the key to press.
Returns:
this fixture.
Throws:
IllegalArgumentException - if any of the given code is not a valid key code.
IllegalStateException - if this fixture's JFileChooser is disabled.
IllegalStateException - if this fixture's JFileChooser is not showing on the screen.
See Also:
KeyEvent

releaseKey

public JFileChooserFixture releaseKey(int keyCode)
Simulates a user releasing the given key on this fixture's JFileChooser.

Specified by:
releaseKey in interface KeyboardInputSimulationFixture
Parameters:
keyCode - the code of the key to release.
Returns:
this fixture.
Throws:
IllegalArgumentException - if any of the given code is not a valid key code.
IllegalStateException - if this fixture's JFileChooser is disabled.
IllegalStateException - if this fixture's JFileChooser is not showing on the screen.
See Also:
KeyEvent

requireFocused

public JFileChooserFixture requireFocused()
Asserts that this fixture's JFileChooser has input focus.

Specified by:
requireFocused in interface FocusableComponentFixture
Returns:
this fixture.
Throws:
AssertionError - if this fixture's JFileChooser does not have input focus.

requireEnabled

public JFileChooserFixture requireEnabled()
Asserts that this fixture's JFileChooser is enabled.

Specified by:
requireEnabled in interface StateVerificationFixture
Returns:
this fixture.
Throws:
AssertionError - if this fixture's JFileChooser is disabled.

requireEnabled

public JFileChooserFixture requireEnabled(Timeout timeout)
Asserts that this fixture's JFileChooser is enabled.

Specified by:
requireEnabled in interface StateVerificationFixture
Parameters:
timeout - the time this fixture will wait for the component to be enabled.
Returns:
this fixture.
Throws:
WaitTimedOutError - if this fixture's JFileChooser is never enabled.

requireDisabled

public JFileChooserFixture requireDisabled()
Asserts that this fixture's JFileChooser is disabled.

Specified by:
requireDisabled in interface StateVerificationFixture
Returns:
this fixture.
Throws:
AssertionError - if this fixture's JFileChooser is enabled.

requireVisible

public JFileChooserFixture requireVisible()
Asserts that this fixture's JFileChooser is visible.

Specified by:
requireVisible in interface StateVerificationFixture
Returns:
this fixture.
Throws:
AssertionError - if this fixture's JFileChooser is not visible.

requireNotVisible

public JFileChooserFixture requireNotVisible()
Asserts that this fixture's JFileChooser is not visible.

Specified by:
requireNotVisible in interface StateVerificationFixture
Returns:
this fixture.
Throws:
AssertionError - if this fixture's JFileChooser is visible.


Copyright © 2007-2011 FEST (Fixtures for Easy Software Testing). All Rights Reserved.