vendredi 2 décembre 2016

Testing an imageeffect using a bufferedimage

Ive made a class that applies a tiling effect to a bufferedimage and i have to make a JUnit test on the class but im unsure of what to test and how i can test it. I know i have to use assert and the likes but im not sure how. I was thinking it would be something with the image being divided in 4.

public class TilesAction extends AbstractSelectedAction  { 
        public static String ID = "edit.Tiles";

    SVGImageFigure image;

    public TilesAction(DrawingEditor editor) {
        super(editor);
    }

    @Override
    public void actionPerformed(ActionEvent ae) {
        final DrawingView view = getView();
        final LinkedList<Figure> figures = new LinkedList<Figure>(view.getSelectedFigures());
        final Figure figure = figures.getFirst();
        tiling(figure);
        fireUndoableEditHappened(new AbstractUndoableEdit() {
            @Override
            public String getPresentationName() {
                return labels.getTextProperty(ID);
            }

            @Override
            public void redo() throws CannotRedoException {
                super.redo();
            }

            @Override
            public void undo() throws CannotUndoException {
                super.undo();
            }
        });
    }        
    private void tiling(Figure figure) {
        image = (SVGImageFigure) figure;
        BufferedImage tilingImage = image.getBufferedImage();
         Graphics g = tilingImage.getGraphics();
         DefaultDrawingView ddv = new DefaultDrawingView();

    int width = tilingImage.getWidth() / 4;
    int height = tilingImage.getHeight() / 4;

    Image scaled = tilingImage.getScaledInstance(width, height, Image.SCALE_SMOOTH);

    // Tile the image to fill our area.
    for (int x = 0; x < tilingImage.getWidth(); x += width) {
        for (int y = 0; y < tilingImage.getHeight(); y += height) {
            g.drawImage(scaled, x, y, null);
        }
    }
    g.dispose();

            }



}

Aucun commentaire:

Enregistrer un commentaire