Added tests for the ERROR and TRUNCATE long file modes of TarArchiveOutputStream

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/compress/trunk@1511218 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStreamTest.java b/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStreamTest.java
index 31cbc60..ea87031 100644
--- a/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStreamTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStreamTest.java
@@ -372,6 +372,46 @@
         tin.close();
     }
 
+    public void testWriteLongDirectoryNameErrorMode() throws Exception {
+        String n = "01234567890123456789012345678901234567890123456789"
+                + "01234567890123456789012345678901234567890123456789"
+                + "01234567890123456789012345678901234567890123456789/";
+
+        try {
+            TarArchiveEntry t = new TarArchiveEntry(n);
+            ByteArrayOutputStream bos = new ByteArrayOutputStream();
+            TarArchiveOutputStream tos = new TarArchiveOutputStream(bos, "ASCII");
+            tos.setLongFileMode(TarArchiveOutputStream.LONGFILE_ERROR);
+            tos.putArchiveEntry(t);
+            tos.closeArchiveEntry();
+            tos.close();
+            
+            fail("Truncated name didn't throw an exception");
+        } catch (RuntimeException e) {
+            // expected
+        }
+    }
+
+    public void testWriteLongDirectoryNameTruncateMode() throws Exception {
+        String n = "01234567890123456789012345678901234567890123456789"
+            + "01234567890123456789012345678901234567890123456789"
+            + "01234567890123456789012345678901234567890123456789/";
+        TarArchiveEntry t = new TarArchiveEntry(n);
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        TarArchiveOutputStream tos = new TarArchiveOutputStream(bos, "ASCII");
+        tos.setLongFileMode(TarArchiveOutputStream.LONGFILE_TRUNCATE);
+        tos.putArchiveEntry(t);
+        tos.closeArchiveEntry();
+        tos.close();
+        byte[] data = bos.toByteArray();
+        TarArchiveInputStream tin =
+            new TarArchiveInputStream(new ByteArrayInputStream(data));
+        TarArchiveEntry e = tin.getNextTarEntry();
+        assertEquals("Entry name", n.substring(0, TarConstants.NAMELEN) + "/", e.getName());
+        assertTrue("The entry is not a directory", e.isDirectory());
+        tin.close();
+    }
+
     /**
      * @see "https://issues.apache.org/jira/browse/COMPRESS-203"
      */