Skip to content

Commit

Permalink
Update Scala version & refactor tests (playframework#495)
Browse files Browse the repository at this point in the history
  • Loading branch information
cchantep authored Aug 21, 2020
1 parent f738239 commit 071844b
Show file tree
Hide file tree
Showing 17 changed files with 523 additions and 602 deletions.
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ rewrite.neverInfix.excludeFilters = [
# better for play-json dsl
and, andKeep, andThen,
# For scalatest
in, should, when
in, should, when, mustEqual, mustBe
]
rewrite.sortModifiers.order = [ "private", "protected", "final", "sealed", "abstract", "implicit", "override", "lazy" ]
spaces.inImportCurlyBraces = true # more idiomatic to include whitespace in import x.{ yyy }
Expand Down
11 changes: 5 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,27 @@ jobs:

- stage: test
name: "Run tests with Scala 2.12 and AdoptOpenJDK 11"
script: scripts/test-code.sh
env:
- TRAVIS_SCALA_VERSION=2.12.10
- TRAVIS_SCALA_VERSION=2.12.12
- TRAVIS_JDK=11
script: echo "Foo: ${TRAVIS_SCALA_VERSION}" && scripts/test-code.sh

- name: "Run tests with Scala 2.13 and AdoptOpenJDK 11"
script: scripts/test-code.sh
env:
- TRAVIS_SCALA_VERSION=2.13.1
- TRAVIS_SCALA_VERSION=2.13.2
- TRAVIS_JDK=11

- name: "Run tests with Scala 2.12 and AdoptOpenJDK 8"
script: scripts/test-code.sh
env:
- TRAVIS_SCALA_VERSION=2.12.10
- TRAVIS_SCALA_VERSION=2.12.12
- TRAVIS_JDK=8

- name: "Run tests with Scala 2.13 and AdoptOpenJDK 8"
script: scripts/test-code.sh
env:
- TRAVIS_SCALA_VERSION=2.13.1
- TRAVIS_SCALA_VERSION=2.13.2
- TRAVIS_JDK=8

- stage: publish
Expand All @@ -53,7 +53,6 @@ stages:
- name: publish
if: ((branch = master AND type = push) OR (tag IS present)) AND NOT fork


cache:
directories:
- "$HOME/.cache/coursier"
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ val scalacOpts = Seq(
"-Ywarn-macros:after"
)

val silencerVersion = "1.6.0"
val silencerVersion = "1.7.0"

libraryDependencies in ThisBuild ++= Seq(
compilerPlugin(("com.github.ghik" % "silencer-plugin" % silencerVersion).cross(CrossVersion.full)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class JsObjectSpec extends AnyWordSpec with Matchers {
"field3" -> JsNull
)

populatedObj.deepMerge(Json.obj()).mustEqual(populatedObj)
populatedObj.deepMerge(Json.obj()) mustEqual populatedObj
}

"merge correctly when the incoming object is empty" in {
Expand All @@ -33,7 +33,7 @@ class JsObjectSpec extends AnyWordSpec with Matchers {
"field3" -> JsNull
)

Json.obj().deepMerge(populatedObj).mustEqual(populatedObj)
Json.obj().deepMerge(populatedObj) mustEqual populatedObj
}
}

Expand Down Expand Up @@ -203,7 +203,7 @@ class JsObjectSpec extends AnyWordSpec with Matchers {
"field5" -> "def",
"field6" -> JsNull
)
Json.stringify(obj1 ++ obj2).mustEqual(Json.stringify(expected))
Json.stringify(obj1 ++ obj2) mustEqual Json.stringify(expected)
}
}

Expand All @@ -226,7 +226,8 @@ class JsObjectSpec extends AnyWordSpec with Matchers {
"field5" -> "def",
"field6" -> JsNull
)
Json.stringify(obj1 + field4 + field5 + field6).mustEqual(Json.stringify(expected))

Json.stringify(obj1 + field4 + field5 + field6) mustEqual Json.stringify(expected)
}
}

Expand All @@ -245,7 +246,8 @@ class JsObjectSpec extends AnyWordSpec with Matchers {
"field5" -> "def",
"field6" -> JsNull
)
Json.stringify(originalObj - "field1" - "field2" - "field3").mustEqual(Json.stringify(expected))

Json.stringify(originalObj - "field1" - "field2" - "field3") mustEqual Json.stringify(expected)
}
}

Expand All @@ -259,7 +261,7 @@ class JsObjectSpec extends AnyWordSpec with Matchers {
)
val expected = """{"field1":null,"field2":null,"field3":null}"""

Json.stringify(originalObj).mustEqual(expected)
Json.stringify(originalObj) mustEqual expected
}

"accept null fields when calling Json.arr" in {
Expand All @@ -272,7 +274,7 @@ class JsObjectSpec extends AnyWordSpec with Matchers {
)
val expected = """{"arrayWithNulls":[null,null,null]}"""

Json.stringify(originalObj).mustEqual(expected)
Json.stringify(originalObj) mustEqual expected
}
}
}
32 changes: 17 additions & 15 deletions play-json/shared/src/test/scala/play/api/libs/json/JsPathSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ class JsPathSpec extends AnyWordSpec with Matchers {
"retrieve simple path" in {
val obj = Json.obj("key1" -> Json.obj("key11" -> "value11"), "key2" -> "value2")

(JsPath \ "key1" \ "key11")(obj).mustEqual(Seq(JsString("value11")))
(JsPath \ "key1" \ "key11")(obj) mustEqual Seq(JsString("value11"))
}

"retrieve path with array index" in {
val obj = Json.obj("key1" -> Json.arr(Json.obj("key11" -> "value11")))

(JsPath \ "key1" \ 0 \ "key11")(obj).mustEqual(Seq(JsString("value11")))
(JsPath \ "key1" \ 0 \ "key11")(obj) mustEqual Seq(JsString("value11"))
}

"retrieve 1-level recursive path" in {
Expand Down Expand Up @@ -70,15 +70,15 @@ class JsPathSpec extends AnyWordSpec with Matchers {
"level2" -> 5
)

(JsPath \\ "tags" \ "sub")(obj).mustEqual(Seq(JsString("alpha1"), JsString("beta2")))
(JsPath \\ "tags" \ "sub")(obj) mustEqual Seq(JsString("alpha1"), JsString("beta2"))
}

"retrieve simple indexed path" in {
val obj = Json.obj(
"level1" -> Json.arr(5, "alpha", true)
)

(JsPath \ "level1")(2)(obj).mustEqual(Seq(JsBoolean(true)))
(JsPath \ "level1")(2)(obj) mustEqual Seq(JsBoolean(true))
}

"retrieve 2-level recursive indexed path #1" in {
Expand All @@ -94,7 +94,7 @@ class JsPathSpec extends AnyWordSpec with Matchers {
"level2" -> 5
)

(JsPath \ "level1" \\ "tags")(1)(obj).mustEqual(Seq(JsString("beta1"), JsString("beta2")))
(JsPath \ "level1" \\ "tags")(1)(obj) mustEqual Seq(JsString("beta1"), JsString("beta2"))
}

"retrieve 2-level recursive indexed path #2" in {
Expand All @@ -112,7 +112,7 @@ class JsPathSpec extends AnyWordSpec with Matchers {
"level2" -> 5
)

((JsPath \ "level1" \ "key1")(1) \\ "tags")(obj).mustEqual(Seq(Json.arr("alpha1", "beta1", "gamma1")))
((JsPath \ "level1" \ "key1")(1) \\ "tags")(obj) mustEqual Seq(Json.arr("alpha1", "beta1", "gamma1"))
}

"retrieve recursive in jsobject and jsarray #1" in {
Expand Down Expand Up @@ -141,7 +141,7 @@ class JsPathSpec extends AnyWordSpec with Matchers {
"level2" -> 5
)

(JsPath \ "level1" \\ "alpha")(obj).mustEqual(Seq(JsString("value11111"), Json.arr("a", "b", "c")))
(JsPath \ "level1" \\ "alpha")(obj) mustEqual Seq(JsString("value11111"), Json.arr("a", "b", "c"))
}

"retrieve recursive in jsobject and jsarray #2" in {
Expand All @@ -154,7 +154,7 @@ class JsPathSpec extends AnyWordSpec with Matchers {
)
)

(JsPath \ "array" \\ "beta")(obj).mustEqual(Seq(JsString("v12"), JsString("v22"), JsString("v32")))
(JsPath \ "array" \\ "beta")(obj) mustEqual Seq(JsString("v12"), JsString("v22"), JsString("v32"))
}

"retrieve with symbol keys" in {
Expand Down Expand Up @@ -225,7 +225,7 @@ class JsPathSpec extends AnyWordSpec with Matchers {
"level2" -> 5
)

(__ \ Symbol("level2")).prune(obj).mustEqual(JsSuccess(res, __ \ Symbol("level2")))
(__ \ Symbol("level2")).prune(obj) mustEqual JsSuccess(res, __ \ Symbol("level2"))
(__ \ Symbol("level1") \ Symbol("key1")).prune(obj).get.mustEqual(res2)
(__ \ Symbol("level1") \ Symbol("key2") \ Symbol("key21")).prune(obj).get.mustEqual(res3)
(__ \\ Symbol("key21"))
Expand Down Expand Up @@ -276,15 +276,17 @@ class JsPathSpec extends AnyWordSpec with Matchers {
val path = __ \ "foo" \ "bar" \ "baz"
val reads = path.readNullable[String]

reads.reads(Json.obj()).mustEqual(JsSuccess(None))
reads.reads(Json.obj("foo" -> Json.obj())).mustEqual(JsSuccess(None))
reads.reads(Json.obj("foo" -> Json.obj("bar" -> Json.obj()))).mustEqual(JsSuccess(None))
reads.reads(Json.obj()) mustEqual JsSuccess(None)
reads.reads(Json.obj("foo" -> Json.obj())) mustEqual JsSuccess(None)
reads.reads(Json.obj("foo" -> Json.obj("bar" -> Json.obj()))) mustEqual JsSuccess(None)

reads
.reads(Json.obj("foo" -> Json.obj("bar" -> Json.obj("baz" -> "blah"))))
.mustEqual(JsSuccess(Some("blah"), path))
reads.reads(Json.obj("foo" -> Json.obj("bar" -> Json.obj("baz" -> JsNull)))).mustEqual(JsSuccess(None))
reads.reads(Json.obj("foo" -> Json.obj("bar" -> JsNull))).mustEqual(JsSuccess(None))
reads.reads(Json.obj("foo" -> Json.obj("bar" -> "blah"))).mustEqual(JsSuccess(None))

reads.reads(Json.obj("foo" -> Json.obj("bar" -> Json.obj("baz" -> JsNull)))) mustEqual JsSuccess(None)
reads.reads(Json.obj("foo" -> Json.obj("bar" -> JsNull))) mustEqual JsSuccess(None)
reads.reads(Json.obj("foo" -> Json.obj("bar" -> "blah"))) mustEqual JsSuccess(None)
}

/*"set 1-level field in simple jsobject" in {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,20 @@ class JsResultSpec extends AnyWordSpec with Matchers {
}

"be converted to Success" in {
JsResult.toTry(JsSuccess("foo")).mustEqual(Success("foo"))
JsResult.toTry(JsSuccess("foo")) mustEqual Success("foo")
}

"be converted to basic Failure" in {
val err = JsError("bar")
JsResult.toTry(err).mustEqual(Failure(JsResult.Exception(err)))
JsResult.toTry(err) mustEqual Failure(JsResult.Exception(err))
}

"be created from a Success" in {
JsResult.fromTry(Success("foo")).mustEqual(JsSuccess("foo"))
JsResult.fromTry(Success("foo")) mustEqual JsSuccess("foo")
}

"be created from a Failure" in {
JsResult.fromTry(Failure(new Throwable("bar"))).mustEqual(JsError("bar"))
JsResult.fromTry(Failure(new Throwable("bar"))) mustEqual JsError("bar")
}
}

Expand Down
Loading

0 comments on commit 071844b

Please sign in to comment.