Skip to content

Commit 4572368

Browse files
committed
test for hasDifferentSizeAs
1 parent 919422e commit 4572368

File tree

2 files changed

+40
-9
lines changed

2 files changed

+40
-9
lines changed

src/test/java/rectangles/TestAssumptions.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,15 +267,27 @@ public static boolean haveEqualSize(List<WebElement> elements) {
267267
}
268268

269269
public static boolean hasDifferentSizeAs(WebElement root, WebElement other) {
270-
return validate(root, uiValidator -> uiValidator.hasDifferentSizeAs(other, "Blub"), 0);
270+
return hasDifferentSizeAs(root, other, 0);
271+
}
272+
273+
public static boolean hasDifferentSizeAs(WebElement root, WebElement other, int tolerance) {
274+
return validate(root, uiValidator -> uiValidator.hasDifferentSizeAs(other, "Blub"), tolerance);
271275
}
272276

273277
public static boolean hasDifferentSizeAs(WebElement root, List<WebElement> others) {
274-
return validate(root, uiValidator -> uiValidator.hasDifferentSizeAs(others), 0);
278+
return hasDifferentSizeAs(root, others, 0);
279+
}
280+
281+
public static boolean hasDifferentSizeAs(WebElement root, List<WebElement> others, int tolerance) {
282+
return validate(root, uiValidator -> uiValidator.hasDifferentSizeAs(others), tolerance);
275283
}
276284

277285
public static boolean haveDifferentSizes(List<WebElement> elements) {
278-
return validate(elements, ResponsiveUIChunkValidator::haveDifferentSizes, 0);
286+
return haveDifferentSizes(elements, 0);
287+
}
288+
289+
public static boolean haveDifferentSizes(List<WebElement> elements, int tolerance) {
290+
return validate(elements, ResponsiveUIChunkValidator::haveDifferentSizes, tolerance);
279291
}
280292

281293
public static boolean hasHeightBetween(WebElement root, int min, int max) {

src/test/java/rectangles/ToleranceOnNegativeAssumptionsTest.java

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
package rectangles;
22

3-
import com.google.common.collect.Lists;
43
import org.assertj.core.api.AbstractBooleanAssert;
54
import org.junit.Before;
65
import org.junit.Test;
76
import org.openqa.selenium.WebElement;
87

98
import static java.util.Arrays.asList;
109
import static org.assertj.core.api.Assertions.assertThat;
11-
import static rectangles.TestAssumptions.doNotOverlap;
12-
import static rectangles.TestAssumptions.isNotOverlapping;
10+
import static rectangles.TestAssumptions.*;
1311

1412
public class ToleranceOnNegativeAssumptionsTest {
1513

@@ -44,10 +42,31 @@ public void isNotOverlappingWithTolerance() {
4442
assertThatNotOverlappingWithTolerance(x, y-height+2).isFalse();
4543
}
4644

45+
@Test
46+
public void hasDifferentSizeAsWithTolerance() {
47+
assertThatHasDifferentSizeWithTolerance(-2, 0).isTrue();
48+
assertThatHasDifferentSizeWithTolerance(-1, 0).isFalse();
49+
assertThatHasDifferentSizeWithTolerance( 0, 0).isFalse();
50+
assertThatHasDifferentSizeWithTolerance(+1, 0).isFalse();
51+
assertThatHasDifferentSizeWithTolerance(0, +2).isTrue();
52+
assertThatHasDifferentSizeWithTolerance(0, -2).isTrue();
53+
assertThatHasDifferentSizeWithTolerance(0, -1).isFalse();
54+
assertThatHasDifferentSizeWithTolerance(0, +1).isFalse();
55+
assertThatHasDifferentSizeWithTolerance(0, +2).isTrue();
56+
}
57+
58+
public AbstractBooleanAssert<?> assertThatHasDifferentSizeWithTolerance(int deltaWidth, int deltaHeight) {
59+
WebElement element = DummyWebElement.createElement(x, y, x + width + deltaWidth, y + height + deltaHeight);
60+
return assertThat(hasDifferentSizeAs(root, element, 1) &&
61+
hasDifferentSizeAs(root, asList(element), 1) &&
62+
haveDifferentSizes(asList(root, element), 1));
63+
}
64+
4765
private AbstractBooleanAssert<?> assertThatNotOverlappingWithTolerance(int x, int y) {
48-
return assertThat(isNotOverlapping(root, createElement(x, y), 1) &&
49-
doNotOverlap(asList(root, createElement(x, y)), 1) &&
50-
isNotOverlapping(root, asList(createElement(x,y)), 1));
66+
WebElement element = createElement(x, y);
67+
return assertThat(isNotOverlapping(root, element, 1) &&
68+
doNotOverlap(asList(root, element), 1) &&
69+
isNotOverlapping(root, asList(element), 1));
5170
}
5271

5372

0 commit comments

Comments
 (0)