Package io.apigee.trireme.util.test

Source Code of io.apigee.trireme.util.test.ConverterTest

package io.apigee.trireme.util.test;

import io.apigee.trireme.util.CharsetConverter;
import org.junit.Test;

import java.io.IOException;
import java.nio.ByteBuffer;

import static org.junit.Assert.*;

public class ConverterTest
{
    @Test
    public void testBasic()
        throws IOException
    {
        final String from = "Hello, World!";
        ByteBuffer in = ByteBuffer.wrap(from.getBytes("utf8"));
        CharsetConverter c = new CharsetConverter("utf8", "ascii");
        ByteBuffer out = c.convert(in, true);
        String result = toString(out, "ascii");
        assertEquals(from, result);
    }

    private String toString(ByteBuffer bb, String cs)
        throws IOException
    {
        assertTrue(bb.hasArray());
        return new String(bb.array(), bb.arrayOffset() + bb.position(), bb.remaining(), cs);
    }
}
TOP

Related Classes of io.apigee.trireme.util.test.ConverterTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.