Skip to content

Commit 102ddc4

Browse files
committed
moved line drawing to context
1 parent da6b1be commit 102ddc4

File tree

4 files changed

+62
-59
lines changed

4 files changed

+62
-59
lines changed

src/main/java/net/itarray/automotion/internal/ResponsiveUIChunkValidatorBase.java

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -324,64 +324,68 @@ private void validateGridAlignment(List<UIElement> elements, int columns, int ro
324324
}
325325

326326
private void validateRightAlignedWithChunk(List<UIElement> elements) {
327+
Context context = getContext();
327328
if (!elements.isEmpty()) {
328-
int oldErrorsSize = getContext().errorCount();
329+
int oldErrorsSize = context.errorCount();
329330
int pickedIndex = 0;
330331
UIElement element = elements.get(pickedIndex);
331332
for (int i = 0; i < elements.size(); i++) {
332333
if (i != pickedIndex) {
333334
UIElement elementToCompare = elements.get(i);
334-
element.validateRightAlignedWith(elementToCompare, getContext());
335+
element.validateRightAlignedWith(elementToCompare, context);
335336
}
336337
}
337-
if (getContext().errorCount() != oldErrorsSize) {
338+
if (context.errorCount() != oldErrorsSize) {
338339
Vector onLine = elements.get(pickedIndex).getCorner();
339-
drawVerticalLine(onLine);
340+
context.drawVerticalLine(onLine);
340341
}
341342
}
342343
}
343344

344345
private void validateLeftAlignedWithChunk(List<UIElement> elements) {
346+
Context context = getContext();
345347
if (!elements.isEmpty()) {
346-
int oldErrorsSize = getContext().errorCount();
348+
int oldErrorsSize = context.errorCount();
347349
int pickedIndex = 0;
348350
UIElement element = elements.get(pickedIndex);
349351
for (int i = 0; i < elements.size(); i++) {
350352
UIElement elementToCompare = elements.get(i);
351-
element.validateLeftAlignedWith(elementToCompare, getContext());
353+
element.validateLeftAlignedWith(elementToCompare, context);
352354
}
353-
if (getContext().errorCount() != oldErrorsSize) {
354-
drawVerticalLine(elements.get(pickedIndex).getOrigin());
355+
if (context.errorCount() != oldErrorsSize) {
356+
context.drawVerticalLine(elements.get(pickedIndex).getOrigin());
355357
}
356358
}
357359
}
358360

359361
private void validateTopAlignedWithChunk(List<UIElement> elements) {
362+
Context context = getContext();
360363
if (!elements.isEmpty()) {
361-
int oldErrorsSize = getContext().errorCount();
364+
int oldErrorsSize = context.errorCount();
362365
int pickedIndex = 0;
363366
UIElement element = elements.get(pickedIndex);
364367
for (int i = 0; i < elements.size(); i++) {
365368
UIElement elementToCompare = elements.get(i);
366-
element.validateTopAlignedWith(elementToCompare, getContext());
369+
element.validateTopAlignedWith(elementToCompare, context);
367370
}
368-
if (getContext().errorCount() != oldErrorsSize) {
369-
drawHorizontalLine(elements.get(pickedIndex).getOrigin());
371+
if (context.errorCount() != oldErrorsSize) {
372+
context.drawHorizontalLine(elements.get(pickedIndex).getOrigin());
370373
}
371374
}
372375
}
373376

374377
private void validateBottomAlignedWithChunk(List<UIElement> elements) {
378+
Context context = getContext();
375379
if (!elements.isEmpty()) {
376-
int oldErrorsSize = getContext().errorCount();
380+
int oldErrorsSize = context.errorCount();
377381
int pickedIndex = 0;
378382
UIElement element = elements.get(pickedIndex);
379383
for (int i = 0; i < elements.size(); i++) {
380384
UIElement elementToCompare = elements.get(i);
381-
element.validateBottomAlignedWith(elementToCompare, getContext());
385+
element.validateBottomAlignedWith(elementToCompare, context);
382386
}
383-
if (getContext().errorCount() != oldErrorsSize) {
384-
drawHorizontalLine(elements.get(pickedIndex).getCorner());
387+
if (context.errorCount() != oldErrorsSize) {
388+
context.drawHorizontalLine(elements.get(pickedIndex).getCorner());
385389
}
386390
}
387391
}

src/main/java/net/itarray/automotion/internal/ResponsiveUIValidatorBase.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,20 @@ public void draw(UIElement element) {
135135
errors.draw(element);
136136
}
137137

138+
@Override
139+
public void drawHorizontalLine(Vector onLine) {
140+
if (isWithReport()) {
141+
getDrawableScreenshot().drawHorizontalLine(onLine.getY());
142+
}
143+
}
144+
145+
@Override
146+
public void drawVerticalLine(Vector onLine) {
147+
if (isWithReport()) {
148+
getDrawableScreenshot().drawVerticalLine(onLine.getX());
149+
}
150+
}
151+
138152
@Override
139153
public int errorCount() {
140154
return errors.getMessages().size();
@@ -260,18 +274,6 @@ public DrawingConfiguration getDrawingConfiguration() {
260274
return getReport().getDrawingConfiguration();
261275
}
262276

263-
protected void drawHorizontalLine(Vector onLine) {
264-
if (isWithReport()) {
265-
getDrawableScreenshot().drawHorizontalLine(onLine.getY());
266-
}
267-
}
268-
269-
protected void drawVerticalLine(Vector onLine) {
270-
if (isWithReport()) {
271-
getDrawableScreenshot().drawVerticalLine(onLine.getX());
272-
}
273-
}
274-
275277
protected void drawElement(UIElement element) {
276278
getDrawableScreenshot().drawRootElement(element);
277279
}

src/main/java/net/itarray/automotion/internal/UIValidatorBase.java

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import net.itarray.automotion.internal.geometry.Direction;
44
import net.itarray.automotion.internal.geometry.Scalar;
5+
import net.itarray.automotion.internal.properties.Context;
56
import net.itarray.automotion.internal.properties.PixelConstant;
67
import net.itarray.automotion.validation.UIElementValidator;
78
import net.itarray.automotion.validation.UISnapshot;
@@ -194,8 +195,9 @@ public UIValidatorBase isNotOverlapping(List<WebElement> elements) {
194195
*/
195196
@Override
196197
public UIValidatorBase isLeftAlignedWith(WebElement element, String readableName) {
197-
rootElement.validateLeftAlignedWith(asElement(element, readableName), getContext());
198-
drawLeftOffsetLine();
198+
Context context = getContext();
199+
rootElement.validateLeftAlignedWith(asElement(element, readableName), context);
200+
context.drawVerticalLine(rootElement.getOrigin());
199201
return this;
200202
}
201203

@@ -207,10 +209,11 @@ public UIValidatorBase isLeftAlignedWith(WebElement element, String readableName
207209
*/
208210
@Override
209211
public UIValidatorBase isLeftAlignedWith(List<WebElement> webElements) {
212+
Context context = getContext();
210213
for (UIElement element : asElements(webElements)) {
211-
rootElement.validateLeftAlignedWith(element, getContext());
214+
rootElement.validateLeftAlignedWith(element, context);
212215
}
213-
drawLeftOffsetLine();
216+
context.drawVerticalLine(rootElement.getOrigin());
214217
return this;
215218
}
216219

@@ -223,8 +226,9 @@ public UIValidatorBase isLeftAlignedWith(List<WebElement> webElements) {
223226
*/
224227
@Override
225228
public UIValidatorBase isRightAlignedWith(WebElement element, String readableName) {
226-
rootElement.validateRightAlignedWith(asElement(element, readableName), getContext());
227-
drawRightOffsetLine();
229+
Context context = getContext();
230+
rootElement.validateRightAlignedWith(asElement(element, readableName), context);
231+
context.drawVerticalLine(rootElement.getCorner());
228232
return this;
229233
}
230234

@@ -236,10 +240,11 @@ public UIValidatorBase isRightAlignedWith(WebElement element, String readableNam
236240
*/
237241
@Override
238242
public UIValidatorBase isRightAlignedWith(List<WebElement> elements) {
243+
Context context = getContext();
239244
for (WebElement element : elements) {
240-
rootElement.validateRightAlignedWith(asElement(element), getContext());
245+
rootElement.validateRightAlignedWith(asElement(element), context);
241246
}
242-
drawRightOffsetLine();
247+
context.drawVerticalLine(rootElement.getCorner());
243248
return this;
244249
}
245250

@@ -252,8 +257,9 @@ public UIValidatorBase isRightAlignedWith(List<WebElement> elements) {
252257
*/
253258
@Override
254259
public UIValidatorBase isTopAlignedWith(WebElement element, String readableName) {
255-
rootElement.validateTopAlignedWith(asElement(element, readableName), getContext());
256-
drawTopOffsetLine();
260+
Context context = getContext();
261+
rootElement.validateTopAlignedWith(asElement(element, readableName), context);
262+
context.drawHorizontalLine(rootElement.getOrigin());
257263
return this;
258264
}
259265

@@ -265,10 +271,11 @@ public UIValidatorBase isTopAlignedWith(WebElement element, String readableName)
265271
*/
266272
@Override
267273
public UIValidatorBase isTopAlignedWith(List<WebElement> elements) {
274+
Context context = getContext();
268275
for (WebElement element : elements) {
269-
rootElement.validateTopAlignedWith(asElement(element), getContext());
276+
rootElement.validateTopAlignedWith(asElement(element), context);
270277
}
271-
drawTopOffsetLine();
278+
context.drawHorizontalLine(rootElement.getOrigin());
272279
return this;
273280
}
274281

@@ -281,8 +288,9 @@ public UIValidatorBase isTopAlignedWith(List<WebElement> elements) {
281288
*/
282289
@Override
283290
public UIValidatorBase isBottomAlignedWith(WebElement element, String readableName) {
284-
rootElement.validateBottomAlignedWith(asElement(element, readableName), getContext());
285-
drawBottomOffsetLine();
291+
Context context = getContext();
292+
rootElement.validateBottomAlignedWith(asElement(element, readableName), context);
293+
context.drawHorizontalLine(rootElement.getCorner());
286294
return this;
287295
}
288296

@@ -294,10 +302,11 @@ public UIValidatorBase isBottomAlignedWith(WebElement element, String readableNa
294302
*/
295303
@Override
296304
public UIValidatorBase isBottomAlignedWith(List<WebElement> elements) {
305+
Context context = getContext();
297306
for (WebElement element : elements) {
298-
rootElement.validateBottomAlignedWith(asElement(element), getContext());
307+
rootElement.validateBottomAlignedWith(asElement(element), context);
299308
}
300-
drawBottomOffsetLine();
309+
context.drawHorizontalLine(rootElement.getCorner());
301310
return this;
302311
}
303312

@@ -592,19 +601,4 @@ protected void drawRootElement() {
592601
drawElement(rootElement);
593602
}
594603

595-
private void drawLeftOffsetLine() {
596-
drawVerticalLine(rootElement.getOrigin());
597-
}
598-
599-
private void drawRightOffsetLine() {
600-
drawVerticalLine(rootElement.getCorner());
601-
}
602-
603-
private void drawTopOffsetLine() {
604-
drawHorizontalLine(rootElement.getOrigin());
605-
}
606-
607-
private void drawBottomOffsetLine() {
608-
drawHorizontalLine(rootElement.getCorner());
609-
}
610604
}

src/main/java/net/itarray/automotion/internal/properties/Context.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33
import net.itarray.automotion.internal.UIElement;
44
import net.itarray.automotion.internal.geometry.Rectangle;
55
import net.itarray.automotion.internal.geometry.Scalar;
6+
import net.itarray.automotion.internal.geometry.Vector;
67

78
public interface Context {
89
Rectangle getPageRectangle();
910
default boolean isPixels() { return false; }
1011
Scalar getTolerance();
1112
default void add(String message) {}
1213
default void draw(UIElement element) {}
14+
default void drawHorizontalLine(Vector onLine) {}
15+
default void drawVerticalLine(Vector onLine) {}
1316
int errorCount();
1417
}

0 commit comments

Comments
 (0)