aglinxinyuan commented on code in PR #6095:
URL: https://github.com/apache/texera/pull/6095#discussion_r3522748891


##########
common/workflow-core/src/test/scala/org/apache/texera/amber/core/storage/model/ReadonlyLocalFileDocumentSpec.scala:
##########
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.texera.amber.core.storage.model
+
+import org.scalatest.flatspec.AnyFlatSpec
+import org.scalatest.matchers.should.Matchers
+
+import java.io.File
+import java.nio.file.Files
+
+class ReadonlyLocalFileDocumentSpec extends AnyFlatSpec with Matchers {
+
+  private def withTempDoc(
+      content: String
+  )(body: (ReadonlyLocalFileDocument, File) => Unit): Unit = {
+    val tmp = File.createTempFile("readonly-local-", ".txt")
+    try {
+      Files.write(tmp.toPath, content.getBytes("UTF-8"))

Review Comment:
   Done — switched to `content.getBytes(StandardCharsets.UTF_8)` (Charset 
overload).



##########
common/workflow-core/src/test/scala/org/apache/texera/amber/core/storage/model/ReadonlyLocalFileDocumentSpec.scala:
##########
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.texera.amber.core.storage.model
+
+import org.scalatest.flatspec.AnyFlatSpec
+import org.scalatest.matchers.should.Matchers
+
+import java.io.File
+import java.nio.file.Files
+
+class ReadonlyLocalFileDocumentSpec extends AnyFlatSpec with Matchers {
+
+  private def withTempDoc(
+      content: String
+  )(body: (ReadonlyLocalFileDocument, File) => Unit): Unit = {
+    val tmp = File.createTempFile("readonly-local-", ".txt")
+    try {
+      Files.write(tmp.toPath, content.getBytes("UTF-8"))
+      body(new ReadonlyLocalFileDocument(tmp.toURI), tmp)
+    } finally {
+      tmp.delete()
+    }
+  }
+
+  "ReadonlyLocalFileDocument" should "expose the backing URI and file" in {
+    withTempDoc("hello") { (doc, tmp) =>
+      doc.getURI shouldBe tmp.toURI
+      doc.asFile() shouldBe new File(tmp.toURI)
+      doc.asFile().getCanonicalFile shouldBe tmp.getCanonicalFile
+    }
+  }
+
+  it should "read the file contents through an input stream" in {
+    withTempDoc("hello world") { (doc, _) =>
+      val in = doc.asInputStream()
+      try new String(in.readAllBytes(), "UTF-8") shouldBe "hello world"

Review Comment:
   Done — the read assertion now uses `new String(bytes, 
StandardCharsets.UTF_8)`.



##########
common/workflow-core/src/test/scala/org/apache/texera/amber/core/storage/model/VirtualDocumentSpec.scala:
##########
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.texera.amber.core.storage.model
+
+import org.scalatest.flatspec.AnyFlatSpec
+import org.scalatest.matchers.should.Matchers
+
+import java.io.ByteArrayInputStream
+import java.net.URI
+
+class VirtualDocumentSpec extends AnyFlatSpec with Matchers {
+
+  // A minimal concrete document overriding only the two abstract members
+  // (getURI, clear); every other method keeps its default throwing body.
+  private class MinimalDoc extends VirtualDocument[Int] {
+    override def getURI: URI = new URI("file:///stub/doc")
+    override def clear(): Unit = ()
+  }
+
+  private def doc: VirtualDocument[Int] = new MinimalDoc
+
+  "VirtualDocument" should "return the implemented URI and support clear" in {
+    doc.getURI shouldBe new URI("file:///stub/doc")
+    noException should be thrownBy doc.clear()
+  }

Review Comment:
   Good catch — `doc` is now a single shared `val`, so the URI and clear() 
assertions run against the same instance.



-- 
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]

Reply via email to