package com.io7m.jvvfs;

import java.io.IOException;

import org.junit.Test;

import com.io7m.jaux.Constraints.ConstraintError;
import com.io7m.jvvfs.Filesystem;
import com.io7m.jvvfs.FilesystemError;
import com.io7m.jvvfs.PathVirtual;

/**
 * Specifically test the slightly unsafe
 * {@link Filesystem#mountUnsafeClasspathItem(Class, PathVirtual)} function.
 */

public class FilesystemClasspathTest
{
  // private static final String archive_dir = "test-archives";
  // private static Filesystem makeFS()
  // throws IOException,
  // ConstraintError,
  // FilesystemError
  // {
  // final Log log =
  // new Log(
  // PropertyUtils.loadFromFile("io7m-jvvfs.properties"),
  // "com.io7m.jvvfs",
  // "main");
  // return new Filesystem(log, new PathReal(
  // FilesystemClasspathTest.archive_dir));
  // }

  /**
   * Mount a file that exists inside a directory on the classpath.
   * 
   * @throws IOException
   * @throws FilesystemError
   * @throws ConstraintError
   */

  @Test public void testFilesystemClasspathMountFile()
    throws IOException,
      FilesystemError,
      ConstraintError
  {
    // TODO: Work out how to make this test work with maven builds.
    // final Filesystem fs = FilesystemClasspathTest.makeFS();
    // fs.mountUnsafeClasspathItem(this.getClass(), new PathVirtual("/"));
    //
    // final InputStream stream =
    // fs.openFile(new PathVirtual(
    // "/com/io7m/jvvfs/tests/FilesystemClasspathTest.class"));
    // assert stream != null;
  }

  /**
   * Mount a file that exists inside Example.jar on the classpath.
   * 
   * @throws IOException
   * @throws FilesystemError
   * @throws ConstraintError
   */

  @Test public void testFilesystemClasspathMountJar()
    throws IOException,
      FilesystemError,
      ConstraintError
  {
    // TODO: Work out how to make this test work with maven builds.
    // final Filesystem fs = FilesystemClasspathTest.makeFS();
    // fs.mountUnsafeClasspathItem(
    // com.io7m.jvvfs_examples.Example.class,
    // new PathVirtual("/"));
    //
    // final InputStream stream =
    // fs.openFile(new PathVirtual("/com/io7m/jvvfs_examples/Example.class"));
    // assert stream != null;
  }
}

@@ -45,16 +45,76 @@
 ception;
+%0Aimport java.io.InputStream;%0A%0Aimport junit.framework.Assert;
 %0A%0Aimport
@@ -198,31 +198,33 @@
 m.io7m.j
-vvfs.Filesystem
+aux.PropertyUtils
 ;%0Aimport
@@ -238,28 +238,15 @@
 7m.j
-vvfs.FilesystemError
+log.Log
 ;%0Aim
@@ -265,27 +265,36 @@
 m.jvvfs.
-PathVirtual
+FilesystemError.Code
 ;%0A%0A/**%0A 
@@ -460,634 +460,40 @@
 %7B%0A  
-// private static final String archive_dir = %22test-archives%22;%0A  // private static Filesystem makeFS()%0A  // throws IOException,%0A  // ConstraintError,%0A  // FilesystemError%0A  // %7B%0A  // final Log log =%0A  // new Log(%0A  // PropertyUtils.loadFromFile(%22io7m-jvvfs.properties%22),%0A  // %22com.io7m.jvvfs%22,%0A  // %22main%22);%0A  // return new Filesystem(log, new PathReal(%0A  // FilesystemClasspathTest.archive_dir));%0A  // %7D%0A%0A  /**%0A   * Mount a file that exists inside a directory on the classpath.%0A   * %0A   * @throws IOException%0A   * @throws FilesystemError%0A   * @throws ConstraintError%0A   */%0A%0A  @Test public void testFilesystemClasspathMountFile
+private static Filesystem makeFS
 ()%0A 
@@ -515,39 +515,16 @@
 eption,%0A
-      FilesystemError,%0A
       Co
@@ -549,379 +549,173 @@
     
-// TODO: Work out how to make this test work with maven builds.%0A    // final Filesystem fs = FilesystemClasspathTest.makeFS();%0A    // fs.mountUnsafeClasspathItem(this.getClass(), new PathVirtual(%22/%22));%0A    //%0A    // final InputStream stream =%0A    // 
+final Log log =%0A      new Log(%0A        PropertyUtils.loadFromFile(%22io7m-jvv
 fs.
+pr
 ope
-nFile(new PathVirtual(%0A
+rties%22),%0A  
     
-//
+ 
  %22
-/
 com
-/
+.
 io7m
-/
+.
 jvvfs
-/tests/FilesystemClasspathTest.class%22));%0A    // assert stream != null
+%22,%0A        %22main%22);%0A    return new Filesystem(log)
 ;%0A  
@@ -764,19 +764,19 @@
 ide 
-Example.jar
+a directory
  on 
@@ -887,16 +887,51 @@
    */%0A%0A 
+ @SuppressWarnings(%22static-method%22)
  @Test p
@@ -939,13 +939,21 @@
 blic
+%0A   
  void
+%0A   
  tes
@@ -981,14 +981,17 @@
 ount
-Jar
+File
 ()%0A
+  
     
@@ -1016,16 +1016,18 @@
 ,%0A      
+  
 Filesyst
@@ -1033,32 +1033,34 @@
 temError,%0A      
+ 
+ 
 ConstraintError%0A
@@ -1070,79 +1070,8 @@
 %0A   
- // TODO: Work out how to make this test work with maven builds.%0A    //
  fin
@@ -1122,27 +1122,24 @@
 akeFS();%0A   
- //
  fs.mountUns
@@ -1159,61 +1159,25 @@
 tem(
-%0A    // com.io7m.jvvfs_examples.Example.class,%0A    //
+Filesystem.class,
  new
@@ -1200,21 +1200,12 @@
 ));%0A
-    //
 %0A   
- //
  fin
@@ -1232,18 +1232,17 @@
 m =%0A    
-//
+ 
  fs.open
@@ -1282,65 +1282,507 @@
 vvfs
-_examples/Example.class%22));%0A    // assert stream != null;
+/Filesystem.class%22));%0A    assert stream != null;%0A  %7D%0A%0A  @SuppressWarnings(%22static-method%22) @Test(expected = FilesystemError.class) public%0A    void%0A    testFilesystemClasspathMountRejected()%0A      throws IOException,%0A        ConstraintError,%0A        FilesystemError%0A  %7B%0A    try %7B%0A      final Filesystem fs = FilesystemClasspathTest.makeFS();%0A      fs.mount(%22nonexistent%22, %22/%22);%0A    %7D catch (final FilesystemError e) %7B%0A      Assert.assertEquals(Code.FS_ERROR_NONEXISTENT, e.code);%0A      throw e;%0A    %7D
 %0A  %7D

Improve unit test coverage