⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uispeclftest.java

📁 基于Junit的 功能和单元测试的的测试工具。只支持Swing.
💻 JAVA
字号:
package org.uispec4j.interception.ui;

import org.uispec4j.utils.UnitTestCase;

import javax.swing.*;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.List;

public class UISpecLFTest extends UnitTestCase {

  private List exceptions = Arrays.asList(new String[]{"TabbedPaneUI", "ViewportUI"});

  // This test only works when run alone
  public void disabled_testAllComponentUIClassesAreOverriden() throws Exception {
    UISpecLF.init();
    UIDefaults defaults = UIManager.getDefaults();
    for (Enumeration dfkeys = defaults.keys(); dfkeys.hasMoreElements();) {
      String key = dfkeys.nextElement().toString();
      if (key.endsWith("UI")) {
        Object value = defaults.get(key);
        if ((value != null)
            && (value.toString().indexOf("UISpec") < 0)
            && (!exceptions.contains(key))) {
          fail(key + " is not overriden (value: " + value + ")");
        }
      }
    }
  }

  public void testSwingComponentsUseUISpecUIs() throws Exception {
    checkUI(new JButton(), UISpecButtonUI.class);
    checkUI(new JCheckBoxMenuItem(), UISpecCheckBoxMenuItemUI.class);
    checkUI(new JCheckBox(), UISpecCheckBoxUI.class);
    checkUI(new JColorChooser(), UISpecColorChooserUI.class);
    checkUI(new JComboBox(), UISpecComboBoxUI.class);
    checkUI(new JDesktopPane(), UISpecDesktopPaneUI.class);
    checkUI(new JEditorPane(), UISpecEditorPaneUI.class);
    checkUI(new JFileChooser(), UISpecFileChooserUI.class);
    checkUI(new JFormattedTextField(), UISpecFormattedTextFieldUI.class);
    checkUI(new JInternalFrame(), UISpecInternalFrameUI.class);
    checkUI(new JLabel(), UISpecLabelUI.class);
    checkUI(new JList(), UISpecListUI.class);
    checkUI(new JMenuBar(), UISpecMenuBarUI.class);
    checkUI(new JMenuItem(), UISpecMenuItemUI.class);
    checkUI(new JMenu(), UISpecMenuUI.class);
    checkUI(new JOptionPane(), UISpecOptionPaneUI.class);
    checkUI(new JPanel(), UISpecPanelUI.class);
    checkUI(new JPasswordField(), UISpecPasswordFieldUI.class);
    checkUI(new JPopupMenu(), UISpecPopupMenuUI.class);
    checkUI(new JProgressBar(), UISpecProgressBarUI.class);
    checkUI(new JRadioButtonMenuItem(), UISpecRadioButtonMenuItemUI.class);
    checkUI(new JRadioButton(), UISpecRadioButtonUI.class);
    checkUI(new JRootPane(), UISpecRootPaneUI.class);
    checkUI(new JScrollBar(), UISpecScrollBarUI.class);
    checkUI(new JScrollPane(), UISpecScrollPaneUI.class);
    checkUI(new JSeparator(), UISpecSeparatorUI.class);
    checkUI(new JSlider(), UISpecSliderUI.class);
    checkUI(new JSpinner(), UISpecSpinnerUI.class);
    checkUI(new JSplitPane(), UISpecSplitPaneUI.class);
    checkUI(new JTable(), UISpecTableUI.class);
    checkUI(new JTextArea(), UISpecTextAreaUI.class);
    checkUI(new JTextField(), UISpecTextFieldUI.class);
    checkUI(new JTextPane(), UISpecTextPaneUI.class);
    checkUI(new JToggleButton(), UISpecToggleButtonUI.class);
    checkUI(new JToolBar(), UISpecToolBarUI.class);
    checkUI(new JToolTip(), UISpecToolTipUI.class);
    checkUI(new JTree(), UISpecTreeUI.class);
  }

  private void checkUI(JComponent component, Class expectedUIClass) throws Exception {
    Method method = component.getClass().getMethod("getUI", new Class[0]);
    Object result = method.invoke(component, new Object[0]);
    assertTrue(expectedUIClass.isInstance(result));
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -