有没有关于如何使用 AssertJ 测试单个组件或 JComponent 的示例?
入门指南显示了使用主类测试整个应用程序的奇怪示例,这还不够细化。我期待首先测试自定义组件。
更新
假设我有以下组件:
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());
}
}
我想检查它是否显示为红色。写什么?
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?
}
}