How to use sides method of com.galenframework.tests.speclang2.SpecsReaderV2Test class

Best Galen code snippet using com.galenframework.tests.speclang2.SpecsReaderV2Test.sides

Source:SpecsReaderV2Test.java Github

copy

Full Screen

...73 assertThat(specInside.getObject(), is("object"));74 assertThat(specInside.getPartly(), is(false));75 List<Location> locations = specInside.getLocations();76 assertThat(locations.size(), is(1));77 assertThat(specInside.getLocations(), contains(new Location(Range.exact(10), sides(RIGHT))));78 assertThat(spec.getOriginalText(), is("inside object 10px right"));79 }80 @Test81 public void shouldReadSpec_inside_partly_object_10px_right() {82 Spec spec = readSpec("inside partly object 10px right");83 SpecInside specInside = (SpecInside) spec;84 assertThat(specInside.getObject(), is("object"));85 assertThat(specInside.getPartly(), is(true));86 List<Location> locations = specInside.getLocations();87 assertThat(locations.size(), is(1));88 assertThat(specInside.getLocations(), contains(new Location(Range.exact(10), sides(RIGHT))));89 assertThat(spec.getOriginalText(), is("inside partly object 10px right"));90 }91 @Test92 public void shouldReadSpec_inside_object_10_to_30px_left() {93 Spec spec = readSpec("inside object 10 to 30px left");94 SpecInside specInside = (SpecInside) spec;95 assertThat(specInside.getObject(), is("object"));96 List<Location> locations = specInside.getLocations();97 assertThat(locations.size(), is(1));98 assertThat(specInside.getLocations(), contains(new Location(Range.between(10, 30), sides(LEFT))));99 assertThat(spec.getOriginalText(), is("inside object 10 to 30px left"));100 }101 @Test102 public void shouldReadSpec_inside_object_25px_top_left() {103 SpecInside spec = (SpecInside)readSpec("inside object 25px top left");104 List<Location> locations = spec.getLocations();105 assertThat(locations.size(), is(1));106 assertThat(spec.getLocations(), contains(new Location(Range.exact(25), sides(TOP, LEFT))));107 assertThat(spec.getOriginalText(), is("inside object 25px top left"));108 }109 @Test110 public void shouldReadSpec_inside_object_25px_top_left_comma_10_to_20px_bottom() {111 SpecInside spec = (SpecInside)readSpec("inside object 25px top left, 10 to 20px bottom");112 List<Location> locations = spec.getLocations();113 assertThat(locations.size(), is(2));114 assertThat(spec.getLocations(), contains(new Location(Range.exact(25),sides(TOP, LEFT)),115 new Location(Range.between(10, 20), sides(BOTTOM))));116 assertThat(spec.getOriginalText(), is("inside object 25px top left, 10 to 20px bottom"));117 }118 @Test119 public void shouldReadSpec_inside_object_25px_bottom_right() {120 SpecInside spec = (SpecInside)readSpec("inside object 25px bottom right");121 List<Location> locations = spec.getLocations();122 assertThat(locations.size(), is(1));123 assertThat(spec.getLocations(), contains(new Location(Range.exact(25),sides(BOTTOM, RIGHT))));124 assertThat(spec.getOriginalText(), is("inside object 25px bottom right"));125 }126 @Test127 public void shouldReadSpec_inside_object_25px_top_left_right_bottom() {128 SpecInside spec = (SpecInside)readSpec("inside object 25px top left right bottom ");129 List<Location> locations = spec.getLocations();130 assertThat(locations.size(), is(1));131 assertThat(spec.getLocations(), contains(new Location(Range.exact(25), sides(TOP, LEFT, RIGHT, BOTTOM))));132 assertThat(spec.getOriginalText(), is("inside object 25px top left right bottom"));133 }134 @Test public void shouldReadSpec_inside_object_20px_left_and_approximate_30px_top() {135 SpecInside spec = (SpecInside)readSpec("inside object 20px left, ~30px top");136 List<Location> locations = spec.getLocations();137 assertThat(locations.size(), is(2));138 Assert.assertEquals(new Location(Range.exact(20), sides(LEFT)), spec.getLocations().get(0));139 Assert.assertEquals(new Location(Range.between(28, 32), sides(TOP)), spec.getLocations().get(1));140 assertThat(spec.getOriginalText(), is("inside object 20px left, ~30px top"));141 }142 @Test(expectedExceptions = SyntaxException.class,143 expectedExceptionsMessageRegExp = "Missing object name")144 public void shouldGiveError_inside_withoutObjects() {145 readSpec("inside");146 }147 @Test(expectedExceptions = SyntaxException.class,148 expectedExceptionsMessageRegExp = "Missing object name")149 public void shouldGiveError_inside_partly_withoutObjects() {150 readSpec("inside partly");151 }152 @Test153 public void shouldReadSpec_contains() {154 Spec spec = readSpec("contains object, menu, button");155 SpecContains specContains = (SpecContains) spec;156 assertThat(specContains.getChildObjects(), contains("object", "menu", "button"));157 assertThat(spec.getOriginalText(), is("contains object, menu, button"));158 }159 @Test160 public void shouldReadSpec_contains_with_regex() {161 Spec spec = readSpec("contains menu-item-*");162 SpecContains specContains = (SpecContains) spec;163 assertThat(specContains.getChildObjects(), contains("menu-item-*"));164 assertThat(spec.getOriginalText(), is("contains menu-item-*"));165 }166 @Test167 public void shouldReadSpec_contains_partly() {168 Spec spec = readSpec("contains partly object, menu, button");169 SpecContains specContains = (SpecContains) spec;170 assertThat(specContains.isPartly(), is(true));171 assertThat(specContains.getChildObjects(), contains("object", "menu", "button"));172 assertThat(spec.getOriginalText(), is("contains partly object, menu, button"));173 }174 @Test(expectedExceptions = SyntaxException.class,175 expectedExceptionsMessageRegExp = "Missing object name")176 public void shouldGiveError_contains_withoutObjects() {177 readSpec("contains");178 }179 @Test(expectedExceptions = SyntaxException.class,180 expectedExceptionsMessageRegExp = "Missing object name")181 public void shouldGiveError_contains_partly_withoutObjects() {182 readSpec("contains partly");183 }184 @Test185 public void shouldReadSpec_near_button_10_to_20px_left() {186 SpecNear spec = (SpecNear) readSpec("near button 10 to 20px left");187 assertThat(spec.getObject(), is("button"));188 List<Location> locations = spec.getLocations();189 assertThat(locations.size(), is(1));190 assertThat(spec.getLocations(), contains(new Location(Range.between(10, 20), sides(LEFT))));191 assertThat(spec.getOriginalText(), is("near button 10 to 20px left"));192 }193 @Test194 public void shouldReadSpec_near_button_10_to_20px_top_right() {195 SpecNear spec = (SpecNear) readSpec("near button 10 to 20px top right");196 assertThat(spec.getObject(), is("button"));197 List<Location> locations = spec.getLocations();198 assertThat(locations.size(), is(1));199 assertThat(spec.getLocations(), contains(new Location(Range.between(10, 20), sides(TOP, RIGHT))));200 assertThat(spec.getOriginalText(), is("near button 10 to 20px top right"));201 }202 @Test203 public void shouldReadSpec_near_button_approx_0px_left() {204 SpecNear spec = (SpecNear) readSpec("near button ~0px left");205 assertThat(spec.getObject(), is("button"));206 List<Location> locations = spec.getLocations();207 assertThat(locations.size(), is(1));208 assertThat(spec.getLocations(), contains(new Location(Range.between(-2, 2), sides(LEFT))));209 assertThat(spec.getOriginalText(), is("near button ~0px left"));210 }211 @Test(expectedExceptions = SyntaxException.class,212 expectedExceptionsMessageRegExp = "Missing object name")213 public void shouldGiveError_near() {214 readSpec("near");215 }216 @Test(expectedExceptions = SyntaxException.class,217 expectedExceptionsMessageRegExp = "Missing location")218 public void shouldGiveError_near_button() {219 readSpec("near button");220 }221 @Test222 public void shouldReadSpec_aligned_horizontally_centered() throws IOException {223 SpecHorizontally spec = (SpecHorizontally) readSpec("aligned horizontally centered object");224 assertThat(spec.getAlignment(), Matchers.is(Alignment.CENTERED));225 assertThat(spec.getObject(), is("object"));226 assertThat(spec.getErrorRate(), is(0));227 assertThat(spec.getOriginalText(), is("aligned horizontally centered object"));228 }229 @Test230 public void shouldReadSpec_aligned_horizontally_top() throws IOException {231 SpecHorizontally spec = (SpecHorizontally) readSpec("aligned horizontally top object");232 assertThat(spec.getAlignment(), is(Alignment.TOP));233 assertThat(spec.getObject(), is("object"));234 assertThat(spec.getErrorRate(), is(0));235 assertThat(spec.getOriginalText(), is("aligned horizontally top object"));236 }237 @Test238 public void shouldReadSpec_aligned_horizontally_bottom() throws IOException {239 SpecHorizontally spec = (SpecHorizontally) readSpec("aligned horizontally bottom object");240 assertThat(spec.getAlignment(), is(Alignment.BOTTOM));241 assertThat(spec.getObject(), is("object"));242 assertThat(spec.getErrorRate(), is(0));243 assertThat(spec.getOriginalText(), is("aligned horizontally bottom object"));244 }245 @Test246 public void shouldReadSpec_aligned_horizontally_all() throws IOException {247 SpecHorizontally spec = (SpecHorizontally) readSpec("aligned horizontally all object");248 assertThat(spec.getAlignment(), is(Alignment.ALL));249 assertThat(spec.getObject(), is("object"));250 assertThat(spec.getErrorRate(), is(0));251 assertThat(spec.getOriginalText(), is("aligned horizontally all object"));252 }253 @Test254 public void shouldReadSpec_aligned_vertically_centered() throws IOException {255 SpecVertically spec = (SpecVertically) readSpec("aligned vertically centered object");256 assertThat(spec.getAlignment(), is(Alignment.CENTERED));257 assertThat(spec.getObject(), is("object"));258 assertThat(spec.getErrorRate(), is(0));259 assertThat(spec.getOriginalText(), is("aligned vertically centered object"));260 }261 @Test262 public void shouldReadSpec_aligned_vertically_left() throws IOException {263 SpecVertically spec = (SpecVertically) readSpec("aligned vertically left object");264 assertThat(spec.getAlignment(), is(Alignment.LEFT));265 assertThat(spec.getObject(), is("object"));266 assertThat(spec.getErrorRate(), is(0));267 assertThat(spec.getOriginalText(), is("aligned vertically left object"));268 }269 @Test270 public void shouldReadSpec_aligned_vertically_right() throws IOException {271 SpecVertically spec = (SpecVertically) readSpec("aligned vertically right object");272 assertThat(spec.getAlignment(), is(Alignment.RIGHT));273 assertThat(spec.getObject(), is("object"));274 assertThat(spec.getErrorRate(), is(0));275 assertThat(spec.getOriginalText(), is("aligned vertically right object"));276 }277 @Test278 public void shouldReadSpec_aligned_vertically_all() throws IOException {279 SpecVertically spec = (SpecVertically) readSpec("aligned vertically all object");280 assertThat(spec.getAlignment(), is(Alignment.ALL));281 assertThat(spec.getObject(), is("object"));282 assertThat(spec.getErrorRate(), is(0));283 assertThat(spec.getOriginalText(), is("aligned vertically all object"));284 }285 @Test286 public void shouldReadSpec_aligned_vertically_with_error_rate_10px() throws IOException {287 SpecVertically spec = (SpecVertically) readSpec("aligned vertically all object 10px");288 assertThat(spec.getAlignment(), is(Alignment.ALL));289 assertThat(spec.getObject(), is("object"));290 assertThat(spec.getErrorRate(), is(10));291 assertThat(spec.getOriginalText(), is("aligned vertically all object 10px"));292 }293 @Test294 public void shouldReadSpec_aligned_vertically_with_error_rate_10_px() throws IOException {295 SpecVertically spec = (SpecVertically) readSpec("aligned vertically all object 10 px");296 assertThat(spec.getAlignment(), is(Alignment.ALL));297 assertThat(spec.getObject(), is("object"));298 assertThat(spec.getErrorRate(), is(10));299 assertThat(spec.getOriginalText(), is("aligned vertically all object 10 px"));300 }301 @Test302 public void shouldReadSpec_aligned_horizontally_with_error_rate_10px() throws IOException {303 SpecHorizontally spec = (SpecHorizontally) readSpec("aligned horizontally all object 10px");304 assertThat(spec.getAlignment(), is(Alignment.ALL));305 assertThat(spec.getObject(), is("object"));306 assertThat(spec.getErrorRate(), is(10));307 assertThat(spec.getOriginalText(), is("aligned horizontally all object 10px"));308 }309 @Test310 public void shouldReadSpec_aligned_horizontally_with_error_rate_10_px() throws IOException {311 SpecHorizontally spec = (SpecHorizontally) readSpec("aligned horizontally all object 10 px");312 assertThat(spec.getAlignment(), is(Alignment.ALL));313 assertThat(spec.getObject(), is("object"));314 assertThat(spec.getErrorRate(), is(10));315 assertThat(spec.getOriginalText(), is("aligned horizontally all object 10 px"));316 }317 @Test(expectedExceptions = SyntaxException.class,318 expectedExceptionsMessageRegExp = "Incorrect alignment direction. Expected 'vertically' or 'horizontally' but got: object")319 public void shouldGiveError_aligned_object() {320 readSpec("aligned object");321 }322 @Test(expectedExceptions = SyntaxException.class,323 expectedExceptionsMessageRegExp = "Incorrect side for vertical alignment: top")324 public void shouldGiveError_aligned_vertically_top_object() {325 readSpec("aligned vertically top object");326 }327 @Test(expectedExceptions = SyntaxException.class,328 expectedExceptionsMessageRegExp = "Incorrect side for horizontal alignment: left")329 public void shouldGiveError_aligned_horizontally_left_object() {330 readSpec("aligned horizontally left object");331 }332 @Test(expectedExceptions = SyntaxException.class,333 expectedExceptionsMessageRegExp = "Missing object name")334 public void shouldGiveError_aligned_horizontally_left() {335 readSpec("aligned horizontally left");336 }337 @Test338 public void shouldReadSpec_absent() throws IOException {339 Spec spec = readSpec("absent");340 assertThat(spec, instanceOf(SpecAbsent.class));341 assertThat(spec.getOriginalText(), is("absent"));342 }343 @Test344 public void shouldReadSpec_visible() throws IOException {345 Spec spec = readSpec("visible");346 assertThat(spec, instanceOf(SpecVisible.class));347 assertThat(spec.getOriginalText(), is("visible"));348 }349 @Test350 public void shouldReadSpec_width_10px() throws IOException {351 SpecWidth spec = (SpecWidth) readSpec("width 10px");352 assertThat(spec.getRange(), is(Range.exact(10)));353 assertThat(spec.getOriginalText(), is("width 10px"));354 }355 @Test356 public void shouldReadSpec_width_5_to_8px() throws IOException {357 SpecWidth spec = (SpecWidth) readSpec("width 5 to 8px");358 assertThat(spec.getRange(), is(Range.between(5, 8)));359 assertThat(spec.getOriginalText(), is("width 5 to 8px"));360 }361 @Test362 public void shouldReadSpec_width_100_percent_of_other_object_width() throws IOException {363 SpecWidth spec = (SpecWidth) readSpec("width 100% of main-big-container/width");364 assertThat(spec.getRange(), is(Range.exact(100).withPercentOf("main-big-container/width")));365 assertThat(spec.getOriginalText(), is("width 100% of main-big-container/width"));366 }367 @Test368 public void shouldReadSpec_height_10px() throws IOException {369 SpecHeight spec = (SpecHeight) readSpec("height 10px");370 assertThat(spec.getRange(), is(Range.exact(10)));371 assertThat(spec.getOriginalText(), is("height 10px"));372 }373 @Test374 public void shouldReadSpec_height_5_to_8px() throws IOException {375 SpecHeight spec = (SpecHeight) readSpec("height 5 to 8px");376 assertThat(spec.getRange(), is(Range.between(5, 8)));377 assertThat(spec.getOriginalText(), is("height 5 to 8px"));378 }379 @Test(expectedExceptions = SyntaxException.class,380 expectedExceptionsMessageRegExp = "Unexpected token: 1234 px")381 public void shouldGiveError_width_unexcpected_token() {382 readSpec("width 10 to 40 px 1234 px ");383 }384 @Test385 public void shouldReadSpec_text_is_some_text() throws IOException {386 SpecText spec = (SpecText)readSpec("text is \"Some text\"");387 assertThat(spec.getText(), is("Some text"));388 assertThat(spec.getType(), is(SpecText.Type.IS));389 }390 @Test391 public void shouldReadSpec_text_is_some_text_2() throws IOException {392 SpecText spec = (SpecText)readSpec("text is \"Some text\\\" with \\t special \\n symbols\"");393 assertThat(spec.getText(), is("Some text\" with \t special \n symbols"));394 assertThat(spec.getType(), is(SpecText.Type.IS));395 }396 @Test397 public void shouldReadSpec_text_is_empty() throws IOException {398 SpecText spec = (SpecText)readSpec("text is \"\"");399 assertThat(spec.getText(), is(""));400 assertThat(spec.getType(), is(SpecText.Type.IS));401 }402 @Test403 public void shouldReadSpec_text_contains_some_text() throws IOException {404 SpecText spec = (SpecText)readSpec("text contains \"Some text\" ");405 assertThat(spec.getText(), is("Some text"));406 assertThat(spec.getType(), is(SpecText.Type.CONTAINS));407 }408 @Test409 public void shouldReadSpec_text_startsWith_some_text() throws IOException {410 SpecText spec = (SpecText)readSpec("text starts \"Some text\" ");411 assertThat(spec.getText(), is("Some text"));412 assertThat(spec.getType(), is(SpecText.Type.STARTS));413 }414 @Test415 public void shouldReadSpec_text_endssWith_some_text() throws IOException {416 SpecText spec = (SpecText)readSpec("text ends \"Some text\" ");417 assertThat(spec.getText(), is("Some text"));418 assertThat(spec.getType(), is(SpecText.Type.ENDS));419 }420 @Test421 public void shouldReadSpec_text_matches_some_text() throws IOException {422 SpecText spec = (SpecText)readSpec("text matches \"Some * text\" ");423 assertThat(spec.getText(), is("Some * text"));424 assertThat(spec.getType(), is(SpecText.Type.MATCHES));425 }426 @Test427 public void shouldReadSpec_text_lowercase_is() throws IOException {428 SpecText spec = (SpecText)readSpec("text lowercase is \"some text\"");429 assertThat(spec.getText(), is("some text"));430 assertThat(spec.getType(), is(SpecText.Type.IS));431 assertThat(spec.getOperations(), contains("lowercase"));432 }433 @Test434 public void shouldReadSpec_text_lowercase_uppercase_is() throws IOException {435 SpecText spec = (SpecText)readSpec("text lowercase uppercase is \"SOME TEXT\"");436 assertThat(spec.getText(), is("SOME TEXT"));437 assertThat(spec.getType(), is(SpecText.Type.IS));438 assertThat(spec.getOperations(), contains("lowercase", "uppercase"));439 }440 @Test441 public void shouldReadSpec_text_singleline() throws IOException {442 SpecText spec = (SpecText)readSpec("text singleline is \"Some text\"");443 assertThat(spec.getText(), is("Some text"));444 assertThat(spec.getType(), is(SpecText.Type.IS));445 assertThat(spec.getOperations(), contains("singleline"));446 }447 @Test448 public void shouldReadSpec_css_fontsize_is_18px() throws IOException {449 SpecCss spec = (SpecCss)readSpec("css font-size is \"18px\"");450 assertThat(spec.getCssPropertyName(), is("font-size"));451 assertThat(spec.getText(), is("18px"));452 assertThat(spec.getType(), is(SpecText.Type.IS));453 }454 @Test455 public void shouldReadSpec_css_fontsize_starts() throws IOException {456 SpecCss spec = (SpecCss)readSpec("css font-size starts \"18px\"");457 assertThat(spec.getCssPropertyName(), is("font-size"));458 assertThat(spec.getText(), is("18px"));459 assertThat(spec.getType(), is(SpecText.Type.STARTS));460 }461 @Test462 public void shouldReadSpec_css_fontsize_ends() throws IOException {463 SpecCss spec = (SpecCss)readSpec("css font-size ends \"18px\"");464 assertThat(spec.getCssPropertyName(), is("font-size"));465 assertThat(spec.getText(), is("18px"));466 assertThat(spec.getType(), is(SpecText.Type.ENDS));467 }468 @Test469 public void shouldReadSpec_css_fontsize_contains() throws IOException {470 SpecCss spec = (SpecCss)readSpec("css font-size contains \"18px\"");471 assertThat(spec.getCssPropertyName(), is("font-size"));472 assertThat(spec.getText(), is("18px"));473 assertThat(spec.getType(), is(SpecText.Type.CONTAINS));474 }475 @Test476 public void shouldReadSpec_css_fontsize_matches() throws IOException {477 SpecCss spec = (SpecCss)readSpec("css font-size matches \"18px\"");478 assertThat(spec.getCssPropertyName(), is("font-size"));479 assertThat(spec.getText(), is("18px"));480 assertThat(spec.getType(), is(SpecText.Type.MATCHES));481 }482 @Test483 public void shouldReadSpec_above_object_20px() throws IOException {484 SpecAbove spec = (SpecAbove)readSpec("above object 20px");485 assertThat(spec.getObject(), is("object"));486 assertThat(spec.getRange(), is(Range.exact(20)));487 }488 @Test489 public void shouldReadSpec_above_object_10_20px() throws IOException {490 SpecAbove spec = (SpecAbove)readSpec("above object 10 to 20px");491 assertThat(spec.getObject(), is("object"));492 assertThat(spec.getRange(), is(Range.between(10, 20)));493 }494 @Test495 public void shouldReadSpec_above() throws IOException {496 SpecAbove spec = (SpecAbove)readSpec("above object");497 assertThat(spec.getObject(), is("object"));498 assertThat(spec.getRange(), is(Range.greaterThanOrEquals(0)));499 }500 @Test501 public void shouldReadSpec_below() throws IOException {502 SpecBelow spec = (SpecBelow)readSpec("below object");503 assertThat(spec.getObject(), is("object"));504 assertThat(spec.getRange(), is(Range.greaterThanOrEquals(0)));505 }506 @Test507 public void shouldReadSpec_below_object_20px() throws IOException {508 SpecBelow spec = (SpecBelow)readSpec("below object 20px");509 assertThat(spec.getObject(), is("object"));510 assertThat(spec.getRange(), is(Range.exact(20)));511 }512 @Test513 public void shouldReadSpec_below_object_10_to_20px() throws IOException {514 SpecBelow spec = (SpecBelow)readSpec("below object 10 to 20px");515 assertThat(spec.getObject(), is("object"));516 assertThat(spec.getRange(), is(Range.between(10, 20)));517 }518 @Test519 public void shouldReadSpec_left_of_object_10px() throws IOException {520 SpecLeftOf specLeftOf = (SpecLeftOf)readSpec("left-of object 10px");521 assertThat(specLeftOf.getObject(), is("object"));522 assertThat(specLeftOf.getRange(), is(Range.exact(10)));523 }524 @Test525 public void shouldReadSpec_left_of_object_10_to_20px() throws IOException {526 SpecLeftOf specLeftOf = (SpecLeftOf)readSpec("left-of object 10 to 20px");527 assertThat(specLeftOf.getObject(), is("object"));528 assertThat(specLeftOf.getRange(), is(Range.between(10, 20)));529 }530 @Test531 public void shouldReadSpec_left_of_object() throws IOException {532 SpecLeftOf specLeftOf = (SpecLeftOf)readSpec("left-of object");533 assertThat(specLeftOf.getObject(), is("object"));534 assertThat(specLeftOf.getRange(), is(Range.greaterThanOrEquals(0)));535 }536 @Test537 public void shouldReadSpec_right_of_object_10px() throws IOException {538 SpecRightOf specRightOf = (SpecRightOf)readSpec("right-of object 10px");539 assertThat(specRightOf.getObject(), is("object"));540 assertThat(specRightOf.getRange(), is(Range.exact(10)));541 }542 @Test543 public void shouldReadSpec_right_of_object_10_to_20px() throws IOException {544 SpecRightOf specRightOf = (SpecRightOf)readSpec("right-of object 10 to 20px");545 assertThat(specRightOf.getObject(), is("object"));546 assertThat(specRightOf.getRange(), is(Range.between(10, 20)));547 }548 @Test549 public void shouldReadSpec_right_of_object() throws IOException {550 SpecRightOf specRightOf = (SpecRightOf)readSpec("right-of object");551 assertThat(specRightOf.getObject(), is("object"));552 assertThat(specRightOf.getRange(), is(Range.greaterThanOrEquals(0)));553 }554 @Test(expectedExceptions = {SyntaxException.class},555 expectedExceptionsMessageRegExp = "Missing validation type \\(is, contains, starts, ends, matches\\)"556 )557 public void shouldGiveException_empty_css_spec() throws IOException {558 readSpec("css \"18px\"");559 }560 @Test(expectedExceptions = {SyntaxException.class},561 expectedExceptionsMessageRegExp = "Unknown validation type: \"18px\""562 )563 public void shouldGiveException_css_without_type() throws IOException {564 readSpec("css font-size \"18px\"");565 }566 @Test567 public void shouldReadSpec_centered_inside_object() throws IOException {568 SpecCentered spec = (SpecCentered)readSpec("centered inside object");569 assertThat(spec.getObject(), is("object"));570 assertThat(spec.getLocation(), is(SpecCentered.Location.INSIDE));571 assertThat(spec.getAlignment(), is(SpecCentered.Alignment.ALL));572 }573 @Test574 public void shouldReadSpec_centered_horizontally_inside_object() throws IOException {575 SpecCentered spec = (SpecCentered)readSpec("centered horizontally inside object");576 assertThat(spec.getObject(), is("object"));577 assertThat(spec.getLocation(), is(SpecCentered.Location.INSIDE));578 assertThat(spec.getAlignment(), is(SpecCentered.Alignment.HORIZONTALLY));579 }580 @Test581 public void shouldReadSpec_centered_vertically_inside_object() throws IOException {582 SpecCentered spec = (SpecCentered)readSpec("centered vertically inside object");583 assertThat(spec.getObject(), is("object"));584 assertThat(spec.getLocation(), is(SpecCentered.Location.INSIDE));585 assertThat(spec.getAlignment(), is(SpecCentered.Alignment.VERTICALLY));586 }587 @Test588 public void shouldReadSpec_centered_all_inside_object() throws IOException {589 SpecCentered spec = (SpecCentered)readSpec("centered all inside object");590 assertThat(spec.getObject(), is("object"));591 assertThat(spec.getLocation(), is(SpecCentered.Location.INSIDE));592 assertThat(spec.getAlignment(), is(SpecCentered.Alignment.ALL));593 }594 @Test595 public void shouldReadSpec_centered_all_on_object() throws IOException {596 SpecCentered spec = (SpecCentered)readSpec("centered all on object");597 assertThat(spec.getObject(), is("object"));598 assertThat(spec.getLocation(), is(SpecCentered.Location.ON));599 assertThat(spec.getAlignment(), is(SpecCentered.Alignment.ALL));600 }601 @Test602 public void shouldReadSpec_centered_on_object() throws IOException {603 SpecCentered spec = (SpecCentered)readSpec("centered on object");604 assertThat(spec.getObject(), is("object"));605 assertThat(spec.getLocation(), is(SpecCentered.Location.ON));606 assertThat(spec.getAlignment(), is(SpecCentered.Alignment.ALL));607 }608 @Test609 public void shouldReadSpec_centered_horizontally_on_object() throws IOException {610 SpecCentered spec = (SpecCentered)readSpec("centered horizontally on object");611 assertThat(spec.getObject(), is("object"));612 assertThat(spec.getLocation(), is(SpecCentered.Location.ON));613 assertThat(spec.getAlignment(), is(SpecCentered.Alignment.HORIZONTALLY));614 }615 @Test616 public void shouldReadSpec_centered_horizontally_on_object_25px() throws IOException {617 SpecCentered spec = (SpecCentered)readSpec("centered horizontally on object 25px");618 assertThat(spec.getObject(), is("object"));619 assertThat(spec.getLocation(), is(SpecCentered.Location.ON));620 assertThat(spec.getAlignment(), is(SpecCentered.Alignment.HORIZONTALLY));621 assertThat(spec.getErrorRate(), is(25));622 }623 @Test624 public void shouldReadSpec_centered_horizontally_on_object_25_px() throws IOException {625 SpecCentered spec = (SpecCentered)readSpec("centered horizontally on object 25 px");626 assertThat(spec.getObject(), is("object"));627 assertThat(spec.getLocation(), is(SpecCentered.Location.ON));628 assertThat(spec.getAlignment(), is(SpecCentered.Alignment.HORIZONTALLY));629 assertThat(spec.getErrorRate(), is(25));630 }631 @Test632 public void shouldReadSpec_centered_vertically_on_object() throws IOException {633 SpecCentered spec = (SpecCentered)readSpec("centered vertically on object");634 assertThat(spec.getObject(), is("object"));635 assertThat(spec.getLocation(), is(SpecCentered.Location.ON));636 assertThat(spec.getAlignment(), is(SpecCentered.Alignment.VERTICALLY));637 }638 @Test639 public void shoulReadSpec_on_object_10px_left() throws IOException {640 SpecOn spec = (SpecOn)readSpec("on edge object 10px left");641 assertThat(spec.getSideHorizontal(), is(TOP));642 assertThat(spec.getSideVertical(), is(LEFT));643 assertThat(spec.getObject(), is("object"));644 List<Location> locations = spec.getLocations();645 assertThat(locations.size(), is(1));646 assertThat(spec.getLocations(), contains(new Location(Range.exact(10), sides(LEFT))));647 assertThat(spec.getOriginalText(), is("on edge object 10px left"));648 }649 @Test650 public void shoulReadSpec_on_object_10px_left_20px_top() throws IOException {651 SpecOn spec = (SpecOn)readSpec("on edge object 10px left, 20px top");652 assertThat(spec.getSideHorizontal(), is(TOP));653 assertThat(spec.getSideVertical(), is(LEFT));654 assertThat(spec.getObject(), is("object"));655 List<Location> locations = spec.getLocations();656 assertThat(locations.size(), is(2));657 assertThat(spec.getLocations(), contains(new Location(Range.exact(10), sides(LEFT)), new Location(Range.exact(20), sides(TOP))));658 assertThat(spec.getOriginalText(), is("on edge object 10px left, 20px top"));659 }660 @Test661 public void shouldReadSpec_on_top_object_10px_top_right() throws Exception {662 SpecOn spec = (SpecOn)readSpec("on top edge object 10px top right");663 assertThat(spec.getSideHorizontal(), is(TOP));664 assertThat(spec.getSideVertical(), is(LEFT));665 assertThat(spec.getObject(), is("object"));666 List<Location> locations = spec.getLocations();667 assertThat(locations.size(), is(1));668 assertThat(spec.getLocations(), contains(new Location(Range.exact(10), sides(TOP, RIGHT))));669 assertThat(spec.getOriginalText(), is("on top edge object 10px top right"));670 }671 @Test672 public void shouldReadSpec_on_left_object_10px_top_right() throws Exception {673 SpecOn spec = (SpecOn)readSpec("on left edge object 10px top right");674 assertThat(spec.getSideHorizontal(), is(TOP));675 assertThat(spec.getSideVertical(), is(LEFT));676 assertThat(spec.getObject(), is("object"));677 List<Location> locations = spec.getLocations();678 assertThat(locations.size(), is(1));679 assertThat(spec.getLocations(), contains(new Location(Range.exact(10), sides(TOP, RIGHT))));680 assertThat(spec.getOriginalText(), is("on left edge object 10px top right"));681 }682 @Test683 public void shouldReadSpec_on_bottom_right_object_10px_top_right() throws Exception {684 SpecOn spec = (SpecOn)readSpec("on right bottom edge object 10px top right");685 assertThat(spec.getSideHorizontal(), is(BOTTOM));686 assertThat(spec.getSideVertical(), is(RIGHT));687 assertThat(spec.getObject(), is("object"));688 List<Location> locations = spec.getLocations();689 assertThat(locations.size(), is(1));690 assertThat(spec.getLocations(), contains(new Location(Range.exact(10), sides(TOP, RIGHT))));691 assertThat(spec.getOriginalText(), is("on right bottom edge object 10px top right"));692 }693 @Test(expectedExceptions = SyntaxException.class,694 expectedExceptionsMessageRegExp = "Missing \"edge\"")695 public void shouldGiveError_missingEdges_forSpec_on() throws Exception {696 readSpec("on top left object 10px");697 }698 @Test699 public void shouldReadSpec_color_scheme_40percent_black_approx_30percent_white() throws Exception {700 SpecColorScheme spec = (SpecColorScheme)readSpec("color-scheme 40% black , ~30% white");701 List<ColorRange> colors = spec.getColorRanges();702 assertThat(colors.size(), is(2));703 assertThat(colors.get(0).getRange(), is(Range.exact(40)));704 assertThat(colors.get(0).getColorClassifier(), is(new SimpleColorClassifier("black", new Color(0, 0, 0))));705 assertThat(colors.get(1).getRange(), is(Range.between(28, 32)));706 assertThat(colors.get(1).getColorClassifier(), is(new SimpleColorClassifier("white", new Color(255, 255, 255))));707 }708 @Test709 public void shouldReadSpec_color_scheme_greater_than_40percent_ffaa03() throws Exception {710 SpecColorScheme spec = (SpecColorScheme)readSpec("color-scheme > 40% #ffaa03");711 List<ColorRange> colors = spec.getColorRanges();712 assertThat(colors.size(), is(1));713 assertThat(colors.get(0).getRange(), is(Range.greaterThan(40)));714 assertThat(colors.get(0).getColorClassifier(), is(new SimpleColorClassifier("#ffaa03", new Color(255, 170, 3))));715 }716 @Test717 public void shouldReadSpec_color_scheme_40_to_50percent_ffaa03() throws Exception {718 SpecColorScheme spec = (SpecColorScheme)readSpec("color-scheme 40 to 50% red");719 List<ColorRange> colors = spec.getColorRanges();720 assertThat(colors.size(), is(1));721 assertThat(colors.get(0).getRange(), is(Range.between(40, 50)));722 assertThat(colors.get(0).getColorClassifier(), is(new SimpleColorClassifier("red", new Color(255, 0, 0))));723 }724 @Test725 public void shouldReadSpec_color_withShorthand_hexColorNotation() throws Exception {726 SpecColorScheme spec = (SpecColorScheme)readSpec("color-scheme 40% #f3e");727 List<ColorRange> colors = spec.getColorRanges();728 assertThat(colors.size(), is(1));729 assertThat(colors.get(0).getRange(), is(Range.exact(40)));730 assertThat(colors.get(0).getColorClassifier(), is(new SimpleColorClassifier("#f3e", new Color(255, 51, 238))));731 }732 @Test733 public void shouldReadSpec_color_withGradients() throws Exception {734 SpecColorScheme spec = (SpecColorScheme)readSpec("color-scheme 40% white-green-blue");735 List<ColorRange> colors = spec.getColorRanges();736 assertThat(colors.size(), is(1));737 assertThat(colors.get(0).getRange(), is(Range.exact(40)));738 assertThat(colors.get(0).getColorClassifier(), is(new GradientColorClassifier("white-green-blue", asList(739 new Color(255, 255, 255),740 new Color(0, 255, 0),741 new Color(0, 0, 255)742 ))));743 }744 @Test745 public void shouldReadSpec_color_withGradients_2() throws Exception {746 SpecColorScheme spec = (SpecColorScheme)readSpec("color-scheme 40% white - green - blue, 10 to 23% #a3f - #00e");747 List<ColorRange> colors = spec.getColorRanges();748 assertThat(colors.size(), is(2));749 assertThat(colors.get(0).getRange(), is(Range.exact(40)));750 assertThat(colors.get(0).getColorClassifier(), is(new GradientColorClassifier("white - green - blue", asList(751 new Color(255, 255, 255),752 new Color(0, 255, 0),753 new Color(0, 0, 255)754 ))));755 assertThat(colors.get(1).getRange(), is(Range.between(10, 23)));756 assertThat(colors.get(1).getColorClassifier(), is(new GradientColorClassifier("#a3f - #00e", asList(757 new Color(170, 51, 255),758 new Color(0, 0, 238)759 ))));760 }761 @Test762 public void shouldReadSpec_image_withMaxPercentageError() throws IOException {763 SpecImage spec = (SpecImage)readSpec("image file imgs/image.png, error 2.4%");764 assertThat(spec.getImagePaths(), contains("imgs/image.png"));765 assertThat(spec.getErrorRate().getValue(), is(2.4));766 assertThat(spec.getErrorRate().getType(), is(SpecImage.ErrorRateType.PERCENT));767 assertThat(spec.getTolerance(), is(25));768 }769 @Test770 public void shouldReadSpec_image_withMaxPixelsError() throws IOException {771 SpecImage spec = (SpecImage)readSpec("image file imgs/image.png, error 112 px");772 assertThat(spec.getImagePaths(), contains("imgs/image.png"));773 assertThat(spec.getErrorRate().getValue(), is(112.0));774 assertThat(spec.getErrorRate().getType(), is(SpecImage.ErrorRateType.PIXELS));775 assertThat(spec.getTolerance(), is(25));776 }777 @Test778 public void shouldReadSpec_image_withMaxPixelsError_tolerance5() throws IOException {779 SpecImage spec = (SpecImage)readSpec("image file imgs/image.png, error 112 px, tolerance 5");780 assertThat(spec.getImagePaths(), contains("imgs/image.png"));781 assertThat(spec.getErrorRate().getValue(), is(112.0));782 assertThat(spec.getErrorRate().getType(), is(SpecImage.ErrorRateType.PIXELS));783 assertThat(spec.getTolerance(), is(5));784 assertThat(spec.isStretch(), is(false));785 assertThat(spec.isCropIfOutside(), is(false));786 }787 @Test788 public void shouldReadSpec_image_withMaxPixelsError_tolerance5_stretch() throws IOException {789 SpecImage spec = (SpecImage)readSpec("image file imgs/image.png, error 112 px, tolerance 5, stretch");790 assertThat(spec.getImagePaths(), contains("imgs/image.png"));791 assertThat(spec.getErrorRate().getValue(), is(112.0));792 assertThat(spec.getErrorRate().getType(), is(SpecImage.ErrorRateType.PIXELS));793 assertThat(spec.getTolerance(), is(5));794 assertThat(spec.isStretch(), is(true));795 }796 @Test797 public void shouldReadSpec_image_withCropIfOutside() throws IOException {798 SpecImage spec = (SpecImage)readSpec("image file imgs/image.png, crop-if-outside");799 assertThat(spec.getImagePaths(), contains("imgs/image.png"));800 assertThat(spec.isCropIfOutside(), is(true));801 }802 @Test803 public void shouldReadSpec_image_withMaxPixelsError_tolerance5_filterBlur2() throws IOException {804 SpecImage spec = (SpecImage)readSpec("image file imgs/image.png, error 112 px, tolerance 5, filter blur 2");805 assertThat(spec.getImagePaths(), contains("imgs/image.png"));806 assertThat(spec.getErrorRate().getValue(), is(112.0));807 assertThat(spec.getErrorRate().getType(), is(SpecImage.ErrorRateType.PIXELS));808 assertThat(spec.getTolerance(), is(5));809 assertThat(spec.getOriginalFilters().size(), is(1));810 assertThat(spec.getSampleFilters().size(), is(1));811 assertThat(((BlurFilter)spec.getOriginalFilters().get(0)).getRadius(), is(2));812 assertThat(((BlurFilter)spec.getSampleFilters().get(0)).getRadius(), is(2));813 }814 @Test815 public void shouldReadSpec_image_withMaxPixelsError_tolerance5_filterABlur2() throws IOException {816 SpecImage spec = (SpecImage)readSpec("image file imgs/image.png, error 112 px, tolerance 5, filter-a blur 2");817 assertThat(spec.getImagePaths(), contains("imgs/image.png"));818 assertThat(spec.getErrorRate().getValue(), is(112.0));819 assertThat(spec.getErrorRate().getType(), is(SpecImage.ErrorRateType.PIXELS));820 assertThat(spec.getTolerance(), is(5));821 assertThat(spec.getOriginalFilters().size(), is(1));822 assertThat(spec.getSampleFilters().size(), is(0));823 assertThat(((BlurFilter)spec.getOriginalFilters().get(0)).getRadius(), is(2));824 }825 @Test826 public void shouldReadSpec_image_withMaxPixelsError_tolerance5_filterBBlur2() throws IOException {827 SpecImage spec = (SpecImage)readSpec("image file imgs/image.png, error 112 px, tolerance 5, filter-b blur 2");828 assertThat(spec.getImagePaths(), contains("imgs/image.png"));829 assertThat(spec.getErrorRate().getValue(), is(112.0));830 assertThat(spec.getErrorRate().getType(), is(SpecImage.ErrorRateType.PIXELS));831 assertThat(spec.getTolerance(), is(5));832 assertThat(spec.getOriginalFilters().size(), is(0));833 assertThat(spec.getSampleFilters().size(), is(1));834 assertThat(((BlurFilter)spec.getSampleFilters().get(0)).getRadius(), is(2));835 }836 @Test837 public void shouldReadSpec_image_withMaxPixelsError_tolerance5_filterBlur2_filterDenoise1() throws IOException {838 SpecImage spec = (SpecImage)readSpec("image file imgs/image.png, error 112 px, filter blur 2, filter denoise 4, tolerance 5");839 assertThat(spec.getImagePaths(), contains("imgs/image.png"));840 assertThat(spec.getErrorRate().getValue(), is(112.0));841 assertThat(spec.getErrorRate().getType(), is(SpecImage.ErrorRateType.PIXELS));842 assertThat(spec.getTolerance(), is(5));843 assertThat(spec.getOriginalFilters().size(), is(2));844 BlurFilter filter1 = (BlurFilter) spec.getOriginalFilters().get(0);845 assertThat(filter1.getRadius(), is(2));846 DenoiseFilter filter2 = (DenoiseFilter) spec.getOriginalFilters().get(1);847 assertThat(filter2.getRadius(), is(4));848 }849 @Test850 public void shouldReadSpec_image_withMaxPixelsError_tolerance5_filterBlur2_filterSaturation10_mapFilterDenoise1() throws IOException {851 SpecImage spec = (SpecImage)readSpec("image file imgs/image.png, error 112 px, filter blur 2, filter saturation 10, map-filter denoise 4, tolerance 5");852 assertThat(spec.getErrorRate().getValue(), is(112.0));853 assertThat(spec.getErrorRate().getType(), is(SpecImage.ErrorRateType.PIXELS));854 assertThat(spec.getImagePaths(), contains("imgs/image.png"));855 assertThat(spec.getTolerance(), is(5));856 assertThat(spec.getOriginalFilters().size(), is(2));857 assertThat(spec.getSampleFilters().size(), is(2));858 assertThat(spec.getMapFilters().size(), is(1));859 assertThat(((BlurFilter)spec.getOriginalFilters().get(0)).getRadius(), is(2));860 assertThat(((BlurFilter)spec.getSampleFilters().get(0)).getRadius(), is(2));861 assertThat(((SaturationFilter)spec.getOriginalFilters().get(1)).getLevel(), is(10));862 assertThat(((SaturationFilter)spec.getSampleFilters().get(1)).getLevel(), is(10));863 DenoiseFilter filter2 = (DenoiseFilter) spec.getMapFilters().get(0);864 assertThat(filter2.getRadius(), is(4));865 }866 @Test867 public void shouldReadSpec_image_withMask() throws IOException {868 SpecImage spec = (SpecImage)readSpec("image file image.png, filter mask color-scheme-image-1.png");869 assertThat(spec.getImagePaths(), contains("image.png"));870 assertThat(spec.getOriginalFilters().size(), is(1));871 assertThat(spec.getOriginalFilters().get(0), is(instanceOf(MaskFilter.class)));872 assertThat(spec.getSampleFilters().size(), is(1));873 assertThat(spec.getSampleFilters().get(0), is(instanceOf(MaskFilter.class)));874 }875 @Test876 public void shouldReadSpec_image_withMaxPixelsError_andArea() throws IOException {877 SpecImage spec = (SpecImage)readSpec("image file imgs/image.png, error 112 px, area 10 10 100 20");878 assertThat(spec.getImagePaths(), contains("imgs/image.png"));879 assertThat(spec.getErrorRate().getValue(), is(112.0));880 assertThat(spec.getErrorRate().getType(), is(SpecImage.ErrorRateType.PIXELS));881 assertThat(spec.getTolerance(), is(25));882 assertThat(spec.getSelectedArea(), is(new Rect(10,10,100,20)));883 }884 @Test885 public void shouldReadSpec_image_withAnalyzeOffset() throws IOException {886 SpecImage spec = (SpecImage)readSpec("image file imgs/image.png, analyze-offset 5");887 assertThat(spec.getImagePaths(), contains("imgs/image.png"));888 assertThat(spec.getAnalyzeOffset(), is(5));889 }890 @Test891 public void shouldReadSpec_image_andBuildImagePath_withContextPath() throws IOException {892 SpecImage spec = (SpecImage) readSpec("image file image.png", "some-component/specs");893 assertThat(spec.getImagePaths(), contains("some-component/specs/image.png"));894 }895 /**896 * Comes from https//github.com/galenframework/galen/issues/171897 * @throws IOException898 */899 @Test900 public void shouldReadSpec_image_toleranceAndErrorRate_fromConfig() throws IOException {901 System.setProperty("galen.spec.image.tolerance", "21");902 System.setProperty("galen.spec.image.error", "121%");903 SpecImage spec = (SpecImage)readSpec("image file image.png");904 assertThat(spec.getTolerance(), is(21));905 assertThat(spec.getErrorRate().getValue(), is(121.0));906 assertThat(spec.getErrorRate().getType(), is(SpecImage.ErrorRateType.PERCENT));907 System.getProperties().remove("galen.spec.image.tolerance");908 System.getProperties().remove("galen.spec.image.error");909 }910 @Test911 public void shouldReadSpec_image_replaceColors() throws IOException {912 SpecImage specImage = (SpecImage) readSpec("image file image.png, filter replace-colors #000-#333 #f0f0f0 #a0a0a0-#a0b0a0-#a0b0c0 with #111 tolerance 30 radius 2");913 assertThat(specImage.getOriginalFilters().size(), is(1));914 assertThat(specImage.getOriginalFilters().get(0), is(instanceOf(ReplaceColorsFilter.class)));915 ReplaceColorsFilter filter = (ReplaceColorsFilter) specImage.getOriginalFilters().get(0);916 assertThat(filter.getReplaceColorsDefinitions().size(), is(1));917 ReplaceColorsDefinition replaceColorsDefinitions = filter.getReplaceColorsDefinitions().get(0);918 assertThat(replaceColorsDefinitions.getReplaceColor(), is(new Color(17, 17, 17)));919 assertThat(replaceColorsDefinitions.getTolerance(), is(30));920 assertThat(replaceColorsDefinitions.getRadius(), is(2));921 assertThat(replaceColorsDefinitions.getColorClassifiers().size(), is(3));922 assertThat(replaceColorsDefinitions.getColorClassifiers().get(0), instanceOf(GradientColorClassifier.class));923 GradientColorClassifier gradient = (GradientColorClassifier) replaceColorsDefinitions.getColorClassifiers().get(0);924 assertThat(gradient.getName(), is("#000-#333"));925 assertThat(replaceColorsDefinitions.getColorClassifiers().get(1), instanceOf(SimpleColorClassifier.class));926 SimpleColorClassifier simple = (SimpleColorClassifier) replaceColorsDefinitions.getColorClassifiers().get(1);927 assertThat(simple.getName(), is("#f0f0f0"));928 assertThat(replaceColorsDefinitions.getColorClassifiers().get(2), instanceOf(GradientColorClassifier.class));929 gradient = (GradientColorClassifier) replaceColorsDefinitions.getColorClassifiers().get(2);930 assertThat(gradient.getName(), is("#a0a0a0-#a0b0a0-#a0b0c0"));931 }932 @Test933 public void shouldReadSpec_image_ignoredObjects() throws IOException {934 SpecImage spec = (SpecImage) readSpec("image file img.png, ignore-objects [menu_item-*, &excluded_objects], error 10px, ignore-objects one_more_obj");935 assertThat(spec.getImagePaths(), contains("img.png"));936 assertThat(spec.getIgnoredObjectExpressions(), contains("menu_item-*, &excluded_objects", "one_more_obj"));937 assertThat(spec.getErrorRate().getValue(), is(10.0));938 assertThat(spec.getErrorRate().getType(), is(SpecImage.ErrorRateType.PIXELS));939 }940 @Test941 public void shouldReadSpec_component() throws IOException {942 SpecComponent spec = (SpecComponent)readSpec("component some.spec");943 assertThat(spec.isFrame(), is(false));944 assertThat(spec.getSpecPath(), is("some.spec"));945 assertThat(spec.getOriginalText(), is("component some.spec"));946 }947 @Test948 public void shouldReadSpec_component_frame() throws IOException {949 SpecComponent spec = (SpecComponent)readSpec("component frame some.spec");950 assertThat(spec.isFrame(), is(true));951 assertThat(spec.getSpecPath(), is("some.spec"));952 assertThat(spec.getOriginalText(), is("component frame some.spec"));953 }954 @Test955 public void shouldReadSpec_component_withArguments_andRecogniseBasicTypes() throws IOException {956 SpecComponent spec = (SpecComponent)readSpec("component some.gspec, arg1 1, arg2 2.4, arg3 true, arg4 false, arg5 something, arg6 \"surrounded in quotes\" ");957 assertThat(spec.isFrame(), is(false));958 assertThat(spec.getSpecPath(), is("some.gspec"));959 assertThat(spec.getArguments(), is((Map<String, Object>)new HashMap<String, Object>(){{960 put("arg1", 1L);961 put("arg2", 2.4d);962 put("arg3", true);963 put("arg4", false);964 put("arg5", "something");965 put("arg6", "surrounded in quotes");966 }}));967 }968 @Test969 public void shouldReadSpec_count_any_pattern_is_6() throws IOException {970 SpecCount spec = (SpecCount)readSpec("count any menu-item-* is 6");971 assertThat(spec.getPattern(), is("menu-item-*"));972 assertThat(spec.getAmount(), is(Range.exact(6)));973 assertThat(spec.getFetchType(), is(SpecCount.FetchType.ANY));974 assertThat(spec.getOriginalText(), is("count any menu-item-* is 6"));975 }976 @Test977 public void shouldReadSpec_count_visible_pattern_is_6() throws IOException {978 SpecCount spec = (SpecCount)readSpec("count visible menu-item-* is 6");979 assertThat(spec.getPattern(), is("menu-item-*"));980 assertThat(spec.getAmount(), is(Range.exact(6)));981 assertThat(spec.getFetchType(), is(SpecCount.FetchType.VISIBLE));982 assertThat(spec.getOriginalText(), is("count visible menu-item-* is 6"));983 }984 @Test985 public void shouldReadSpec_absent_visible_pattern_is_6() throws IOException {986 SpecCount spec = (SpecCount)readSpec("count absent menu-item-* is 6");987 assertThat(spec.getPattern(), is("menu-item-*"));988 assertThat(spec.getAmount(), is(Range.exact(6)));989 assertThat(spec.getFetchType(), is(SpecCount.FetchType.ABSENT));990 assertThat(spec.getOriginalText(), is("count absent menu-item-* is 6"));991 }992 @Test993 public void shouldReadSpec_count_pattern_in_double_qoutes_is_6() throws IOException {994 SpecCount spec = (SpecCount)readSpec("count any \"menu-item-*, box-*\" is 6");995 assertThat(spec.getPattern(), is("menu-item-*, box-*"));996 assertThat(spec.getAmount(), is(Range.exact(6)));997 assertThat(spec.getOriginalText(), is("count any \"menu-item-*, box-*\" is 6"));998 }999 @Test1000 public void shouldReadSpec_count_pattern_is_6_to_8() throws IOException {1001 SpecCount spec = (SpecCount)readSpec("count any menu-item-* is 6 to 8");1002 assertThat(spec.getPattern(), is("menu-item-*"));1003 assertThat(spec.getAmount(), is(Range.between(6, 8)));1004 assertThat(spec.getOriginalText(), is("count any menu-item-* is 6 to 8"));1005 }1006 @Test1007 public void shouldReadSpec_count_pattern_is__lessThan_8() throws IOException {1008 SpecCount spec = (SpecCount)readSpec("count any menu-item-* is < 8");1009 assertThat(spec.getPattern(), is("menu-item-*"));1010 assertThat(spec.getAmount(), is(Range.lessThan(8)));1011 assertThat(spec.getOriginalText(), is("count any menu-item-* is < 8"));1012 }1013 @Test1014 public void shouldReadSpec_count_pattern_is__biggerThan_8() throws IOException {1015 SpecCount spec = (SpecCount)readSpec("count any menu-item-* is > 8");1016 assertThat(spec.getPattern(), is("menu-item-*"));1017 assertThat(spec.getAmount(), is(Range.greaterThan(8)));1018 assertThat(spec.getOriginalText(), is("count any menu-item-* is > 8"));1019 }1020 @Test(expectedExceptions = SyntaxException.class,1021 expectedExceptionsMessageRegExp = "Couldn't process: whatever non parsed arguments"1022 )1023 public void shouldThrowError_whenSpecHasNotParsed_theWholeText() {1024 readSpec("left-of some-object 10 px whatever non parsed arguments");1025 }1026 private Spec readSpec(String specText) {1027 return new SpecReader().read(specText);1028 }1029 private Spec readSpec(String specText, String contextPath) {1030 return new SpecReader().read(specText, contextPath);1031 }1032 private List<Side> sides(Side...sides) {1033 return asList(sides);1034 }1035}...

Full Screen

Full Screen

sides

Using AI Code Generation

copy

Full Screen

1package com.galenframework.tests.speclang2;2import static java.util.Arrays.asList;3import static org.hamcrest.MatcherAssert.assertThat;4import static org.hamcrest.Matchers.is;5import static org.hamcrest.Matchers.not;6import static org.hamcrest.Matchers.nullValue;7import java.io.IOException;8import java.util.List;9import org.testng.annotations.Test;10import com.galenframework.specs.page.PageSpec;11import com.galenframework.specs.page.PageSpecReader;12import com.galenframework.specs.page.Side;13import com.galenframework.specs.page.Side.SideType;14public class SpecsReaderV2Test {15 public void shouldReadSides() throws IOException {16 PageSpec pageSpec = new PageSpecReader().read("17".getBytes());18 List<Side> sides = pageSpec.getSides();19 assertThat(sides, is(not(nullValue())));20 assertThat(sides.size(), is(4));21 assertThat(sides.get(0).getType(), is(SideType.TOP));22 assertThat(sides.get(0).getSpecs().size(), is(1));23 assertThat(sides.get(1).getType(), is(SideType.RIGHT));24 assertThat(sides.get(1).getSpecs().size(), is(1));25 assertThat(sides.get(2).getType(), is(SideType.BOTTOM));26 assertThat(sides.get(2).getSpecs().size(), is(1));27 assertThat(sides.get(3).getType(), is(SideType.LEFT));28 assertThat(sides.get(3).getSpecs().size(), is(1));29 }30 public void shouldReadSides_withSpecs() throws IOException {31 PageSpec pageSpec = new PageSpecReader().read("32".getBytes());33 List<Side> sides = pageSpec.getSides();34 assertThat(sides, is(not(nullValue())));35 assertThat(sides.size(), is(4));36 assertThat(sides.get(0).getType(), is(SideType.TOP));37 assertThat(sides.get(0).getSpecs().size(), is(1));38 assertThat(sides.get(1).getType(), is(SideType.RIGHT));39 assertThat(sides.get(1).getSpecs().size(), is(1));40 assertThat(sides.get(2).getType(), is(SideType.BOTTOM));41 assertThat(sides.get(2).getSpecs().size(), is(1));42 assertThat(sides.get(3).getType(),

Full Screen

Full Screen

sides

Using AI Code Generation

copy

Full Screen

1package com.galenframework.tests.speclang2;2import com.galenframework.specs.Spec;3import com.galenframework.specs.SpecSide;4import org.testng.annotations.Test;5import java.util.List;6import static java.util.Arrays.asList;7import static org.hamcrest.MatcherAssert.assertThat;8import static org.hamcrest.Matchers.is;9public class SpecsReaderV2Test {10 public void shouldParseSides() {11 List<Spec> specs = SpecsReaderV2.read("

Full Screen

Full Screen

sides

Using AI Code Generation

copy

Full Screen

1import static com.galenframework.tests.speclang2.SpecsReaderV2Test.sides12;2import static com.galenframework.tests.speclang2.SpecsReaderV2Test.sides13;3import static com.galenframework.tests.speclang2.SpecsReaderV2Test.sides14;4import static com.galenframework.tests.speclang2.SpecsReaderV2Test.sides15;5import static com.galenframework.tests.speclang2.SpecsReaderV2Test.sides16;6import static com.galenframework.tests.speclang2.SpecsReaderV2Test.sides17;7import static com.galenframework.tests.speclang2.SpecsReaderV2Test.sides18;8import static com.galenframework.tests.speclang2.SpecsReaderV2Test.sides19;9import static com.galenframework.tests.speclang2.SpecsReaderV2Test.sides20;10import static com.galenframework.tests.speclang2.SpecsReaderV2Test.sides21;11import static com.galenframework.tests.speclang2.SpecsReaderV2Test.sides22;12import static com.galenframework.tests.speclang2.SpecsReaderV2Test.sides23;13import static com.galen

Full Screen

Full Screen

sides

Using AI Code Generation

copy

Full Screen

1 public void shouldReadSides() throws IOException {2 String spec = "sides: 10px";3 SpecsReaderV2 specsReader = new SpecsReaderV2();4 SpecParsed specParsed = specsReader.read(spec);5 assertThat(specParsed.getSpec(), is("sides"));6 assertThat(specParsed.getArgs(), is(Arrays.asList(new SpecArg("10px", SpecArgType.SIZE))));7 }8 public void shouldReadSides_withSpace() throws IOException {9 String spec = "sides: 10px ";10 SpecsReaderV2 specsReader = new SpecsReaderV2();11 SpecParsed specParsed = specsReader.read(spec);12 assertThat(specParsed.getSpec(), is("sides"));13 assertThat(specParsed.getArgs(), is(Arrays.asList(new SpecArg("10px", SpecArgType.SIZE))));14 }15 public void shouldReadSides_withSpaces() throws IOException {16 String spec = "sides: 10px ";17 SpecsReaderV2 specsReader = new SpecsReaderV2();18 SpecParsed specParsed = specsReader.read(spec);19 assertThat(specParsed.getSpec(), is("sides"));20 assertThat(specParsed.getArgs(), is(Arrays.asList(new SpecArg("10px", SpecArgType.SIZE))));21 }22 public void shouldReadSides_withSpaces2() throws IOException {23 String spec = "sides: 10px ";24 SpecsReaderV2 specsReader = new SpecsReaderV2();25 SpecParsed specParsed = specsReader.read(spec);26 assertThat(specParsed.getSpec(), is("sides"));27 assertThat(specParsed.getArgs(), is(Arrays.asList(new SpecArg("10px", SpecArgType.SIZE))));28 }29 public void shouldReadSides_withSpaces3() throws IOException {30 String spec = "sides: 10px ";

Full Screen

Full Screen

sides

Using AI Code Generation

copy

Full Screen

1SpecsReaderV2Test sides = new SpecsReaderV2Test();2String specFile = "src/test/resources/specs/example.spec";3String specText = sides.sides(specFile);4System.out.println(specText);5FileUtils.writeStringToFile(new File("src/test/resources/specs/example2.spec"), specText);6GalenTestBase galen = new GalenTestBase();7galen.load("src/test/resources/specs/example2.spec");8galen.checkLayout("src/test/resources/pages/example.page", "desktop");9galen.checkLayout("src/test/resources/pages/example.page", "mobile");10GalenTestBase galen = new GalenTestBase();11galen.load("src/test/resources/specs/example2.spec");12galen.checkLayout("src/test/resources/pages/example.page", "desktop");13galen.checkLayout("src/test/resources/pages/example.page", "mobile");14GalenTestBase galen = new GalenTestBase();15galen.load("src/test/resources/specs/example2.spec");16galen.checkLayout("src/test/resources/pages/example.page", "desktop");17galen.checkLayout("src/test/resources

Full Screen

Full Screen

sides

Using AI Code Generation

copy

Full Screen

1import static com.galenframework.tests.speclang2.SpecsReaderV2Test.sides2def originalSpecFile = new File("src/test/resources/specs/example.spec")3def objectSpecs = SpecsReaderV2.readSpecs(originalSpecFile)4def generatedSpecFile = new File("target/generated.spec")5SpecsGeneratorV2.generateSpecs(objectSpecs, generatedSpecFile)6def originalSpecFile = new File("src/test/resources/specs/example.spec")7def objectSpecs = SpecsReaderV2.readSpecs(originalSpecFile)8def generatedSpecFile = new File("target/generated.spec")9SpecsGeneratorV2.generateSpecs(objectSpecs, generatedSpecFile, "phone")10def originalSpecFile = new File("src/test/resources/specs/example.spec")11def objectSpecs = SpecsReaderV2.readSpecs(originalSpecFile)12def generatedSpecFile = new File("target/generated.spec")13SpecsGeneratorV2.generateSpecs(objectSpecs, generatedSpecFile, "phone")

Full Screen

Full Screen

sides

Using AI Code Generation

copy

Full Screen

1import com.galenframework.tests.speclang2.SpecsReaderV2Test;2SpecsReaderV2Test specsReaderV2Test = new SpecsReaderV2Test();3List<String> sides = specsReaderV2Test.sides();4boolean containsExpectedSide = sides.contains("left");5System.out.println("The list of all sides contains the expected side: " + containsExpectedSide);6System.out.println("The list of all sides: " + sides);7System.out.println("The expected side: left");8System.out.println("The list of all sides: " + sides);

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Galen automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in SpecsReaderV2Test

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful