package com.adaptris.core.http.jetty.retry;

import static com.adaptris.core.http.jetty.retry.FilesystemRetryStoreTest.TEST_BASE_URL;
import static org.junit.Assert.assertEquals;
import java.io.File;
import java.io.FileFilter;
import org.apache.commons.io.filefilter.DirectoryFileFilter;
import org.junit.Test;
import com.adaptris.core.AdaptrisMessage;
import com.adaptris.core.DefaultMessageFactory;
import com.adaptris.core.ServiceException;
import com.adaptris.core.fs.FsHelper;
import com.adaptris.interlok.junit.scaffolding.BaseCase;
import com.adaptris.interlok.junit.scaffolding.services.ExampleServiceCase;

public class RetryStoreWriteTest extends ExampleServiceCase {

  @Test
  public void testService() throws Exception {
    File retryStoreDir = FsHelper.toFile(BaseCase.getConfiguration(TEST_BASE_URL));
    AdaptrisMessage msg = new DefaultMessageFactory().newMessage("hello");
    RetryStoreWriteService service = new RetryStoreWriteService()
        .withRetryStore(new FilesystemRetryStore().withBaseUrl(getConfiguration(TEST_BASE_URL)));
    int base = retryStoreDir.listFiles((FileFilter) DirectoryFileFilter.DIRECTORY).length;
    execute(service, msg);
    assertEquals(1,
        retryStoreDir.listFiles((FileFilter) DirectoryFileFilter.DIRECTORY).length - base);
  }

  @Test(expected = ServiceException.class)
  public void testService_Exception() throws Exception {
    File retryStoreDir = FsHelper.toFile(BaseCase.getConfiguration(TEST_BASE_URL));
    AdaptrisMessage msg = new DefaultMessageFactory().newMessage("hello");
    RetryStoreWriteService service = new RetryStoreWriteService()
        .withRetryStore(
            new FilesystemRetryStore().withBaseUrl(getConfiguration(TEST_BASE_URL) + "/ invalid"));
    execute(service, msg);
  }

  @Override
  protected RetryStoreWriteService retrieveObjectForSampleConfig() {
    return new RetryStoreWriteService().withRetryStore(new FilesystemRetryStore().withBaseUrl("file:///path/to/store"));

  }
}

@@ -212,32 +212,59 @@
 .io.FileFilter;%0A
+import java.util.Optional;%0A
 import org.apach
@@ -1085,16 +1085,20 @@
     
-int base
+File%5B%5D files
  = r
@@ -1159,24 +1159,87 @@
 r.DIRECTORY)
+;%0A    int base = Optional.ofNullable(files).orElse(new File%5B0%5D)
 .length;%0A   
@@ -1483,92 +1483,8 @@
 n %7B%0A
-    File retryStoreDir = FsHelper.toFile(BaseCase.getConfiguration(TEST_BASE_URL));%0A
     

Add null protection for listing files.