Are there any examples on how to test single Component or JComponent with AssertJ?
Getting started guide shows strange example to test entire application with main class, which is no granulated enough. I am expecting to test custom components first.
UPDATE
Suppose I have the following component:
package tests;
import javax.swing.*;
import java.awt.*;
public class JCustomPanel extends JPanel {
@Override
public void paint(Graphics g) {
super.paint(g);
g.setColor(Color.RED);
g.fillRect(0, 0, getWidth(), getHeight());
}
}
and I wish to check if it appears red. What to write?
package tests;
import org.assertj.swing.edt.FailOnThreadViolationRepaintManager;
import org.assertj.swing.fixture.JPanelFixture;
import org.assertj.swing.testing.AssertJSwingTestCaseTemplate;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
public class Test01 extends AssertJSwingTestCaseTemplate {
private JPanelFixture panel;
@BeforeClass
public static void setUpOnce() {
FailOnThreadViolationRepaintManager.install();
}
@Before
public void setUp() {
panel = new JPanelFixture(robot(), new JCustomPanel());
}
@Test
public void testColorIsRed() {
//what to write here?
}
}