assertj / assertj/assertj-swing

Component Positions requirements

Open
#60 0 comments 0 reactions 0 assignees View on GitHub
import from fest-swing Major New Feature
Dominant language
Java
Stars
121
Forks
52
PR merge metrics
No merged PRs in 30d

Description

_Issue by **[Florian SIMON](http://jira.codehaus.org/secure/ViewProfile.jspa?name=florian_simon98)** 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(int x, int y);
PositionVerificationFixture requireNotLocatedOnScreen(int x, int 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;
}

public FrameFixture requireNotLocatedOnScreen(int x, int y) {
this.driver.requireNotLocatedOnScreen(this.target, x, y);
return this;
}

public FrameFixture requireAtTheTopOf(
Component component) {

this.driver.requireAtTheTopOf(this.target, component);
return this;
}

public FrameFixture requireToTheLeftOf(
Component component) {

this.driver.requireToTheLeftOf(this.target, component);
return this;
}

public FrameFixture requireToTheRightOf(
Component component) {

this.driver.requireToTheRightOf(this.target, component);
return this;
}

public FrameFixture requireAtTheBottomOf(
Component component) {

this.driver.requireAtTheBottomOf(this.target, component);
return this;
}


Cheers

Florian

---

votes (original issue): 0
watches (original issue): 0

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.