Skip to content

Commit 70bf46c

Browse files
committed
shared ChunkDefs and support for different find methods
1 parent 3ac9596 commit 70bf46c

File tree

7 files changed

+35
-153
lines changed

7 files changed

+35
-153
lines changed

src/main/java/net/itarray/automotion/validation/Chunk.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@
1515
public @interface Chunk {
1616
Element[] value() default {};
1717
String name() default "";
18-
String parameters() default "";
18+
String[] params() default {""};
19+
boolean oneOrMore() default false;
1920
}

src/main/java/net/itarray/automotion/validation/ChunkUIElementValidator.java

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,15 @@ public interface ChunkUIElementValidator {
3535
// ? filled needs to be expressed somehow
3636
// areAlignedInColumns(numberOfColumns)
3737
@ValidChunks({
38-
@Chunk(parameters = "3", name = "empty"),
39-
@Chunk(parameters = "1", name = "one element"),
40-
@Chunk(parameters = "3", name="three elements with different sizes in a row with different gutters"),
41-
@Chunk(parameters = "4", name="three elements with different sizes in a row with different gutters"),
42-
@Chunk(parameters = "3", name = "seven elements in three rows with different sizes and gutters"),
38+
@Chunk(name = "empty", params = {"3"}),
39+
@Chunk(name = "one element", params = {"1"}),
40+
@Chunk(name = "three elements with different sizes in a row with different gutters", params = {"3", "4"}),
41+
@Chunk(name = "seven elements in three rows with different sizes and gutters", params = {"3"}),
4342
})
4443
@InvalidChunks({
45-
@Chunk(parameters = "2", name="three elements with different sizes in a row with different gutters"),
46-
@Chunk(parameters = "2", name = "seven elements in three rows with different sizes and gutters"),
47-
@Chunk(parameters = "4", name = "seven elements in three rows with different sizes and gutters"),
44+
@Chunk(name = "empty", params = {"3"}, oneOrMore = true),
45+
@Chunk(name = "three elements with different sizes in a row with different gutters", params = {"2"}),
46+
@Chunk(name = "seven elements in three rows with different sizes and gutters", params = {"2", "4"}),
4847
})
4948
ChunkUIElementValidator alignedAsGrid(int horizontalGridSize);
5049

@@ -62,25 +61,23 @@ public interface ChunkUIElementValidator {
6261
@Chunk(name = "seven elements in three rows with different sizes and gutters"),
6362
})
6463
@InvalidChunks({
64+
@Chunk(name = "empty", oneOrMore = true),
6565
@Chunk(name = "two overlapping elements"),
6666
})
6767
ChunkUIElementValidator areAlignedAsGridCells();
6868

6969

7070
// area
7171
@ValidChunks({
72-
@Chunk(parameters = "1, 1", name = "one element"),
73-
@Chunk(parameters = "3, 1", name="three elements with different sizes in a row with different gutters"),
74-
@Chunk(parameters = "4, 1", name="three elements with different sizes in a row with different gutters"),
75-
@Chunk(parameters = "3, 3", name = "seven elements in three rows with different sizes and gutters"),
72+
@Chunk(name = "one element", params = {"1, 1"}),
73+
@Chunk(name = "three elements with different sizes in a row with different gutters", params = {"3, 1", "4, 1"}),
74+
@Chunk(name = "seven elements in three rows with different sizes and gutters", params = {"3, 3"}),
7675
})
7776
@InvalidChunks({
78-
@Chunk(parameters = "3, 3", name = "empty"),
79-
@Chunk(parameters = "3, 2", name="three elements with different sizes in a row with different gutters"),
80-
@Chunk(parameters = "4, 2", name="three elements with different sizes in a row with different gutters"),
81-
@Chunk(parameters = "3, 2", name = "seven elements in three rows with different sizes and gutters"),
82-
@Chunk(parameters = "3, 4", name = "seven elements in three rows with different sizes and gutters"),
83-
@Chunk(parameters = "4, 1", name = "seven elements in three rows with different sizes and gutters"),
77+
@Chunk(name = "empty", params = {"3, 3"}, oneOrMore = true),
78+
@Chunk(name = "empty", params = {"3, 3"}),
79+
@Chunk(name = "three elements with different sizes in a row with different gutters", params = {"3, 2", "4, 2"}),
80+
@Chunk(name = "seven elements in three rows with different sizes and gutters", params = {"3, 2", "3, 4", "4, 1"}),
8481
})
8582
ChunkUIElementValidator alignedAsGrid(int horizontalGridSize, int verticalGridSize);
8683

src/test/java/net/itarray/automotion/tests/grid/AllowEmpty.java

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/test/java/net/itarray/automotion/tests/grid/AnnotatedSpecificationTest.java

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import static rectangles.DummyWebElement.createElement;
3131

3232
@RunWith(Parameterized.class)
33-
@PageSize
3433
public class AnnotatedSpecificationTest {
3534

3635
protected ChunkUIElementValidator chunkValidator;
@@ -39,18 +38,14 @@ public class AnnotatedSpecificationTest {
3938
public void setUp() {
4039
DummyDriverFacade driverFacade = new DummyDriverFacade();
4140

42-
PageSize pageSize = getClass().getAnnotation(PageSize.class);
43-
driverFacade.setPageSize(new Dimension(pageSize.xy()[0], pageSize.xy()[1]));
41+
driverFacade.setPageSize(new Dimension(2000, 1000));
4442

4543
ResponsiveUIValidator uiValidator = new ResponsiveUIValidator(driverFacade);
4644
UISnapshot snapshot = uiValidator.snapshot();
4745

4846
List<WebElement> webElements = chunk;
49-
boolean allowEmpty = true;
5047
chunkValidator =
51-
allowEmpty ?
52-
snapshot.findZeroOrMoreElements(webElements) :
53-
snapshot.findElements(webElements);
48+
this.oneOrMore ? snapshot.findElements(webElements) : snapshot.findZeroOrMoreElements(webElements);
5449
}
5550

5651
public static List<WebElement> toWebElements(Chunk chunk) {
@@ -77,19 +72,23 @@ public static Collection<Object[]> data() {
7772
ValidChunks validChunks = method.getAnnotation(ValidChunks.class);
7873
if (validChunks != null) {
7974
for (Chunk chunk : validChunks.value()) {
80-
String name = String.format("%s(%s) is valid on %s chunk", method.getName(), chunk.parameters(), chunk.name());
81-
Optional<List<WebElement>> repositoryChunk = repository.getChunk(chunk.name());
82-
List<WebElement> webElements = repositoryChunk.orElse(toWebElements(chunk));
83-
result.add(new Object[]{method, webElements, name, true, parseArgs(chunk.parameters())});
75+
for (String parameters : chunk.params()) {
76+
String name = String.format("%s(%s) is valid on %s chunk", method.getName(), parameters, chunk.name());
77+
Optional<List<WebElement>> repositoryChunk = repository.getChunk(chunk.name());
78+
List<WebElement> webElements = repositoryChunk.orElse(toWebElements(chunk));
79+
result.add(new Object[]{method, webElements, name, true, parseArgs(parameters), chunk.oneOrMore()});
80+
}
8481
}
8582
}
8683
InvalidChunks invalidChunks = method.getAnnotation(InvalidChunks.class);
8784
if (invalidChunks != null) {
8885
for (Chunk chunk : invalidChunks.value()) {
89-
String name = String.format("%s(%s) is not valid on %s chunk", method.getName(), chunk.parameters(), chunk.name());
90-
Optional<List<WebElement>> repositoryChunk = repository.getChunk(chunk.name());
91-
List<WebElement> webElements = repositoryChunk.orElse(toWebElements(chunk));
92-
result.add(new Object[]{method, webElements, name, false, parseArgs(chunk.parameters())});
86+
for (String parameters : chunk.params()) {
87+
String name = String.format("%s(%s) is not valid on %s chunk", method.getName(), parameters, chunk.name());
88+
Optional<List<WebElement>> repositoryChunk = repository.getChunk(chunk.name());
89+
List<WebElement> webElements = repositoryChunk.orElse(toWebElements(chunk));
90+
result.add(new Object[]{method, webElements, name, false, parseArgs(parameters), chunk.oneOrMore()});
91+
}
9392
}
9493
}
9594
}
@@ -121,6 +120,10 @@ public static Object[] parseArgs(String parameters1) {
121120
@Parameter(4)
122121
public Object[] arguments;
123122

123+
@Parameter(5)
124+
public boolean oneOrMore;
125+
126+
124127
@Test
125128
public void valid() {
126129
try {

src/test/java/net/itarray/automotion/tests/grid/ChunkTest.java

Lines changed: 0 additions & 62 deletions
This file was deleted.

src/test/java/net/itarray/automotion/tests/grid/NoElementsWithFindOneOrMoreTest.java

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/test/java/net/itarray/automotion/tests/grid/PageSize.java

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)