package com.twelvemonkeys.imageio.stream;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import javax.imageio.ImageIO;
import javax.imageio.spi.IIORegistry;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;

import static org.junit.Assert.*;

/**
 * Base64DataURLImageInputStreamTest
 *
 * @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
 * @author last modified by $Author: haraldk$
 * @version $Id: Base64DataURLImageInputStreamTest.java,v 1.0 04.09.13 13:47 haraldk Exp$
 */
public class Base64DataURLImageInputStreamTest {
    static final String DATA = "data:image/png;base64,[encoded data, 7548 characters]";
    static final Base64DataURLImageInputStreamSpi provider = new Base64DataURLImageInputStreamSpi();

    @Before
    public void init() {
        IIORegistry.getDefaultInstance().registerServiceProvider(provider);
    }

    @After
    public void destroy() {
        IIORegistry.getDefaultInstance().deregisterServiceProvider(provider);
    }

    @Test
    public void testRead() throws IOException, InvocationTargetException, InterruptedException {
        BufferedImage image = ImageIO.read(ImageIO.createImageInputStream(DATA));

        assertNotNull(image);
        assertEquals(56, image.getWidth());
        assertEquals(34, image.getHeight());
    }
}
