Search in sources :

Example 1 with ParseMode

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());
    }
}
Also used : ParseMode(com.puppycrawl.tools.checkstyle.gui.MainFrameModel.ParseMode) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with ParseMode

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;
}
Also used : JPanel(javax.swing.JPanel) GridLayout(java.awt.GridLayout) JComboBox(javax.swing.JComboBox) BorderLayout(java.awt.BorderLayout) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) ParseMode(com.puppycrawl.tools.checkstyle.gui.MainFrameModel.ParseMode)

Aggregations

ParseMode (com.puppycrawl.tools.checkstyle.gui.MainFrameModel.ParseMode)2 BorderLayout (java.awt.BorderLayout)1 GridLayout (java.awt.GridLayout)1 JButton (javax.swing.JButton)1 JComboBox (javax.swing.JComboBox)1 JLabel (javax.swing.JLabel)1 JPanel (javax.swing.JPanel)1 Test (org.junit.Test)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1