jeudi 3 décembre 2015

JUnit test for Constructor

I need to write unit tests for this constructor, I have written one unit test for the case when BufferedImage image is null:

@Test(expected = NullPointerException.class)
public void testConstructorNull(){        
    bfImage = null;
    ColorImage cImage = null;
    assertNotNull(cImage = new ColorImage(bfImage));
}

, but I am not sure how to write a test when everything works

public ColorImage(BufferedImage image)
{
    super(image.getWidth(), image.getHeight(), TYPE_INT_RGB);
    int width = image.getWidth();
    int height = image.getHeight();
    for (int y=0; y<height; y++)
        for (int x=0; x<width; x++)
            setRGB(x, y, image.getRGB(x,y));
}

Please help.

Aucun commentaire:

Enregistrer un commentaire