Skip to content

Commit 3f87234

Browse files
committed
Port TokenTest to Scalatest
1 parent 688e203 commit 3f87234

File tree

1 file changed

+38
-36
lines changed

1 file changed

+38
-36
lines changed

geocss/src/test/scala/TokenTest.scala

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,55 @@
11
package org.geoscript.geocss
22

3-
import org.specs2._
43
import org.opengis.filter.Filter.{ INCLUDE, EXCLUDE }
54
import org.opengis.{ filter => ogc }
5+
import org.scalatest._, matchers._
66

77
/**
88
* Tests for token methods
99
*/
10-
class TokenTest extends Specification with matcher.DataTables {
10+
class TokenTest extends FunSuite with ShouldMatchers {
1111
val filterFactory =
1212
org.geotools.factory.CommonFactoryFinder.getFilterFactory2(null)
1313
import filterFactory._
1414

15-
val expr =
16-
(org.geotools.filter.text.ecql.ECQL.toFilter(_: String)) andThen
17-
(Selector.asSelector)
15+
val expr = (x: String) =>
16+
Selector.asSelector(org.geotools.filter.text.ecql.ECQL.toFilter(x))
1817
val expr1 = expr("a>b")
1918
val expr2 = expr("c<d")
2019

21-
def is =
22-
"'And' Selectors should do some basic simplification" ^
23-
"empty And goes to Include" ! {
24-
And(Nil).filterOpt must beSome(INCLUDE)
25-
} ^
26-
"single-element And goes to simple filter" ! {
27-
And(List(expr1)).filterOpt must_== expr1.filterOpt
28-
} ^
29-
"'and' filter is correctly generated for larger And's" ! {
30-
And(List(expr1, expr2)).filterOpt must_==
31-
(for { f <- expr1.filterOpt; g <- expr2.filterOpt }
32-
yield and(f, g))
33-
} ^ end ^
34-
"'Not' selectors produce negated Filters" ! {
35-
"selector" | "filter" |
36-
Not(Accept) ! Some(EXCLUDE) |
37-
Not(Not(Accept)) ! Some(INCLUDE) |
38-
Accept ! Some(INCLUDE) |> {
39-
(sel, filt) => sel.filterOpt must_== filt
40-
}
41-
} ^ end ^
42-
"Spot checks on miscellaneous filter combos" ! {
43-
"selector" | "criterion" |
44-
expr1 ! beAnInstanceOf[ogc.PropertyIsGreaterThan] |
45-
Not(expr1) ! beAnInstanceOf[ogc.Not] |
46-
Or(List(expr1)) ! beAnInstanceOf[ogc.PropertyIsGreaterThan] |
47-
And(List(expr1)) ! beAnInstanceOf[ogc.PropertyIsGreaterThan] |
48-
Not(And(List(expr1))) ! beAnInstanceOf[ogc.Not] |
49-
Or(List(And(List(expr1)))) ! beAnInstanceOf[ogc.PropertyIsGreaterThan] |
50-
Or(List(And(List(Not(expr1))))) ! beAnInstanceOf[ogc.Not] |>
51-
{ (sel, pass) => sel.filterOpt must beSome.which(_ must pass) }
20+
test("empty And goes to Include") {
21+
And(Nil).filterOpt should be(Some(INCLUDE))
22+
}
23+
24+
test("single-element And goes to simple filter") {
25+
And(List(expr1)).filterOpt should equal(expr1.filterOpt)
26+
}
27+
28+
test("'and' filter is correctly generated for larger And's") {
29+
val expected =
30+
for {
31+
f <- expr1.filterOpt
32+
g <- expr2.filterOpt
33+
} yield and(f, g)
34+
35+
expect(expected) {
36+
And(List(expr1, expr2)).filterOpt
5237
}
38+
}
39+
40+
test("'Not' selectors produce negated Filters") {
41+
Not(Accept).filterOpt should equal(Some(EXCLUDE))
42+
Not(Not(Accept)).filterOpt should equal(Some(INCLUDE))
43+
Accept.filterOpt should equal(Some(INCLUDE))
44+
}
45+
46+
test("Spot checks on miscellaneous filter combos") {
47+
assert(expr1.filterOpt exists(_.isInstanceOf[ogc.PropertyIsGreaterThan]))
48+
assert(Not(expr1).filterOpt exists(_.isInstanceOf[ogc.Not]))
49+
assert(Or(List(expr1)).filterOpt exists(_.isInstanceOf[ogc.PropertyIsGreaterThan]))
50+
assert(And(List(expr1)).filterOpt exists(_.isInstanceOf[ogc.PropertyIsGreaterThan]))
51+
assert(Not(And(List(expr1))).filterOpt exists(_.isInstanceOf[ogc.Not]))
52+
assert(Or(List(And(List(expr1)))).filterOpt exists(_.isInstanceOf[ogc.PropertyIsGreaterThan]))
53+
assert(Or(List(And(List(Not(expr1))))).filterOpt exists(_.isInstanceOf[ogc.Not]))
54+
}
5355
}

0 commit comments

Comments
 (0)