mirror of
https://github.com/nasa/trick.git
synced 2025-01-31 08:25:41 +00:00
Finished testsuite for font testing
This commit is contained in:
parent
f9c81f25f4
commit
2579eaf87b
trick_source/java/src
main/java/trick/common/ui/components
test/java/trick
@ -292,7 +292,7 @@ public class FontChooser extends JDialog implements ActionListener, ListSelectio
|
||||
selectionPanel.add(sizePanel);
|
||||
selectionPanel.add(stylePanel);
|
||||
|
||||
selectionPanel.setMinimumSize(selectionPanel.getPreferredSize());
|
||||
// selectionPanel.setMinimumSize(selectionPanel.getPreferredSize());
|
||||
|
||||
return selectionPanel;
|
||||
}
|
||||
@ -308,12 +308,15 @@ public class FontChooser extends JDialog implements ActionListener, ListSelectio
|
||||
JPanel stylePanel = new JPanel();
|
||||
stylePanel.setLayout(new BoxLayout(stylePanel, BoxLayout.Y_AXIS));
|
||||
|
||||
JLabel styleLabel = new JLabel("Style");
|
||||
String name = "Style";
|
||||
JLabel styleLabel = new JLabel(name);
|
||||
|
||||
boldBox = new JCheckBox(BOLD_OPTION);
|
||||
boldBox.setName("BoldCheck");
|
||||
boldBox.addActionListener(this);
|
||||
|
||||
italicBox = new JCheckBox(ITALIC_OPTION);
|
||||
italicBox.setName("ItalicCheck");
|
||||
italicBox.addActionListener(this);
|
||||
|
||||
stylePanel.add(styleLabel);
|
||||
@ -322,6 +325,7 @@ public class FontChooser extends JDialog implements ActionListener, ListSelectio
|
||||
stylePanel.add(italicBox);
|
||||
stylePanel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
|
||||
stylePanel.setPreferredSize(new Dimension(stylePanel.getPreferredSize().width, height));
|
||||
stylePanel.setName(name);
|
||||
|
||||
return stylePanel;
|
||||
}
|
||||
@ -333,7 +337,9 @@ public class FontChooser extends JDialog implements ActionListener, ListSelectio
|
||||
*/
|
||||
private JPanel buildSamplePanel() {
|
||||
JPanel samplePanel = new JPanel(new BorderLayout());
|
||||
samplePanel.setBorder(new TitledBorder(new EtchedBorder(), "Preview"));
|
||||
String title = "Preview";
|
||||
samplePanel.setName(title);
|
||||
samplePanel.setBorder(new TitledBorder(new EtchedBorder(), title));
|
||||
|
||||
sampleLabel = new JLabel("", JLabel.CENTER);
|
||||
sampleLabel.setBackground(Color.white);
|
||||
@ -361,6 +367,7 @@ public class FontChooser extends JDialog implements ActionListener, ListSelectio
|
||||
|
||||
buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
|
||||
buttonPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
|
||||
buttonPanel.setName("Buttons");
|
||||
|
||||
buttonPanel.add(Box.createHorizontalStrut(30));
|
||||
buttonPanel.add(okButton);
|
||||
|
@ -0,0 +1,73 @@
|
||||
package trick.common.fixtures;
|
||||
|
||||
import java.awt.Font;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
|
||||
import org.assertj.swing.core.Robot;
|
||||
import org.assertj.swing.fixture.DialogFixture;
|
||||
import org.assertj.swing.fixture.JCheckBoxFixture;
|
||||
import org.assertj.swing.fixture.JLabelFixture;
|
||||
import org.assertj.swing.fixture.JListFixture;
|
||||
import org.assertj.swing.fixture.JPanelFixture;
|
||||
|
||||
import trick.common.fixtures.FontChooserFixtureExtension;
|
||||
import trick.common.ui.components.FontChooser;
|
||||
|
||||
public class FontChooserFixture extends DialogFixture {
|
||||
private JListFixture fonts, sizes;
|
||||
private JCheckBoxFixture bold, italic;
|
||||
private JLabelFixture preview;
|
||||
|
||||
public static final String[] FONT_LIST = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
|
||||
|
||||
public FontChooserFixture(Robot robot, FontChooser target) {
|
||||
super(robot, target);
|
||||
|
||||
JPanelFixture fontPanel = panel("Font"),
|
||||
sizePanel = panel("Size"),
|
||||
stylPanel = panel("Style"),
|
||||
prevPanel = panel("Preview"),
|
||||
bttnPanel = panel("Buttons");
|
||||
|
||||
fonts = fontPanel.list();
|
||||
sizes = sizePanel.list();
|
||||
bold = stylPanel.checkBox("BoldCheck");
|
||||
italic = stylPanel.checkBox("ItalicCheck");
|
||||
preview = prevPanel.label();
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void selectFont(int index) { fonts.clickItem(index); }
|
||||
public void selectFont(String name) { fonts.clickItem(name); }
|
||||
|
||||
public void selectSize(int size) {
|
||||
if (size < 4) size = 4;
|
||||
else if (size > 24) size = 24;
|
||||
|
||||
sizes.clickItem("" + size);
|
||||
}
|
||||
|
||||
public void setBold(boolean toggled) {
|
||||
if (toggled) bold.check();
|
||||
else bold.uncheck();
|
||||
}
|
||||
|
||||
public void setItalic(boolean toggled) {
|
||||
if (toggled) italic.check();
|
||||
else italic.uncheck();
|
||||
}
|
||||
|
||||
public String getPreviewText() {
|
||||
return preview.text();
|
||||
}
|
||||
|
||||
public Font getPreviewFont() {
|
||||
return preview.font().target();
|
||||
}
|
||||
|
||||
public static FontChooserFixtureExtension getExtension() {
|
||||
return new FontChooserFixtureExtension();
|
||||
}
|
||||
|
||||
}
|
17
trick_source/java/src/test/java/trick/common/fixtures/FontChooserFixtureExtension.java
Normal file
17
trick_source/java/src/test/java/trick/common/fixtures/FontChooserFixtureExtension.java
Normal file
@ -0,0 +1,17 @@
|
||||
package trick.common.fixtures;
|
||||
|
||||
import java.awt.Container;
|
||||
|
||||
import org.assertj.swing.core.Robot;
|
||||
import org.assertj.swing.fixture.ComponentFixtureExtension;
|
||||
|
||||
import trick.common.fixtures.FontChooserFixture;
|
||||
import trick.common.ui.components.FontChooser;
|
||||
|
||||
public class FontChooserFixtureExtension extends ComponentFixtureExtension {
|
||||
@Override
|
||||
public FontChooserFixture createFixture(Robot robot, Container root) {
|
||||
FontChooser fontDialog = robot.finder().findByType(root, FontChooser.class, true);
|
||||
return new FontChooserFixture(robot, fontDialog);
|
||||
}
|
||||
}
|
@ -72,6 +72,7 @@ public class StubbedSimControlApplication extends SimControlApplication {
|
||||
@Override
|
||||
public void showStatusFont() {
|
||||
ActionRecord.push(ActionID.SET_FONT);
|
||||
super.showStatusFont();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,9 +1,13 @@
|
||||
package trick.simcontrol;
|
||||
|
||||
import trick.common.fixtures.FontChooserFixture;
|
||||
import trick.common.ui.components.FontChooser;
|
||||
import trick.simcontrol.SimControlApplication;
|
||||
import trick.simcontrol.StubbedSimControlApplication;
|
||||
|
||||
import java.awt.Font;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Component;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.datatransfer.Clipboard;
|
||||
@ -14,6 +18,8 @@ import java.beans.Transient;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JMenu;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.JToggleButton;
|
||||
import javax.swing.text.JTextComponent;
|
||||
@ -21,8 +27,11 @@ import javax.swing.text.JTextComponent;
|
||||
import org.assertj.swing.core.GenericTypeMatcher;
|
||||
import org.assertj.swing.core.KeyPressInfo;
|
||||
import org.assertj.swing.exception.ComponentLookupException;
|
||||
import org.assertj.swing.fixture.AbstractComponentFixture;
|
||||
import org.assertj.swing.fixture.ComponentContainerFixture;
|
||||
import org.assertj.swing.fixture.DialogFixture;
|
||||
import org.assertj.swing.fixture.JButtonFixture;
|
||||
import org.assertj.swing.fixture.JMenuItemFixture;
|
||||
import org.assertj.swing.fixture.JPanelFixture;
|
||||
import org.assertj.swing.fixture.JTextComponentFixture;
|
||||
import org.assertj.swing.fixture.JToggleButtonFixture;
|
||||
@ -176,15 +185,15 @@ public class StubbedSimControlTests extends AssertJSwingJUnitTestCase {
|
||||
public void testFindPanelButtons() {
|
||||
// ARRANGE
|
||||
final String message = "I must not fear.\n" + //
|
||||
"Fear is the mind-killer.\n" + //
|
||||
"Fear is the little-death that brings total obliteration.\n" + //
|
||||
"I will face my fear.\n" + //
|
||||
"I will permit it to pass over me and through me.\n" + //
|
||||
"And when it has gone past, I will turn the inner eye to see its path.\n" + //
|
||||
"Where the fear has gone there will be nothing. Only I will remain";
|
||||
"Fear is the mind-killer.\n" + //
|
||||
"Fear is the little-death that brings total obliteration.\n" + //
|
||||
"I will face my fear.\n" + //
|
||||
"I will permit it to pass over me and through me.\n" + //
|
||||
"And when it has gone past, I will turn the inner eye to see its path.\n" + //
|
||||
"Where the fear has gone there will be nothing. Only I will remain";
|
||||
final String outStencil = "%s@%d";
|
||||
final String[] expOutputNext = {"null@304", "fear@11",
|
||||
"Fear@17" , "Fear@42",
|
||||
"Fear@17" , "Fear@42",
|
||||
"fear@114", "fear@249"},
|
||||
expOutputPrev = {"fear@114", "Fear@42",
|
||||
"Fear@17" , "fear@11"};
|
||||
@ -194,7 +203,7 @@ public class StubbedSimControlTests extends AssertJSwingJUnitTestCase {
|
||||
JXEditorPane editorPane = (JXEditorPane) editorFixture.target();
|
||||
JButtonFixture findNextButton = getButtonByText(findPanel, "Find Next"),
|
||||
findPrevButton = getButtonByText(findPanel, "Find Previous");
|
||||
|
||||
|
||||
assumeThat(findNextButton).isNotNull();
|
||||
assumeThat(findPrevButton).isNotNull();
|
||||
|
||||
@ -233,7 +242,52 @@ public class StubbedSimControlTests extends AssertJSwingJUnitTestCase {
|
||||
|
||||
for(int i = 0; i < 4; i++)
|
||||
assertThat(queryResults[i + 6]).isEqualTo(expOutputPrev[i]);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------
|
||||
// JMenuBar Tests
|
||||
//--------------------
|
||||
|
||||
@Test
|
||||
public void testFontChange() {
|
||||
// ARRANGE
|
||||
FontChooserFixture fontDialogFixt;
|
||||
JButtonFixture okButton;
|
||||
|
||||
JMenuItemFixture fontMenu = getJMenuItemByName(mainFrame, "showStatusFontMenuItem");
|
||||
|
||||
final int fontSize = 15;
|
||||
final String fontName = "Droid Sans",
|
||||
expPreviewText = fontName + ":3:" + fontSize;
|
||||
final Font expFont = new Font(fontName, 3, fontSize);
|
||||
|
||||
String actualPreviewText;
|
||||
Font actualFont, actualPreviewFont;
|
||||
|
||||
fontMenu.click();
|
||||
fontDialogFixt = getFontChooserFixture();
|
||||
okButton = getButtonByText(fontDialogFixt, "Ok");
|
||||
|
||||
assumeThat(fontDialogFixt).isNotNull();
|
||||
|
||||
// ACT
|
||||
fontDialogFixt.selectFont(fontName);
|
||||
fontDialogFixt.selectSize(fontSize);
|
||||
fontDialogFixt.setBold(true);
|
||||
fontDialogFixt.setItalic(true);
|
||||
|
||||
actualPreviewText = fontDialogFixt.getPreviewText();
|
||||
actualPreviewFont = fontDialogFixt.getPreviewFont();
|
||||
|
||||
okButton.click();
|
||||
|
||||
actualFont = editorFixture.font().target();
|
||||
|
||||
// ASSERT
|
||||
assertThat(actualPreviewText).isEqualTo(expPreviewText);
|
||||
assertThat(actualPreviewFont).isEqualTo(expFont);
|
||||
assertThat(actualFont).isEqualTo(expFont);
|
||||
}
|
||||
|
||||
//--------------------
|
||||
// Helper Methods
|
||||
@ -243,20 +297,9 @@ public class StubbedSimControlTests extends AssertJSwingJUnitTestCase {
|
||||
try {Thread.sleep(ms);} catch(Exception ignored) {}
|
||||
}
|
||||
|
||||
private JTextComponentFixture setStatusMessage(String text) {
|
||||
JTextComponentFixture editorFixture = mainFrame.textBox(
|
||||
new GenericTypeMatcher<JXEditorPane>(JXEditorPane.class) {
|
||||
@Override
|
||||
protected boolean isMatching(JXEditorPane pane) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
private void setStatusMessage(String text) {
|
||||
editorFixture.deleteText()
|
||||
.setText(text);
|
||||
|
||||
return editorFixture;
|
||||
}
|
||||
|
||||
private void setFindText(String text) {
|
||||
@ -355,6 +398,19 @@ public class StubbedSimControlTests extends AssertJSwingJUnitTestCase {
|
||||
assertThat(logSize).isEqualTo(initialLogSize + 1);
|
||||
}
|
||||
|
||||
protected FontChooserFixture getFontChooserFixture() {
|
||||
try {
|
||||
AbstractComponentFixture abst = mainFrame.with(FontChooserFixture.getExtension());
|
||||
|
||||
if (abst instanceof FontChooserFixture)
|
||||
return (FontChooserFixture) abst;
|
||||
else
|
||||
return null;
|
||||
} catch(Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected FrameFixture getFrameByTitle(String title) {
|
||||
FrameFixture frame = findFrame(new GenericTypeMatcher<Frame>(Frame.class) {
|
||||
protected boolean isMatching(Frame frame) {
|
||||
@ -365,6 +421,42 @@ public class StubbedSimControlTests extends AssertJSwingJUnitTestCase {
|
||||
return frame;
|
||||
}
|
||||
|
||||
protected JMenuItemFixture getJMenuByName(ComponentContainerFixture container, String name) {
|
||||
JMenuItemFixture menu;
|
||||
|
||||
try {
|
||||
menu = container.menuItem(new GenericTypeMatcher<JMenu>(JMenu.class) {
|
||||
@Override
|
||||
protected boolean isMatching(JMenu jmenu) {
|
||||
return name.equals(jmenu.getName());
|
||||
}
|
||||
});
|
||||
} catch (ComponentLookupException e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return menu;
|
||||
|
||||
}
|
||||
|
||||
protected JMenuItemFixture getJMenuItemByName(ComponentContainerFixture container, String name) {
|
||||
JMenuItemFixture menu;
|
||||
|
||||
try {
|
||||
menu = container.menuItem(new GenericTypeMatcher<JMenuItem>(JMenuItem.class) {
|
||||
@Override
|
||||
protected boolean isMatching(JMenuItem jmenu) {
|
||||
return name.equals(jmenu.getName());
|
||||
}
|
||||
});
|
||||
} catch (ComponentLookupException e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return menu;
|
||||
|
||||
}
|
||||
|
||||
protected JButtonFixture getButtonByText(ComponentContainerFixture container, String text) {
|
||||
JButtonFixture button;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user