blob: a4a3d30110a8541d86c341b94e2aa996d36e3db5 [file] [log] [blame]
/***********************************************************************************************************************
* Copyright (c) 2008 empolis GmbH and brox IT Solutions GmbH. All rights reserved. This program and the accompanying
* materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*
* Contributors: Ivan Churkin (brox IT Solutions GmbH) - initial creator
**********************************************************************************************************************/
package org.apache.commons.io.test;
import java.io.File;
import java.io.InputStream;
import java.net.URL;
import java.util.List;
import junit.framework.TestCase;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
/**
* Simple test which indicates that commons-io API is accessible.
*/
public class IOTest extends TestCase {
/**
* A test file name.
*/
private static final String FILE_NAME = "io-test.txt";
/**
* A test file content.
*/
private static final String FILE_CONTENT = "io-test content";
/**
* A test API access for IOUtils class.
*
* @throws Exception
* if any error has occured
*/
public void testIOUtils() throws Exception {
final InputStream in = IOTest.class.getResourceAsStream(FILE_NAME);
assertNotNull("File " + FILE_NAME + " not found.", in);
try {
final String result = IOUtils.toString(in);
assertNotNull("Test file content is null.", result);
assertEquals("Incorrect test file content.", FILE_CONTENT, result);
} finally {
IOUtils.closeQuietly(in);
}
}
/**
* A test API access for FileUtils class.
*
* @throws Exception
* if any error has occured
*/
@SuppressWarnings("unchecked")
public void testFileUtils() throws Exception {
final URL url = IOTest.class.getResource(FILE_NAME);
assertNotNull("File " + FILE_NAME + " not found.", url);
final URL nativeUrl = org.eclipse.core.runtime.FileLocator.resolve(url);
final File file = new File(nativeUrl.getFile());
final List list = FileUtils.readLines(file);
assertNotNull(list);
assertEquals(1, list.size());
}
}