JoshRosen commented on code in PR #36885:
URL: https://github.com/apache/spark/pull/36885#discussion_r898646978


##########
core/src/test/scala/org/apache/spark/util/JsonProtocolSuite.scala:
##########
@@ -610,13 +618,34 @@ class JsonProtocolSuite extends SparkFunSuite {
         |  "Event" : "org.apache.spark.util.TestListenerEvent",
         |  "foo" : "foo"
         |}""".stripMargin
-    assert(JsonProtocol.sparkEventFromJson(parse(unknownFieldsJson)) === 
expected)
+    assert(JsonProtocol.sparkEventFromJson(unknownFieldsJson) === expected)
   }
 }
 
 
 private[spark] object JsonProtocolSuite extends Assertions {
   import InternalAccumulator._
+  import JsonProtocol.toJsonString
+
+  private val mapper = new ObjectMapper()
+
+  private implicit class JsonStringImplicits(json: String) {
+    def removeField(field: String): String = {
+      val tree = mapper.readTree(json)
+      
Option(tree.asInstanceOf[ObjectNode].findParent(field)).foreach(_.remove(field))
+      tree.toString
+    }
+
+    def addStringField(k: String, v: String): String = {
+      val tree = mapper.readTree(json)
+      tree.asInstanceOf[ObjectNode].set(k, new TextNode(v))
+      tree.toString
+    }
+  }
+
+  private implicit def toJsonNode(json: String): JsonNode = {

Review Comment:
   This implicit greatly reduces the amount of boilerplate needed in each test. 
To me, this seems preferable to having to update hundreds of lines of test 
cases in this file.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to