package io.github.jonestimd.finance.stockquote;

import java.awt.image.BufferedImage;

import javax.swing.ImageIcon;

import com.google.common.collect.ImmutableMap;
import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
import org.junit.Test;
import sun.awt.image.ToolkitImage;

import static org.assertj.core.api.Assertions.*;

public class IconLoaderTest extends HttpServerTest {
    @Test
    public void returns16x16ImageFromIcoFile() throws Exception {
        Config config = ConfigFactory.parseMap(ImmutableMap.of("iconUrl", getUrl("multi-icon.ico")));

        ImageIcon icon = new IconLoader(config).getIcon();

        assertThat(icon.getIconWidth()).isEqualTo(16);
        BufferedImage image = (BufferedImage) icon.getImage();
        assertThat(image.getRGB(0, 0)).isEqualTo(0xff0000ff);
    }

    @Test
    public void returnsScaled16x16ImageFromIcoFile() throws Exception {
        Config config = ConfigFactory.parseMap(ImmutableMap.of("iconUrl", getUrl("icon-32x32.ico")));

        ImageIcon icon = new IconLoader(config).getIcon();

        assertThat(icon.getIconWidth()).isEqualTo(16);
        ToolkitImage image = (ToolkitImage) icon.getImage();
        assertThat(image.getBufferedImage().getRGB(0, 0)).isEqualTo(0xffffff00);
    }

    @Test
    public void returnsDefaultIconForMissingIcoFile() throws Exception {
        Config config = ConfigFactory.parseMap(ImmutableMap.of("iconUrl", getUrl("icon.ico")));

        ImageIcon icon = new IconLoader(config).getIcon();

        assertThat(icon).isSameAs(IconLoader.DEFAULT_ICON);
    }

    @Test
    public void returns16x16ImageFromPngFile() throws Exception {
        Config config = ConfigFactory.parseMap(ImmutableMap.of("iconUrl", getUrl("icon-16x16.png")));

        ImageIcon icon = new IconLoader(config).getIcon();

        assertThat(icon.getIconWidth()).isEqualTo(16);
        BufferedImage image = (BufferedImage) icon.getImage();
        assertThat(image.getRGB(0, 0)).isEqualTo(0xffff00ff);
    }

    @Test
    public void returnsScaled16x16ImageFromPngFile() throws Exception {
        Config config = ConfigFactory.parseMap(ImmutableMap.of("iconUrl", getUrl("icon-32x32.png")));

        ImageIcon icon = new IconLoader(config).getIcon();

        assertThat(icon.getIconWidth()).isEqualTo(16);
        ToolkitImage image = (ToolkitImage) icon.getImage();
        assertThat(image.getBufferedImage().getRGB(0, 0)).isEqualTo(0xffffff00);
    }
}
@@ -38,24 +38,50 @@
 tockquote;%0A%0A
+import java.awt.Graphics;%0A
 import java.
@@ -101,24 +101,24 @@
 feredImage;%0A
-
 %0Aimport java
@@ -287,43 +287,8 @@
 est;
-%0Aimport sun.awt.image.ToolkitImage;
 %0A%0Aim
@@ -388,16 +388,323 @@
 rTest %7B%0A
+    private BufferedImage getImage(ImageIcon icon) %7B%0A        BufferedImage image = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);%0A        Graphics g = image.createGraphics();%0A        icon.paintIcon(null, g, 0,0);%0A        g.dispose();%0A        return image;%0A    %7D%0A%0A
     @Tes
@@ -1023,38 +1023,21 @@
 e = 
-(Buffered
+get
 Image
-) 
+(
 icon
-.getImage(
 );%0A 
@@ -1404,39 +1404,40 @@
 To(16);%0A        
-Toolkit
+Buffered
 Image image = (T
@@ -1438,37 +1438,21 @@
 e = 
-(Toolki
+ge
 tImage
-) 
+(
 icon
-.getImage(
 );%0A 
@@ -1475,35 +1475,16 @@
 t(image.
-getBufferedImage().
 getRGB(0
@@ -2154,38 +2154,21 @@
 e = 
-(Buffered
+get
 Image
-) 
+(
 icon
-.getImage(
 );%0A 
@@ -2543,23 +2543,24 @@
         
-Toolkit
+Buffered
 Image im
@@ -2569,37 +2569,21 @@
 e = 
-(Toolki
+ge
 tImage
-) 
+(
 icon
-.getImage(
 );%0A 
@@ -2610,27 +2610,8 @@
 age.
-getBufferedImage().
 getR

Replace usage of ToolkitImage