package org.team619.crossout.program.calculator;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.runners.MockitoJUnitRunner;
import org.team619.crossout.program.data.Calculations;
import org.team619.crossout.program.data.ProgramContext;
import org.team619.crossout.program.supplier.GeneratedSupplier;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

@RunWith(MockitoJUnitRunner.class)
public class GeneratedSupplierTest {

    @InjectMocks
    GeneratedSupplier generatedSupplier;

    public static void generateImage() throws IOException {
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        GeneratedSupplierTest test = new GeneratedSupplierTest();
        GeneratedSupplier generatedSupplier = new GeneratedSupplier();
        generatedSupplier.config(ProgramContext.builder()
                .calculations(Calculations.builder()
                        .screenHeight((int) screenSize.getHeight())
                        .screenWidth((int) screenSize.getWidth())
                        .build())
                .build());
        test.generatedSupplier = generatedSupplier;
        test.testGenerateImage();
    }

    @Before
    public void setUp() {
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        generatedSupplier.config(ProgramContext.builder()
                .calculations(Calculations.builder()
                        .screenHeight((int) screenSize.getHeight())
                        .screenWidth((int) screenSize.getWidth())
                        .build())
                .build());
        System.out.println("GeneratedSupplierTest.setUp: " + new File(".").getAbsolutePath());
    }

    @Test
    public void testGenerateImage() throws IOException {
        BufferedImage image = generatedSupplier.takeScreenShot();

        File parent = new File("images");
        parent.mkdirs();
        File file = new File(parent, "generated.png");
        ImageIO.write(image, "PNG", file);
    }

}
