Search in sources :

Example 1 with DefaultTempFile

use of org.nanohttpd.protocols.http.tempfiles.DefaultTempFile in project nanohttpd by NanoHttpd.

the class JavaIOTempDirExistTest method testJavaIoTempDefault.

@Test
public void testJavaIoTempDefault() throws Exception {
    String tmpdir = System.getProperty("java.io.tmpdir");
    DefaultTempFileManager manager = new DefaultTempFileManager();
    DefaultTempFile tempFile = (DefaultTempFile) manager.createTempFile("xx");
    File tempFileBackRef = new File(tempFile.getName());
    Assert.assertEquals(tempFileBackRef.getParentFile(), new File(tmpdir));
    // force an exception
    tempFileBackRef.delete();
    Exception e = null;
    try {
        tempFile.delete();
    } catch (Exception ex) {
        e = ex;
    }
    Assert.assertNotNull(e);
    manager.clear();
}
Also used : DefaultTempFileManager(org.nanohttpd.protocols.http.tempfiles.DefaultTempFileManager) DefaultTempFile(org.nanohttpd.protocols.http.tempfiles.DefaultTempFile) DefaultTempFile(org.nanohttpd.protocols.http.tempfiles.DefaultTempFile) File(java.io.File) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 Test (org.junit.Test)1 DefaultTempFile (org.nanohttpd.protocols.http.tempfiles.DefaultTempFile)1 DefaultTempFileManager (org.nanohttpd.protocols.http.tempfiles.DefaultTempFileManager)1