Component Positions requirements
Issue by Florian SIMON from Thu, 28 Jan 2010 10:26:56 -0600 Originally opened as http://jira.codehaus.org/browse/FEST-298
Hi,
I have found many requirements which specify the location of a component.
Especially the position of each component related to those neighbours.
For instance, the component A is to the left of the component B.
It's the reason why I have added to the CommonComponentFixture many methods.
In Interface CommonComponentFixture :
public interface CommonComponentFixture extends FocusableComponentFixture, KeyboardInputSimulationFixture, MouseInputSimulationFixture, StateVerificationFixture, PositionVerificationFixture {}Create Interface PositionVerificationFixture
package org.fest.swing.fixture;
import java.awt.Component;
public interface PositionVerificationFixture {
PositionVerificationFixture requireLocatedOnScreen(<span class="code-object">int</span> x, <span class="code-object">int</span> y); PositionVerificationFixture requireNotLocatedOnScreen(<span class="code-object">int</span> x, <span class="code-object">int</span> y); PositionVerificationFixture requireAtTheTopOf(Component composant); PositionVerificationFixture requireToTheLeftOf(Component composant); PositionVerificationFixture requireToTheRightOf(Component composant);PositionVerificationFixture requireAtTheBottomOf(Component composant); }
Add this following methods in ComponentDriver
@RunsInEDT public void requireLocatedOnScreen(Component c, int x, int y) { assertThat(c.getLocationOnScreen().x == x && c.getLocationOnScreen().y == y).as(locationProperty(c)).isTrue(); }@RunsInEDT public void requireNotLocatedOnScreen(Component c, int x, int y) { assertThat(c.getLocationOnScreen().x == x && c.getLocationOnScreen().y == y).as(locationProperty(c)).isFalse(); }
@RunsInEDT public void requireAtTheTopOf(Component c, Component c2) { assertThat(c.getLocationOnScreen().y < c2.getLocationOnScreen().y ).as(locationProperty(c)).isTrue(); }
@RunsInEDT public void requireToTheLeftOf(Component c, Component c2) { assertThat(c.getLocationOnScreen().x < c2.getLocationOnScreen().x ).as(locationProperty(c)).isTrue(); }
@RunsInEDT public void requireToTheRightOf(Component c, Component c2) { assertThat(c.getLocationOnScreen().x > c2.getLocationOnScreen().x ).as(locationProperty(c)).isTrue(); }
@RunsInEDT public void requireAtTheBottomOf(Component c, Component c2) { assertThat(c.getLocationOnScreen().y > c2.getLocationOnScreen().y ).as(locationProperty(c)).isTrue(); }
@RunsInEDT private static Description locationProperty(Component c) { return propertyName(c, LOCATION_PROPERTY); }
In all classes which implement CommonComponentFixture
Ex : FrameFixture
public FrameFixture requireLocatedOnScreen(int x, int y) { this.driver.requireLocatedOnScreen(this.target, x, y); return this; }<span class="code-keyword">public</span> FrameFixture requireNotLocatedOnScreen(<span class="code-object">int</span> x, <span class="code-object">int</span> y) { <span class="code-keyword">this</span>.driver.requireNotLocatedOnScreen(<span class="code-keyword">this</span>.target, x, y); <span class="code-keyword">return</span> <span class="code-keyword">this</span>; } <span class="code-keyword">public</span> FrameFixture requireAtTheTopOf( Component component) { <span class="code-keyword">this</span>.driver.requireAtTheTopOf(<span class="code-keyword">this</span>.target, component); <span class="code-keyword">return</span> <span class="code-keyword">this</span>; } <span class="code-keyword">public</span> FrameFixture requireToTheLeftOf( Component component) { <span class="code-keyword">this</span>.driver.requireToTheLeftOf(<span class="code-keyword">this</span>.target, component); <span class="code-keyword">return</span> <span class="code-keyword">this</span>; } <span class="code-keyword">public</span> FrameFixture requireToTheRightOf( Component component) { <span class="code-keyword">this</span>.driver.requireToTheRightOf(<span class="code-keyword">this</span>.target, component); <span class="code-keyword">return</span> <span class="code-keyword">this</span>; } <span class="code-keyword">public</span> FrameFixture requireAtTheBottomOf( Component component) { <span class="code-keyword">this</span>.driver.requireAtTheBottomOf(<span class="code-keyword">this</span>.target, component); <span class="code-keyword">return</span> <span class="code-keyword">this</span>; }
Cheers
Florian
votes (original issue): 0 watches (original issue): 0