ramitg254 commented on code in PR #471:
URL: https://github.com/apache/tez/pull/471#discussion_r3008908869


##########
tez-tools/analyzers/job-analyzer/src/test/java/org/apache/tez/analyzer/TestCSVResult.java:
##########
@@ -0,0 +1,122 @@
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.tez.analyzer;
+
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.AccessDeniedException;
+import java.nio.file.FileAlreadyExistsException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+
+import org.junit.Assert;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+
+public class TestCSVResult {
+
+  @Rule
+  public TemporaryFolder tmpDir = new TemporaryFolder();
+
+  @Test
+  public void testDumpToFileWritesContent() throws Exception {
+    Path out = tmpDir.newFolder().toPath().resolve("out.csv");
+    CSVResult result = new CSVResult(new String[]{"h1", "h2"});
+    result.addRecord(new String[]{"a", "b"});
+    result.dumpToFile(out.toString());
+    String content = new String(Files.readAllBytes(out), 
StandardCharsets.UTF_8);
+    Assert.assertEquals("h1,h2\na,b\n", content);
+  }
+
+  @Test
+  public void testDumpToFileRejectsExistingFile() throws Exception {
+    Path out = tmpDir.newFile("existing.csv").toPath();
+    CSVResult result = new CSVResult(new String[]{"x"});
+    try {
+      result.dumpToFile(out.toString());
+      Assert.fail("Expected FileAlreadyExistsException when output file 
already exists");
+    } catch (FileAlreadyExistsException e) {
+      Assert.assertTrue("expected File Already Exist Exception", 
e.getMessage().contains(out.toString()));
+    }
+  }
+
+  @Test
+  public void testDumpToFileRejectsMissingParentDir() throws Exception {
+    Path missingParent = tmpDir.getRoot().toPath().resolve("no-such-dir");
+    Path out = missingParent.resolve("out.csv");
+    CSVResult result = new CSVResult(new String[]{"x"});
+    try {
+      result.dumpToFile(out.toString());
+      Assert.fail("Expected IOException when parent directory does not exist");
+    } catch (IOException e) {
+      Assert.assertTrue(e.getMessage().contains("Parent directory does not 
exist"));
+    }
+  }
+
+  @Test(expected = IllegalArgumentException.class)
+  public void testDumpToFileRejectsNullFileName() throws Exception {
+    new CSVResult(new String[]{"x"}).dumpToFile(null);
+  }
+
+  @Test(expected = IllegalArgumentException.class)
+  public void testDumpToFileRejectsEmptyFileName() throws Exception {
+    new CSVResult(new String[]{"x"}).dumpToFile("");
+  }
+
+  @Test(expected = IllegalArgumentException.class)
+  public void testDumpToFileRejectsBlankFileName() throws Exception {
+    new CSVResult(new String[]{"x"}).dumpToFile("   ");
+  }
+
+  @Test
+  public void testDumpToFileNestedDirectory() throws Exception {
+    Path base = tmpDir.newFolder().toPath();
+    Path nested = base.resolve("a").resolve("b");
+    Files.createDirectories(nested);
+    Path out = nested.resolve("nested.csv");
+    CSVResult result = new CSVResult(new String[]{"h"});
+    result.addRecord(new String[]{"r"});
+    result.dumpToFile(out.toString());
+    Assert.assertEquals("h\nr\n", new String(Files.readAllBytes(out), 
StandardCharsets.UTF_8));
+  }
+
+  @Test
+  public void testDumpToFileNoWritePermissionRelativePath() throws Exception {

Review Comment:
   done added like if with use paths like ../ moves upward from the pwd from 
which process was launched it should throw IO exception



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