001/* 002 * jDTAUS Core Utilities 003 * Copyright (C) 2005 Christian Schulte 004 * <cs@schulte.it> 005 * 006 * This library is free software; you can redistribute it and/or 007 * modify it under the terms of the GNU Lesser General Public 008 * License as published by the Free Software Foundation; either 009 * version 2.1 of the License, or any later version. 010 * 011 * This library is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 * Lesser General Public License for more details. 015 * 016 * You should have received a copy of the GNU Lesser General Public 017 * License along with this library; if not, write to the Free Software 018 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 019 * 020 */ 021package org.jdtaus.core.io.util.test; 022 023import java.io.ByteArrayOutputStream; 024import org.jdtaus.core.io.FileOperations; 025import org.jdtaus.core.io.it.FileOperationsTest; 026import org.jdtaus.core.io.util.MemoryFileOperations; 027 028/** 029 * Testcase for {@code MemoryFileOperations} implementations. 030 * 031 * @author <a href="mailto:cs@schulte.it">Christian Schulte</a> 032 * @version $JDTAUS: MemoryFileOperationsTest.java 8641 2012-09-27 06:45:17Z schulte $ 033 */ 034public class MemoryFileOperationsTest extends FileOperationsTest 035{ 036 //--FileOperationsTest------------------------------------------------------ 037 038 public FileOperations getFileOperations() 039 { 040 return new MemoryFileOperations(); 041 } 042 043 //------------------------------------------------------FileOperationsTest-- 044 //--TestCase---------------------------------------------------------------- 045 046 protected void runTest() throws Throwable 047 { 048 super.runTest(); 049 this.testStreaming(); 050 } 051 052 //----------------------------------------------------------------TestCase-- 053 //--MemoryFileOperationsTest------------------------------------------------ 054 055 /** 056 * Tests the {@link FileOperations#read(OutputStream)} and 057 * {@link FileOperations#write(InputStream)} methods. 058 * <p><ol> 059 * <li>Writes a testfile from an {@code InputStream} to the file, then reads 060 * the file contents into a {@code ByteArrayOutputStream} and checks 061 * that the read data matches the written data.</li> 062 * </ol></p> 063 */ 064 public void testStreaming() throws Exception 065 { 066 final MemoryFileOperations ops = new MemoryFileOperations(); 067 final ByteArrayOutputStream out = new ByteArrayOutputStream(); 068 069 ops.write( this.getTestFile() ); 070 this.assertValidTestFile( new String( ops.getData(), "UTF-8" ) ); 071 ops.read( out ); 072 out.close(); 073 this.assertValidTestFile( new String( out.toByteArray(), "UTF-8" ) ); 074 } 075 076 //------------------------------------------------MemoryFileOperationsTest-- 077}