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.IOException;
024import org.jdtaus.core.io.StructuredFile;
025import org.jdtaus.core.io.it.StructuredFileTest;
026import org.jdtaus.core.io.util.CoalescingFileOperations;
027import org.jdtaus.core.io.util.MemoryFileOperations;
028import org.jdtaus.core.io.util.StructuredFileOperations;
029
030/**
031 * Testcase for {@code StructuredFileOperations} implementations.
032 *
033 * @author <a href="mailto:cs@schulte.it">Christian Schulte</a>
034 * @version $JDTAUS: StructuredFileOperationsCoalescingTest.java 8641 2012-09-27 06:45:17Z schulte $
035 */
036public class StructuredFileOperationsCoalescingTest extends StructuredFileTest
037{
038    //--StructuredFileTest------------------------------------------------------
039
040    /** {@code FileOperations} backing the {@code StructuredFile}. */
041    private final MemoryFileOperations memOps = new MemoryFileOperations();
042
043    /** {@code StructuredFile} implementation being tested. */
044    private StructuredFileOperations structuredFile;
045
046    protected byte[] getStructuredData()
047    {
048        try
049        {
050            this.structuredFile.flush();
051            return this.memOps.getData();
052
053        }
054        catch ( IOException e )
055        {
056            throw new AssertionError( e );
057        }
058    }
059
060    protected StructuredFile getStructuredFile()
061    {
062        try
063        {
064            if ( this.structuredFile == null )
065            {
066                this.structuredFile = new StructuredFileOperations(
067                    StructuredFileTest.BLOCK_SIZE,
068                    new CoalescingFileOperations( this.memOps ) );
069
070            }
071
072            return this.structuredFile;
073        }
074        catch ( IOException e )
075        {
076            throw new AssertionError( e );
077        }
078    }
079
080    //------------------------------------------------------StructuredFileTest--
081}