This is an automated email from the ASF dual-hosted git repository.

leerho pushed a commit to branch integrateJava17_v3
in repository https://gitbox.apache.org/repos/asf/datasketches-memory.git

commit 1a8c9a7ed3dde6b8e9f9f4b51a1d43e9300c7f04
Author: Lee Rhodes <[email protected]>
AuthorDate: Sun Oct 1 12:17:06 2023 -0700

    Change method of accessing Resource file GettysburgAddress.txt
---
 .../AllocateDirectWritableMapMemoryTest.java       |  7 ++--
 .../internal/AllocateDirectMapMemoryTest.java      | 16 ++++-----
 .../AllocateDirectWritableMapMemoryTest.java       |  9 ++---
 .../datasketches/memory/internal/TestUtil.java     | 40 ++++++++++++++++++++++
 4 files changed, 57 insertions(+), 15 deletions(-)

diff --git 
a/datasketches-memory-java17/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectWritableMapMemoryTest.java
 
b/datasketches-memory-java17/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectWritableMapMemoryTest.java
index 1f33854..500ee42 100644
--- 
a/datasketches-memory-java17/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectWritableMapMemoryTest.java
+++ 
b/datasketches-memory-java17/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectWritableMapMemoryTest.java
@@ -24,6 +24,7 @@
 package org.apache.datasketches.memory.internal;
 
 import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.apache.datasketches.memory.internal.TestUtil.gettysPath;
 import static org.apache.datasketches.memory.internal.Util.getResourceFile;
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertFalse;
@@ -59,7 +60,7 @@ public class AllocateDirectWritableMapMemoryTest {
   public void simpleMap()
       throws IllegalArgumentException, InvalidPathException, 
IllegalStateException, UnsupportedOperationException,
       IOException, SecurityException {
-    File file = getResourceFile("GettysburgAddress.txt");
+    File file = gettysPath.resolve("GettysburgAddress.txt").toFile();
     Memory mem = null;
     try (ResourceScope scope = ResourceScope.newConfinedScope()) {
       mem = Memory.map(file,scope);
@@ -143,7 +144,7 @@ public class AllocateDirectWritableMapMemoryTest {
   public void simpleMap2()
       throws IllegalArgumentException, InvalidPathException, 
IllegalStateException, UnsupportedOperationException,
       IOException, SecurityException {
-    File file = getResourceFile("GettysburgAddress.txt");
+    File file = gettysPath.resolve("GettysburgAddress.txt").toFile();
     assertTrue(file.canRead());
     assertFalse(file.canWrite());
     WritableMemory wmem = null;
@@ -157,7 +158,7 @@ public class AllocateDirectWritableMapMemoryTest {
   public void checkReadException()
       throws IllegalArgumentException, InvalidPathException, 
IllegalStateException, UnsupportedOperationException,
       IOException, SecurityException {
-    File file = getResourceFile("GettysburgAddress.txt");
+    File file = gettysPath.resolve("GettysburgAddress.txt").toFile();
     WritableMemory wmem = null;
     try (ResourceScope scope = ResourceScope.newConfinedScope()) {
       wmem = WritableMemory.writableMap(file, 0, 1 << 20, scope, 
ByteOrder.nativeOrder());
diff --git 
a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectMapMemoryTest.java
 
b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectMapMemoryTest.java
index 423e59a..6eef570 100644
--- 
a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectMapMemoryTest.java
+++ 
b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectMapMemoryTest.java
@@ -23,7 +23,7 @@
 
 package org.apache.datasketches.memory.internal;
 
-import static org.apache.datasketches.memory.internal.Util.getResourceFile;
+import static org.apache.datasketches.memory.internal.TestUtil.gettysPath;
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertTrue;
 import static org.testng.Assert.fail;
@@ -45,7 +45,7 @@ public class AllocateDirectMapMemoryTest {
 
   @Test(expectedExceptions = IllegalStateException.class)
   public void simpleMap() {
-    File file = getResourceFile("GettysburgAddress.txt");
+    File file = gettysPath.resolve("GettysburgAddress.txt").toFile();
     assertTrue(AllocateDirectWritableMap.isFileReadOnly(file));
     try (Memory mem = Memory.map(file)) {
       mem.close(); //explicit close
@@ -54,7 +54,7 @@ public class AllocateDirectMapMemoryTest {
 
   @Test
   public void printGettysbergAddress()  {
-    File file = getResourceFile("GettysburgAddress.txt");
+    File file = gettysPath.resolve("GettysburgAddress.txt").toFile();
     try (Memory mem = Memory.map(file))
     {
       println("Mem Cap:       " + mem.getCapacity());
@@ -79,7 +79,7 @@ public class AllocateDirectMapMemoryTest {
 
   @Test
   public void testIllegalArguments() {
-    File file = getResourceFile("GettysburgAddress.txt");
+    File file = gettysPath.resolve("GettysburgAddress.txt").toFile();
     try (Memory mem = Memory.map(file, -1, Integer.MAX_VALUE, 
ByteOrder.nativeOrder())) {
       fail("Failed: Position was negative.");
     } catch (IllegalArgumentException e) {
@@ -95,7 +95,7 @@ public class AllocateDirectMapMemoryTest {
 
   @Test(expectedExceptions = IllegalStateException.class)
   public void testAccessAfterClose() {
-    File file = getResourceFile("GettysburgAddress.txt");
+    File file = gettysPath.resolve("GettysburgAddress.txt").toFile();
     long memCapacity = file.length();
     try (Memory mem = Memory.map(file, 0, memCapacity, 
ByteOrder.nativeOrder())) {
       assertEquals(memCapacity, mem.getCapacity());
@@ -107,7 +107,7 @@ public class AllocateDirectMapMemoryTest {
 
   @Test(expectedExceptions = IllegalStateException.class)
   public void testReadFailAfterClose()  {
-    File file = getResourceFile("GettysburgAddress.txt");
+    File file = gettysPath.resolve("GettysburgAddress.txt").toFile();
     long memCapacity = file.length();
     Memory mem = Memory.map(file, 0, memCapacity, ByteOrder.nativeOrder());
     mem.close();
@@ -116,7 +116,7 @@ public class AllocateDirectMapMemoryTest {
 
   @Test
   public void testLoad()  {
-    File file = getResourceFile("GettysburgAddress.txt");
+    File file = gettysPath.resolve("GettysburgAddress.txt").toFile();
     long memCapacity = file.length();
     try (Memory mem = Memory.map(file, 0, memCapacity, 
ByteOrder.nativeOrder())) {
       mem.load();
@@ -139,7 +139,7 @@ public class AllocateDirectMapMemoryTest {
    */
   static void print(final Object o) {
     if (o != null) {
-      //System.out.print(o.toString()); //disable here
+      System.out.print(o.toString()); //disable here
     }
   }
 
diff --git 
a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectWritableMapMemoryTest.java
 
b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectWritableMapMemoryTest.java
index 98d3c2a..865157b 100644
--- 
a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectWritableMapMemoryTest.java
+++ 
b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectWritableMapMemoryTest.java
@@ -24,7 +24,7 @@
 package org.apache.datasketches.memory.internal;
 
 import static java.nio.charset.StandardCharsets.UTF_8;
-import static org.apache.datasketches.memory.internal.Util.getResourceFile;
+import static org.apache.datasketches.memory.internal.TestUtil.gettysPath;
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertTrue;
 import static org.testng.Assert.fail;
@@ -42,6 +42,7 @@ import org.apache.datasketches.memory.WritableMemory;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
 
+@SuppressWarnings("javadoc")
 public class AllocateDirectWritableMapMemoryTest {
   private static final String LS = System.getProperty("line.separator");
 
@@ -52,7 +53,7 @@ public class AllocateDirectWritableMapMemoryTest {
 
   @Test
   public void simpleMap() throws Exception {
-    File file = getResourceFile("GettysburgAddress.txt");
+    File file = gettysPath.resolve("GettysburgAddress.txt").toFile();
     try (Memory mem = Memory.map(file)) {
       byte[] bytes = new byte[(int)mem.getCapacity()];
       mem.getByteArray(0, bytes, 0, bytes.length);
@@ -133,7 +134,7 @@ public class AllocateDirectWritableMapMemoryTest {
 
   @Test(expectedExceptions = ReadOnlyException.class)
   public void simpleMap2() throws IOException {
-    File file = getResourceFile("GettysburgAddress.txt");
+    File file = gettysPath.resolve("GettysburgAddress.txt").toFile();
     assertTrue(file.canRead() && !file.canWrite());
     try (WritableMemory wmem = WritableMemory.writableMap(file)) { //throws
       //
@@ -142,7 +143,7 @@ public class AllocateDirectWritableMapMemoryTest {
 
   @Test(expectedExceptions = ReadOnlyException.class)
   public void checkOverLength() throws Exception  {
-    File file = getResourceFile("GettysburgAddress.txt");
+    File file = gettysPath.resolve("GettysburgAddress.txt").toFile();
     WritableMemory.writableMap(file, 0, 1 << 20, ByteOrder.nativeOrder());
   }
 
diff --git 
a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/TestUtil.java
 
b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/TestUtil.java
new file mode 100644
index 0000000..4fc3162
--- /dev/null
+++ 
b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/TestUtil.java
@@ -0,0 +1,40 @@
+/*
+ * 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.datasketches.memory.internal;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+/**
+ * Utilities for Test
+ */
+public class TestUtil {
+  private static String userDir = System.getProperty("user.dir");
+
+  public static Path gettysPath = createPath("src/test/resources");
+
+  private static Path createPath(final String projectLocalDir) {
+    try {
+      return Files.createDirectories(Paths.get(userDir, projectLocalDir));
+    } catch (IOException e) { throw new 
IllegalArgumentException(e.getCause().toString()); }
+  }
+}


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

Reply via email to