use of com.puppycrawl.tools.checkstyle.gui.MainFrameModel.ParseMode in project checkstyle by checkstyle.
the class MainFrameModelTest method testOpenFileWithUnknownParseMode.
@Test
@PrepareForTest(ParseMode.class)
public void testOpenFileWithUnknownParseMode() throws CheckstyleException {
final ParseMode unknownParseMode = PowerMockito.mock(ParseMode.class);
Whitebox.setInternalState(unknownParseMode, "ordinal", 3);
PowerMockito.when(unknownParseMode.toString()).thenReturn("Unknown parse mode");
PowerMockito.mockStatic(ParseMode.class);
PowerMockito.when(ParseMode.values()).thenReturn(new ParseMode[] { ParseMode.PLAIN_JAVA, ParseMode.JAVA_WITH_COMMENTS, ParseMode.JAVA_WITH_JAVADOC_AND_COMMENTS, unknownParseMode });
try {
model.setParseMode(unknownParseMode);
model.openFile(testData);
fail("Expected IllegalArgumentException is not thrown.");
} catch (IllegalArgumentException ex) {
assertEquals("Unknown mode: Unknown parse mode", ex.getMessage());
}
}
use of com.puppycrawl.tools.checkstyle.gui.MainFrameModel.ParseMode in project checkstyle by checkstyle.
the class MainFrame method createButtonsPanel.
/**
* Create buttons panel.
* @return buttons panel.
*/
private JPanel createButtonsPanel() {
final JButton openFileButton = new JButton(new FileSelectionAction());
openFileButton.setMnemonic(KeyEvent.VK_S);
openFileButton.setText("Open File");
reloadAction.setEnabled(false);
final JButton reloadFileButton = new JButton(reloadAction);
reloadFileButton.setMnemonic(KeyEvent.VK_R);
reloadFileButton.setText("Reload File");
final JComboBox<ParseMode> modesCombobox = new JComboBox<>(ParseMode.values());
modesCombobox.setSelectedIndex(0);
modesCombobox.addActionListener(e -> {
model.setParseMode((ParseMode) modesCombobox.getSelectedItem());
reloadAction.actionPerformed(null);
});
final JLabel modesLabel = new JLabel("Modes:", SwingConstants.RIGHT);
final int leftIndentation = 10;
modesLabel.setBorder(BorderFactory.createEmptyBorder(0, leftIndentation, 0, 0));
final JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new GridLayout(1, 2));
buttonPanel.add(openFileButton);
buttonPanel.add(reloadFileButton);
final JPanel modesPanel = new JPanel();
modesPanel.add(modesLabel);
modesPanel.add(modesCombobox);
final JPanel mainPanel = new JPanel();
mainPanel.setLayout(new BorderLayout());
mainPanel.add(buttonPanel);
mainPanel.add(modesPanel, BorderLayout.LINE_END);
return mainPanel;
}
Aggregations