Skip to content

Commit b42c6fc

Browse files
committed
Improved specification annotation naming and used chunk ids for references
1 parent 70bf46c commit b42c6fc

File tree

8 files changed

+132
-99
lines changed

8 files changed

+132
-99
lines changed
Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package net.itarray.automotion.validation;
22

3-
import net.itarray.automotion.validation.Element;
4-
53
import java.lang.annotation.ElementType;
64
import java.lang.annotation.Inherited;
75
import java.lang.annotation.Retention;
@@ -13,8 +11,7 @@
1311
@Retention(RetentionPolicy.RUNTIME)
1412
@Inherited
1513
public @interface Chunk {
16-
Element[] value() default {};
17-
String name() default "";
18-
String[] params() default {""};
19-
boolean oneOrMore() default false;
14+
Element[] elements() default {};
15+
String description() default "";
16+
String id();
2017
}

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

Lines changed: 86 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,27 @@
22

33
import org.openqa.selenium.WebElement;
44

5-
@ChunkDefs({
6-
@ChunkDef(name = "empty", value={
5+
@Chunks({
6+
@Chunk(id = "empty",
7+
description = "empty", elements ={
78
}),
8-
@ChunkDef(name = "one element", value={
9+
@Chunk(id = "one",
10+
description = "one element", elements ={
911
@Element({10, 20, 40, 50})
1012
}),
11-
@ChunkDef(name = "two overlapping elements", value={
13+
@Chunk(id = "two_overlapping",
14+
description = "two overlapping elements", elements ={
1215
@Element({10, 20, 30, 35}),
1316
@Element({15, 25, 35, 50}),
1417
}),
15-
@ChunkDef(name="three elements with different sizes in a row with different gutters", value={
18+
@Chunk(id = "three",
19+
description ="three elements with different sizes in a row with different gutters", elements ={
1620
@Element({100, 50, 300, 60}),
1721
@Element({400, 50, 700, 60}),
1822
@Element({900, 50, 1200, 60}),
1923
}),
20-
@ChunkDef(name="seven elements in three rows with different sizes and gutters", value={
24+
@Chunk(id = "seven",
25+
description ="seven elements in three rows with different sizes and gutters", elements ={
2126
@Element({100, 50, 300, 60}),
2227
@Element({400, 50, 700, 70}),
2328
@Element({900, 50, 1200, 80}),
@@ -34,16 +39,16 @@ public interface ChunkUIElementValidator {
3439

3540
// ? filled needs to be expressed somehow
3641
// areAlignedInColumns(numberOfColumns)
37-
@ValidChunks({
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"}),
42+
@Valid({
43+
@Scenario(chunk = "empty", params = {"3"}),
44+
@Scenario(chunk = "one", params = {"1"}),
45+
@Scenario(chunk = "three", params = {"3", "4"}),
46+
@Scenario(chunk = "seven", params = {"3"}),
4247
})
43-
@InvalidChunks({
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"}),
48+
@NotValid({
49+
@Scenario(chunk = "empty", params = {"3"}, oneOrMore = true),
50+
@Scenario(chunk = "three", params = {"2"}),
51+
@Scenario(chunk = "seven", params = {"2", "4"}),
4752
})
4853
ChunkUIElementValidator alignedAsGrid(int horizontalGridSize);
4954

@@ -55,29 +60,29 @@ public interface ChunkUIElementValidator {
5560
*
5661
* @return this
5762
*/
58-
@ValidChunks({
59-
@Chunk(name = "empty"),
60-
@Chunk(name = "single element"),
61-
@Chunk(name = "seven elements in three rows with different sizes and gutters"),
63+
@Valid({
64+
@Scenario(chunk = "empty"),
65+
@Scenario(chunk = "one"),
66+
@Scenario(chunk = "seven"),
6267
})
63-
@InvalidChunks({
64-
@Chunk(name = "empty", oneOrMore = true),
65-
@Chunk(name = "two overlapping elements"),
68+
@NotValid({
69+
@Scenario(chunk = "empty", oneOrMore = true),
70+
@Scenario(chunk = "two_overlapping"),
6671
})
6772
ChunkUIElementValidator areAlignedAsGridCells();
6873

6974

7075
// area
71-
@ValidChunks({
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"}),
76+
@Valid({
77+
@Scenario(chunk = "one", params = {"1, 1"}),
78+
@Scenario(chunk = "three", params = {"3, 1", "4, 1"}),
79+
@Scenario(chunk = "seven", params = {"3, 3"}),
7580
})
76-
@InvalidChunks({
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"}),
81+
@NotValid({
82+
@Scenario(chunk = "empty", params = {"3, 3"}, oneOrMore = true),
83+
@Scenario(chunk = "empty", params = {"3, 3"}),
84+
@Scenario(chunk = "three", params = {"3, 2", "4, 2"}),
85+
@Scenario(chunk = "seven", params = {"3, 2", "3, 4", "4, 1"}),
8186
})
8287
ChunkUIElementValidator alignedAsGrid(int horizontalGridSize, int verticalGridSize);
8388

@@ -86,29 +91,71 @@ public interface ChunkUIElementValidator {
8691

8792
// size
8893

94+
@Valid({
95+
@Scenario(chunk = "empty"),
96+
@Scenario(chunk = "one"),
97+
})
98+
@NotValid({
99+
@Scenario(chunk = "empty", oneOrMore = true),
100+
})
89101
ChunkUIElementValidator haveEqualSize();
102+
@Valid({
103+
@Scenario(chunk = "empty"),
104+
@Scenario(chunk = "one"),
105+
})
106+
@NotValid({
107+
@Scenario(chunk = "empty", oneOrMore = true),
108+
})
90109
ChunkUIElementValidator haveEqualWidth();
110+
@Valid({
111+
@Scenario(chunk = "empty"),
112+
@Scenario(chunk = "one"),
113+
})
114+
@NotValid({
115+
@Scenario(chunk = "empty", oneOrMore = true),
116+
})
91117
ChunkUIElementValidator haveEqualHeight();
118+
@Valid({
119+
@Scenario(chunk = "empty"),
120+
@Scenario(chunk = "one"),
121+
})
122+
@NotValid({
123+
@Scenario(chunk = "empty", oneOrMore = true),
124+
})
92125
ChunkUIElementValidator haveDifferentSizes();
126+
@Valid({
127+
@Scenario(chunk = "empty"),
128+
@Scenario(chunk = "one"),
129+
})
130+
@NotValid({
131+
@Scenario(chunk = "empty", oneOrMore = true),
132+
})
93133
ChunkUIElementValidator haveDifferentWidths();
134+
@Valid({
135+
@Scenario(chunk = "empty"),
136+
@Scenario(chunk = "one"),
137+
})
138+
@NotValid({
139+
@Scenario(chunk = "empty", oneOrMore = true),
140+
})
94141
ChunkUIElementValidator haveDifferentHeights();
95142

96143
// alignment
97144

98-
@ValidChunks({
99-
@Chunk(name = "one element"),
145+
@Valid({
146+
@Scenario(chunk = "one"),
100147
})
101148
ChunkUIElementValidator areLeftAligned();
102-
@ValidChunks({
103-
@Chunk(name = "one element"),
149+
@Valid({
150+
@Scenario(chunk = "one"),
104151
})
105152
ChunkUIElementValidator areRightAligned();
106-
@ValidChunks({
107-
@Chunk(name = "one element"),
153+
@Valid({
154+
@Scenario(chunk = "one"),
108155
})
109156
ChunkUIElementValidator areTopAligned();
110-
@ValidChunks({
111-
@Chunk(name = "one element"),
157+
@Valid({
158+
@Scenario(chunk = "one"),
112159
})
113160
ChunkUIElementValidator areBottomAligned();
114161

src/main/java/net/itarray/automotion/validation/ValidChunks.java renamed to src/main/java/net/itarray/automotion/validation/Chunks.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
import java.lang.annotation.Target;
88

99

10-
@Target(ElementType.METHOD)
10+
@Target(ElementType.TYPE)
1111
@Retention(RetentionPolicy.RUNTIME)
1212
@Inherited
13-
public @interface ValidChunks {
13+
public @interface Chunks {
1414
Chunk[] value() default {};
1515
}

src/main/java/net/itarray/automotion/validation/InvalidChunks.java renamed to src/main/java/net/itarray/automotion/validation/NotValid.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
@Target(ElementType.METHOD)
1111
@Retention(RetentionPolicy.RUNTIME)
1212
@Inherited
13-
public @interface InvalidChunks {
14-
Chunk[] value() default {};
13+
public @interface NotValid {
14+
Scenario[] value() default {};
1515
}

src/main/java/net/itarray/automotion/validation/ChunkDef.java renamed to src/main/java/net/itarray/automotion/validation/Scenario.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package net.itarray.automotion.validation;
22

3+
import net.itarray.automotion.validation.Element;
4+
35
import java.lang.annotation.ElementType;
46
import java.lang.annotation.Inherited;
57
import java.lang.annotation.Retention;
@@ -10,7 +12,8 @@
1012
@Target(ElementType.TYPE)
1113
@Retention(RetentionPolicy.RUNTIME)
1214
@Inherited
13-
public @interface ChunkDef {
14-
Element[] value() default {};
15-
String name() default "";
15+
public @interface Scenario {
16+
String chunk() default "";
17+
String[] params() default {""};
18+
boolean oneOrMore() default false;
1619
}

src/main/java/net/itarray/automotion/validation/ChunkDefs.java renamed to src/main/java/net/itarray/automotion/validation/Valid.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
import java.lang.annotation.Target;
88

99

10-
@Target(ElementType.TYPE)
10+
@Target(ElementType.METHOD)
1111
@Retention(RetentionPolicy.RUNTIME)
1212
@Inherited
13-
public @interface ChunkDefs {
14-
ChunkDef[] value() default {};
13+
public @interface Valid {
14+
Scenario[] value() default {};
1515
}

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

Lines changed: 17 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22

33
import com.google.common.collect.Lists;
44
import net.itarray.automotion.internal.ResponsiveUIValidatorBase;
5-
import net.itarray.automotion.validation.Chunk;
5+
import net.itarray.automotion.validation.Scenario;
66
import net.itarray.automotion.validation.ChunkUIElementValidator;
7-
import net.itarray.automotion.validation.Element;
8-
import net.itarray.automotion.validation.InvalidChunks;
7+
import net.itarray.automotion.validation.NotValid;
98
import net.itarray.automotion.validation.ResponsiveUIValidator;
109
import net.itarray.automotion.validation.UISnapshot;
11-
import net.itarray.automotion.validation.ValidChunks;
10+
import net.itarray.automotion.validation.Valid;
1211
import org.junit.Before;
1312
import org.junit.Test;
1413
import org.junit.runner.RunWith;
@@ -23,7 +22,6 @@
2322
import java.lang.reflect.Method;
2423
import java.util.Collection;
2524
import java.util.List;
26-
import java.util.Optional;
2725

2826
import static com.google.common.collect.Lists.newArrayList;
2927
import static org.assertj.core.api.Assertions.assertThat;
@@ -48,19 +46,6 @@ public void setUp() {
4846
this.oneOrMore ? snapshot.findElements(webElements) : snapshot.findZeroOrMoreElements(webElements);
4947
}
5048

51-
public static List<WebElement> toWebElements(Chunk chunk) {
52-
List<WebElement> webElements = newArrayList();
53-
for (Element element : chunk.value()) {
54-
webElements.add(createElement(
55-
element.value()[0],
56-
element.value()[1],
57-
element.value()[2],
58-
element.value()[3]
59-
));
60-
}
61-
return webElements;
62-
}
63-
6449
@Parameters(name = "{2}")
6550
public static Collection<Object[]> data() {
6651

@@ -69,25 +54,23 @@ public static Collection<Object[]> data() {
6954

7055
Collection<Object[]> result = Lists.newArrayList();
7156
for (Method method : ChunkUIElementValidator.class.getDeclaredMethods()) {
72-
ValidChunks validChunks = method.getAnnotation(ValidChunks.class);
73-
if (validChunks != null) {
74-
for (Chunk chunk : validChunks.value()) {
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()});
57+
Valid valid = method.getAnnotation(Valid.class);
58+
if (valid != null) {
59+
for (Scenario scenario : valid.value()) {
60+
for (String parameters : scenario.params()) {
61+
String name = String.format("%s(%s) is valid on %s chunk", method.getName(), parameters, scenario.chunk());
62+
List<WebElement> webElements = repository.get(scenario.chunk());
63+
result.add(new Object[]{method, webElements, name, true, parseArgs(parameters), scenario.oneOrMore()});
8064
}
8165
}
8266
}
83-
InvalidChunks invalidChunks = method.getAnnotation(InvalidChunks.class);
84-
if (invalidChunks != null) {
85-
for (Chunk chunk : invalidChunks.value()) {
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()});
67+
NotValid notValid = method.getAnnotation(NotValid.class);
68+
if (notValid != null) {
69+
for (Scenario scenario : notValid.value()) {
70+
for (String parameters : scenario.params()) {
71+
String name = String.format("%s(%s) is not valid on %s chunk", method.getName(), parameters, scenario.chunk());
72+
List<WebElement> webElements = repository.get(scenario.chunk());
73+
result.add(new Object[]{method, webElements, name, false, parseArgs(parameters), scenario.oneOrMore()});
9174
}
9275
}
9376
}

0 commit comments

Comments
 (0)