|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| JTreePathFixture | Line # 36 | 25 | 0% | 14 | 0 | 100% |
1.0
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
| No Tests | |||
| 1 | /* | |
| 2 | * Created on Dec 26, 2009 | |
| 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 @2009-2010 the original author or authors. | |
| 15 | */ | |
| 16 | package org.fest.swing.fixture; | |
| 17 | ||
| 18 | import javax.swing.JTree; | |
| 19 | ||
| 20 | import org.fest.swing.core.MouseButton; | |
| 21 | import org.fest.swing.core.MouseClickInfo; | |
| 22 | import org.fest.swing.exception.*; | |
| 23 | ||
| 24 | /** | |
| 25 | * Understands functional testing of single nodes, referenced by their paths, in <code>{@link JTree}</code>s: | |
| 26 | * <ul> | |
| 27 | * <li>user input simulation</li> | |
| 28 | * <li>state verification</li> | |
| 29 | * <li>property value query</li> | |
| 30 | * </ul> | |
| 31 | * | |
| 32 | * @author Alex Ruiz | |
| 33 | * | |
| 34 | * @since 1.2 | |
| 35 | */ | |
| 36 | public class JTreePathFixture implements JTreeNodeFixture { | |
| 37 | ||
| 38 | private final String path; | |
| 39 | private final JTreeFixture tree; | |
| 40 | ||
| 41 | /** | |
| 42 | * Creates a new </code>{@link JTreePathFixture}</code>. | |
| 43 | * @param tree handles the <code>JTree</code> containing the node with the given path. | |
| 44 | * @param path the given path. | |
| 45 | */ | |
| 46 | 13 |
protected JTreePathFixture(JTreeFixture tree, String path) { |
| 47 | 13 | this.tree = tree; |
| 48 | 13 | this.path = path; |
| 49 | } | |
| 50 | ||
| 51 | /** | |
| 52 | * Simulates a user expanding this fixture's tree node. | |
| 53 | * @return this fixture. | |
| 54 | * @throws IllegalStateException if the <code>JTree</code> is disabled. | |
| 55 | * @throws IllegalStateException if the <code>JTree</code> is not showing on the screen. | |
| 56 | * @throws ActionFailedException if this method fails to expand the path. | |
| 57 | * @since 1.2 | |
| 58 | */ | |
| 59 | 1 |
public JTreePathFixture expand() { |
| 60 | 1 | tree.expandPath(path); |
| 61 | 1 | return this; |
| 62 | } | |
| 63 | ||
| 64 | /** | |
| 65 | * Simulates a user collapsing this fixture's tree node. | |
| 66 | * @return this fixture. | |
| 67 | * @throws IllegalStateException if the <code>JTree</code> is disabled. | |
| 68 | * @throws IllegalStateException if the <code>JTree</code> is not showing on the screen. | |
| 69 | * @throws ActionFailedException if this method fails to collapse the path. | |
| 70 | * @since 1.2 | |
| 71 | */ | |
| 72 | 1 |
public JTreePathFixture collapse() { |
| 73 | 1 | tree.collapsePath(path); |
| 74 | 1 | return this; |
| 75 | } | |
| 76 | ||
| 77 | /** | |
| 78 | * Selects the this fixture's tree node, expanding parent nodes if necessary. This method will not click the node if | |
| 79 | * it is already selected. | |
| 80 | * @return this fixture. | |
| 81 | * @throws IllegalStateException if this fixture's <code>JTree</code> is disabled. | |
| 82 | * @throws IllegalStateException if this fixture's <code>JTree</code> is not showing on the screen. | |
| 83 | */ | |
| 84 | 1 |
public JTreePathFixture select() { |
| 85 | 1 | tree.selectPath(path); |
| 86 | 1 | return this; |
| 87 | } | |
| 88 | ||
| 89 | /** | |
| 90 | * Simulates a user clicking this fixture's tree node. | |
| 91 | * @return this fixture. | |
| 92 | * @throws IllegalStateException if the <code>JTree</code> is disabled. | |
| 93 | * @throws IllegalStateException if the <code>JTree</code> is not showing on the screen. | |
| 94 | */ | |
| 95 | 1 |
public JTreePathFixture click() { |
| 96 | 1 | tree.clickPath(path); |
| 97 | 1 | return this; |
| 98 | } | |
| 99 | ||
| 100 | /** | |
| 101 | * Simulates a user clicking this fixture's tree node. | |
| 102 | * @param button the button to click. | |
| 103 | * @return this fixture. | |
| 104 | * @throws NullPointerException if the given button is <code>null</code>. | |
| 105 | * @throws IllegalStateException if the <code>JTree</code> is disabled. | |
| 106 | * @throws IllegalStateException if the <code>JTree</code> is not showing on the screen. | |
| 107 | */ | |
| 108 | 1 |
public JTreePathFixture click(MouseButton button) { |
| 109 | 1 | tree.clickPath(path, button); |
| 110 | 1 | return this; |
| 111 | } | |
| 112 | ||
| 113 | /** | |
| 114 | * Simulates a user clicking this fixture's tree node. | |
| 115 | * @param mouseClickInfo specifies the button to click and the times the button should be clicked. | |
| 116 | * @return this fixture. | |
| 117 | * @throws NullPointerException if the given <code>MouseClickInfo</code> is <code>null</code>. | |
| 118 | * @throws IllegalStateException if the <code>JTree</code> is disabled. | |
| 119 | * @throws IllegalStateException if the <code>JTree</code> is not showing on the screen. | |
| 120 | */ | |
| 121 | 1 |
public JTreePathFixture click(MouseClickInfo mouseClickInfo) { |
| 122 | 1 | tree.clickPath(path, mouseClickInfo); |
| 123 | 1 | return this; |
| 124 | } | |
| 125 | ||
| 126 | /** | |
| 127 | * Simulates a user double-clicking this fixture's tree node. | |
| 128 | * @return this fixture. | |
| 129 | * @throws IllegalStateException if the <code>JTree</code> is disabled. | |
| 130 | * @throws IllegalStateException if the <code>JTree</code> is not showing on the screen. | |
| 131 | */ | |
| 132 | 1 |
public JTreePathFixture doubleClick() { |
| 133 | 1 | tree.doubleClickPath(path); |
| 134 | 1 | return this; |
| 135 | } | |
| 136 | ||
| 137 | /** | |
| 138 | * Simulates a user right-clicking this fixture's tree node. | |
| 139 | * @return this fixture. | |
| 140 | * @throws IllegalStateException if the <code>JTree</code> is disabled. | |
| 141 | * @throws IllegalStateException if the <code>JTree</code> is not showing on the screen. | |
| 142 | */ | |
| 143 | 1 |
public JTreePathFixture rightClick() { |
| 144 | 1 | tree.rightClickPath(path); |
| 145 | 1 | return this; |
| 146 | } | |
| 147 | ||
| 148 | /** | |
| 149 | * Simulates a user dragging this fixture's tree node. | |
| 150 | * @return this fixture. | |
| 151 | * @throws IllegalStateException if the <code>JTree</code> is disabled. | |
| 152 | * @throws IllegalStateException if the <code>JTree</code> is not showing on the screen. | |
| 153 | */ | |
| 154 | 1 |
public JTreePathFixture drag() { |
| 155 | 1 | tree.drag(path); |
| 156 | 1 | return this; |
| 157 | } | |
| 158 | ||
| 159 | /** | |
| 160 | * Simulates a user dropping relative to this fixture's tree node. | |
| 161 | * @return this fixture. | |
| 162 | * @throws IllegalStateException if the <code>JTree</code> is disabled. | |
| 163 | * @throws IllegalStateException if the <code>JTree</code> is not showing on the screen. | |
| 164 | * @throws ActionFailedException if there is no drag action in effect. | |
| 165 | */ | |
| 166 | 1 |
public JTreePathFixture drop() { |
| 167 | 1 | tree.drop(path); |
| 168 | 1 | return this; |
| 169 | } | |
| 170 | ||
| 171 | /** | |
| 172 | * Shows a pop-up menu using this fixture's tree node as the invoker of the pop-up menu. | |
| 173 | * @return a fixture that handles functional testing of the displayed pop-up menu. | |
| 174 | * @throws IllegalStateException if the <code>JTree</code> is disabled. | |
| 175 | * @throws IllegalStateException if the <code>JTree</code> is not showing on the screen. | |
| 176 | * @throws ComponentLookupException if a pop-up menu cannot be found. | |
| 177 | */ | |
| 178 | 1 |
public JPopupMenuFixture showPopupMenu() { |
| 179 | 1 | return tree.showPopupMenuAt(path); |
| 180 | } | |
| 181 | ||
| 182 | /** | |
| 183 | * Returns the <code>String</code> representation of this fixture's tree node. | |
| 184 | * @return the <code>String</code> representation of this fixture's tree node. | |
| 185 | */ | |
| 186 | 1 |
public String value() { |
| 187 | 1 | return tree.valueAt(path); |
| 188 | } | |
| 189 | ||
| 190 | /** | |
| 191 | * Returns the path of this fixture's node. | |
| 192 | * @return the path of this fixture's node. | |
| 193 | */ | |
| 194 | 1 |
public String path() { |
| 195 | 1 | return path; |
| 196 | } | |
| 197 | } | |
|
||||||||||||