/*
 * The Gemma project
 * 
 * Copyright (c) 2006 University of British Columbia
 * 
 * Licensed 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
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * 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 ubic.gemma.loader.util.fetcher;

import java.io.File;
import java.util.Collection;

import org.apache.commons.lang.RandomStringUtils;

import ubic.gemma.model.common.description.LocalFile;
import junit.framework.TestCase;

/**
 * @author pavlidis
 * @version $Id$
 */
public class AbstractFetcherTest extends TestCase {

    File f;

    /**
     * Test method for {@link ubic.gemma.loader.util.fetcher.AbstractFetcher#mkdir(java.lang.String)}.
     */
    public final void testMkdirMakeTemp() throws Exception {
        TestFetcher tf = new TestFetcher();
        tf.setLocalDataPath( "there is no way this path exists \\/[]" );
        f = tf.mkdir( RandomStringUtils.randomAlphabetic( 4 ) );
        assertTrue( f.canRead() );
    }

    /**
     * Test method for {@link ubic.gemma.loader.util.fetcher.AbstractFetcher#mkdir(java.lang.String)}.
     */
    public final void testMkdirMakeSubdirs() throws Exception {
        TestFetcher tf = new TestFetcher();
        String usertempdir = System.getProperty( "java.io.tmpdir" );
        assertTrue( usertempdir != null );
        tf.setLocalDataPath( usertempdir );
        f = tf.mkdir( RandomStringUtils.randomAlphabetic( 4 ) );
        assertTrue( f.canRead() );
    }

    /**
     * Test method for {@link ubic.gemma.loader.util.fetcher.AbstractFetcher#mkdir(java.lang.String)}.
     */
    public final void testMkdirAlreadyExists() throws Exception {
        TestFetcher tf = new TestFetcher();
        String name = RandomStringUtils.randomAlphabetic( 4 );
        String usertempdir = System.getProperty( "java.io.tmpdir" );
        assert ( usertempdir != null );
        File g = new File( usertempdir + File.separatorChar + name );
        assert ( g.mkdir() );

        tf.setLocalDataPath( usertempdir );
        f = tf.mkdir( RandomStringUtils.randomAlphabetic( 4 ) );
        assertTrue( f.canRead() );
    }

    /*
     * (non-Javadoc)
     * 
     * @see junit.framework.TestCase#tearDown()
     */
    @Override
    protected void tearDown() throws Exception {

        super.tearDown();
        if ( f != null && f.canRead() ) {
            f.delete();
        }
    }

    class TestFetcher extends AbstractFetcher {

        public void setLocalDataPath( String localDataPath ) {
            this.localBasePath = localDataPath;
        }

        /*
         * (non-Javadoc)
         * 
         * @see ubic.gemma.loader.util.fetcher.Fetcher#fetch(java.lang.String)
         */@SuppressWarnings("unused")
        public Collection<LocalFile> fetch( String identifier ) {
            return null;
        }
    }

}

@@ -1241,48 +1241,12 @@
 th( 
-%22there is no way this path exists %5C%5C/%5B%5D%22
+null
  );%0A

fix path that caused directory creation