|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| JListItemFixture | Line # 40 | 23 | 0% | 13 | 0 | 100% |
1.0
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
| No Tests | |||
| 1 | /* | |
| 2 | * Created on Dec 8, 2007 | |
| 3 | * | |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | |
| 5 | * in compliance with the License. You may obtain a copy of the License at | |
| 6 | * | |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 8 | * | |
| 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License | |
| 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | |
| 11 | * or implied. See the License for the specific language governing permissions and limitations under | |
| 12 | * the License. | |
| 13 | * | |
| 14 | * Copyright @2007-2010 the original author or authors. | |
| 15 | */ | |
| 16 | package org.fest.swing.fixture; | |
| 17 | ||
| 18 | import static org.fest.swing.core.MouseButton.LEFT_BUTTON; | |
| 19 | import static org.fest.swing.core.MouseButton.RIGHT_BUTTON; | |
| 20 | ||
| 21 | import javax.swing.JList; | |
| 22 | ||
| 23 | import org.fest.swing.cell.JListCellReader; | |
| 24 | import org.fest.swing.core.MouseButton; | |
| 25 | import org.fest.swing.core.MouseClickInfo; | |
| 26 | import org.fest.swing.exception.ActionFailedException; | |
| 27 | import org.fest.swing.exception.ComponentLookupException; | |
| 28 | ||
| 29 | /** | |
| 30 | * Understands functional testing of single rows in <code>{@link JList}</code>s: | |
| 31 | * <ul> | |
| 32 | * <li>user input simulation</li> | |
| 33 | * <li>state verification</li> | |
| 34 | * <li>property value query</li> | |
| 35 | * </ul> | |
| 36 | * | |
| 37 | * @author Yvonne Wang | |
| 38 | * @author Alex Ruiz | |
| 39 | */ | |
| 40 | public class JListItemFixture implements ItemFixture { | |
| 41 | ||
| 42 | final JListFixture list; | |
| 43 | final int index; | |
| 44 | ||
| 45 | /** | |
| 46 | * Creates a new </code>{@link JListItemFixture}</code>. | |
| 47 | * @param list manages the <code>JList</code> containing the list item to be managed by this fixture. | |
| 48 | * @param index index of the list item to be managed by this fixture. | |
| 49 | * @throws NullPointerException if <code>list</code> is <code>null</code>. | |
| 50 | */ | |
| 51 | 16 |
public JListItemFixture(JListFixture list, int index) { |
| 52 | 1 | if (list == null) throw new NullPointerException("The given JListFixture should not be null"); |
| 53 | 15 | this.list = list; |
| 54 | 15 | this.index = index; |
| 55 | } | |
| 56 | ||
| 57 | /** | |
| 58 | * Simulates a user selecting this fixture's list item. | |
| 59 | * @return this fixture. | |
| 60 | * @throws IllegalStateException if this fixture's <code>JList</code> is disabled. | |
| 61 | * @throws IllegalStateException if this fixture's <code>JList</code> is not showing on the screen. | |
| 62 | * @throws IndexOutOfBoundsException if this item's index is negative or greater than the index of the last item in | |
| 63 | * the <code>JList</code>. | |
| 64 | */ | |
| 65 | 1 |
public final JListItemFixture select() { |
| 66 | 1 | list.selectItem(index); |
| 67 | 1 | return this; |
| 68 | } | |
| 69 | ||
| 70 | /** | |
| 71 | * Simulates a user clicking this fixture's list item. | |
| 72 | * @return this fixture. | |
| 73 | * @throws IllegalStateException if this fixture's <code>JList</code> is disabled. | |
| 74 | * @throws IllegalStateException if this fixture's <code>JList</code> is not showing on the screen. | |
| 75 | * @throws IndexOutOfBoundsException if this item's index is negative or greater than the index of the last item in | |
| 76 | * the <code>JList</code>. | |
| 77 | */ | |
| 78 | 1 |
public final JListItemFixture click() { |
| 79 | 1 | list.clickItem(index); |
| 80 | 1 | return this; |
| 81 | } | |
| 82 | ||
| 83 | /** | |
| 84 | * Simulates a user clicking this fixture's list item. | |
| 85 | * @param button the button to click. | |
| 86 | * @return this fixture. | |
| 87 | * @throws NullPointerException if the given <code>MouseButton</code> is <code>null</code>. | |
| 88 | * @throws IllegalStateException if this fixture's <code>JList</code> is disabled. | |
| 89 | * @throws IllegalStateException if this fixture's <code>JList</code> is not showing on the screen. | |
| 90 | * @throws IndexOutOfBoundsException if this item's index is negative or greater than the index of the last item in | |
| 91 | * the <code>JList</code>. | |
| 92 | */ | |
| 93 | 1 |
public final JListItemFixture click(MouseButton button) { |
| 94 | 1 | list.clickItem(index, button, 1); |
| 95 | 1 | return this; |
| 96 | } | |
| 97 | ||
| 98 | /** | |
| 99 | * Simulates a user clicking this fixture's list item. | |
| 100 | * @param mouseClickInfo specifies the button to click and the times the button should be clicked. | |
| 101 | * @return this fixture. | |
| 102 | * @throws NullPointerException if the given <code>MouseClickInfo</code> is <code>null</code>. | |
| 103 | * @throws IllegalStateException if this fixture's <code>JList</code> is disabled. | |
| 104 | * @throws IllegalStateException if this fixture's <code>JList</code> is not showing on the screen. | |
| 105 | * @throws IndexOutOfBoundsException if this item's index is negative or greater than the index of the last item in | |
| 106 | * the <code>JList</code>. | |
| 107 | */ | |
| 108 | 1 |
public final JListItemFixture click(MouseClickInfo mouseClickInfo) { |
| 109 | 1 | list.clickItem(index, mouseClickInfo.button(), mouseClickInfo.times()); |
| 110 | 1 | return this; |
| 111 | } | |
| 112 | ||
| 113 | /** | |
| 114 | * Simulates a user double-clicking this fixture's list item. | |
| 115 | * @return this fixture. | |
| 116 | * @throws IllegalStateException if this fixture's <code>JList</code> is disabled. | |
| 117 | * @throws IllegalStateException if this fixture's <code>JList</code> is not showing on the screen. | |
| 118 | * @throws IndexOutOfBoundsException if this item's index is negative or greater than the index of the last item in | |
| 119 | * the <code>JList</code>. | |
| 120 | */ | |
| 121 | 1 |
public final JListItemFixture doubleClick() { |
| 122 | 1 | list.clickItem(index, LEFT_BUTTON, 2); |
| 123 | 1 | return this; |
| 124 | } | |
| 125 | ||
| 126 | /** | |
| 127 | * Simulates a user right-clicking this fixture's list item. | |
| 128 | * @return this fixture. | |
| 129 | * @throws IllegalStateException if this fixture's <code>JList</code> is disabled. | |
| 130 | * @throws IllegalStateException if this fixture's <code>JList</code> is not showing on the screen. | |
| 131 | * @throws IndexOutOfBoundsException if this item's index is negative or greater than the index of the last item in | |
| 132 | * the <code>JList</code>. | |
| 133 | */ | |
| 134 | 1 |
public final JListItemFixture rightClick() { |
| 135 | 1 | list.clickItem(index, RIGHT_BUTTON, 1); |
| 136 | 1 | return this; |
| 137 | } | |
| 138 | ||
| 139 | /** | |
| 140 | * Shows a pop-up menu using this fixture's list item as the invoker of the pop-up menu. | |
| 141 | * @return a fixture that manages the displayed pop-up menu. | |
| 142 | * @throws IllegalStateException if this fixture's <code>JList</code> is disabled. | |
| 143 | * @throws IllegalStateException if this fixture's <code>JList</code> is not showing on the screen. | |
| 144 | * @throws IndexOutOfBoundsException if this item's index is negative or greater than the index of the last item in | |
| 145 | * the <code>JList</code>. | |
| 146 | * @throws ComponentLookupException if a pop-up menu cannot be found. | |
| 147 | */ | |
| 148 | 1 |
public final JPopupMenuFixture showPopupMenu() { |
| 149 | 1 | return list.showPopupMenuAt(index); |
| 150 | } | |
| 151 | ||
| 152 | /** | |
| 153 | * Returns the <code>String</code> representation of the value of this fixture's list item, using the | |
| 154 | * <code>{@link JListCellReader}</code> from the <code>{@link JListFixture}</code> that created this | |
| 155 | * <code>{@link JListItemFixture}</code>. | |
| 156 | * @return the <code>String</code> representation of the value of this fixture's list item. | |
| 157 | * @throws IndexOutOfBoundsException if this item's index is negative or greater than the index of the last item in | |
| 158 | * the <code>JList</code>. | |
| 159 | * @see JListFixture#cellReader(JListCellReader) | |
| 160 | */ | |
| 161 | 1 |
public final String value() { |
| 162 | 1 | return list.valueAt(index); |
| 163 | } | |
| 164 | ||
| 165 | /** | |
| 166 | * Simulates a user dragging this fixture's list item. | |
| 167 | * @return this fixture. | |
| 168 | * @throws IllegalStateException if this fixture's <code>JList</code> is disabled. | |
| 169 | * @throws IllegalStateException if this fixture's <code>JList</code> is not showing on the screen. | |
| 170 | * @throws IndexOutOfBoundsException if this item's index is negative or greater than the index of the last item in | |
| 171 | * the <code>JList</code>. | |
| 172 | */ | |
| 173 | 1 |
public final JListItemFixture drag() { |
| 174 | 1 | list.drag(index); |
| 175 | 1 | return this; |
| 176 | } | |
| 177 | ||
| 178 | /** | |
| 179 | * Simulates a user dropping into this fixture's list item. | |
| 180 | * @return this fixture. | |
| 181 | * @throws IllegalStateException if this fixture's <code>JList</code> is disabled. | |
| 182 | * @throws IllegalStateException if this fixture's <code>JList</code> is not showing on the screen. | |
| 183 | * @throws IndexOutOfBoundsException if this item's index is negative or greater than the index of the last item in | |
| 184 | * the <code>JList</code>. | |
| 185 | * @throws ActionFailedException if there is no drag action in effect. | |
| 186 | */ | |
| 187 | 1 |
public final JListItemFixture drop() { |
| 188 | 1 | list.drop(index); |
| 189 | 1 | return this; |
| 190 | } | |
| 191 | ||
| 192 | /** | |
| 193 | * Returns the index of this fixture's list item. | |
| 194 | * @return the index of this fixture's list item. | |
| 195 | */ | |
| 196 | 1 |
public final int index() { return index; } |
| 197 | } | |
|
||||||||||||