edu.umn.msi.tropix.common.io.StreamInputContextImplTest.java Source code

Java tutorial

Introduction

Here is the source code for edu.umn.msi.tropix.common.io.StreamInputContextImplTest.java

Source

/*******************************************************************************
 * Copyright 2009 Regents of the University of Minnesota. All rights
 * reserved.
 * Copyright 2009 Mayo Foundation for Medical Education and Research.
 * All rights reserved.
 *
 * This program is 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
 *
 * 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 INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS
 * OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A
 * PARTICULAR PURPOSE.  See the License for the specific language
 * governing permissions and limitations under the License.
 *
 * Contributors:
 * Minnesota Supercomputing Institute - initial API and implementation
 ******************************************************************************/

package edu.umn.msi.tropix.common.io;

import java.io.File;
import java.io.IOException;
import java.io.OutputStream;

import org.testng.annotations.Test;

public class StreamInputContextImplTest {

    static class TestStreamInputContextImpl extends StreamInputContextImpl {
        private byte[] bytes;

        public void get(final OutputStream outputStream) {
            try {
                outputStream.write(bytes);
            } catch (final IOException e) {
                throw new IORuntimeException(e);
            }
        }

    }

    @Test(groups = "unit")
    public void getOutputContext() throws IOException {
        final File file = File.createTempFile("tpxtst", "");
        try {
            final TestStreamInputContextImpl context = new TestStreamInputContextImpl();
            context.bytes = "Moo Cow".getBytes();
            context.get(OutputContexts.forFile(file));
            assert org.apache.commons.io.FileUtils.readFileToString(file).equals("Moo Cow");
        } finally {
            file.delete();
        }
    }

    @Test(groups = "unit")
    public void getFile() throws IOException {
        final File file = File.createTempFile("tpxtst", "");
        try {
            final TestStreamInputContextImpl context = new TestStreamInputContextImpl();
            context.bytes = "Moo Cow".getBytes();
            context.get(file);
            assert org.apache.commons.io.FileUtils.readFileToString(file).equals("Moo Cow");
        } finally {
            file.delete();
        }
    }

}