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

📄 panelcomponentsearchtest.java

📁 基于Junit的 功能和单元测试的的测试工具。只支持Swing.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
    for (int i = 0; i < swingClasses.length; i++) {
      jPanel.removeAll();
      Component component = createSwingInstance(swingClasses[i]);
      jPanel.add(component);
      TestUtils.assertUIComponentRefersTo(component, getAccessor(uiComponentType).getComponent());
    }
  }

  private void checkGetComponentWithCustomMatcher(Class uiComponentClass) throws Exception {
    Class[] swingClasses = UIComponentAnalyzer.getSwingClasses(uiComponentClass);
    String uiComponentType = UIComponentAnalyzer.getTypeName(uiComponentClass);
    for (int i = 0; i < swingClasses.length; i++) {
      jPanel.removeAll();
      Component component = createSwingInstance(swingClasses[i]);
      jPanel.add(component);
      ComponentMatcher matcher = new ComponentMatcher() {
        public boolean matches(Component component) {
          return component.isEnabled();
        }
      };
      TestUtils.assertUIComponentRefersTo(component, getAccessor(uiComponentType).getComponent(matcher));
    }
  }

  private Component createComponentWithText(Class componentClass, String componentName) throws Exception {
    Constructor componentConstructor = componentClass.getConstructor(new Class[]{String.class});
    return (Component)componentConstructor.newInstance(new Object[]{componentName});
  }

  private TypedComponentAccessor getAccessor(String typeName) {
    return (TypedComponentAccessor)componentAccessors.get(typeName);
  }

  private static Map createAccessors(final Panel panel) {
    HashMap map = new HashMap();
    map.put(Button.TYPE_NAME, new ComponentAccessorAdapter() {
      public UIComponent getComponent(ComponentMatcher matcher) throws Exception {
        return panel.getButton(matcher);
      }

      public UIComponent getComponent(String componentName) throws Exception {
        return panel.getButton(componentName);
      }

      public UIComponent getComponent() throws Exception {
        return panel.getButton();
      }
    });
    map.put(ToggleButton.TYPE_NAME, new ComponentAccessorAdapter() {
      public UIComponent getComponent(ComponentMatcher matcher) throws Exception {
        return panel.getToggleButton(matcher);
      }

      public UIComponent getComponent(String componentName) throws Exception {
        return panel.getToggleButton(componentName);
      }

      public UIComponent getComponent() throws Exception {
        return panel.getToggleButton();
      }
    });
    map.put(CheckBox.TYPE_NAME, new ComponentAccessorAdapter() {
      public UIComponent getComponent(ComponentMatcher matcher) throws Exception {
        return panel.getCheckBox(matcher);
      }

      public UIComponent getComponent(String componentName) throws Exception {
        return panel.getCheckBox(componentName);
      }

      public UIComponent getComponent() throws Exception {
        return panel.getCheckBox();
      }
    });
    map.put(TextBox.TYPE_NAME, new ComponentAccessorAdapter() {
      public UIComponent getComponent() throws Exception {
        return panel.getTextBox();
      }

      public UIComponent getComponent(ComponentMatcher matcher) throws Exception {
        return panel.getTextBox(matcher);
      }

      public UIComponent getComponent(String componentName) throws Exception {
        return panel.getTextBox(componentName);
      }
    });
    map.put(TabGroup.TYPE_NAME, new ComponentAccessorAdapter() {
      public UIComponent getComponent() throws Exception {
        return panel.getTabGroup();
      }

      public UIComponent getComponent(ComponentMatcher matcher) throws Exception {
        return panel.getTabGroup(matcher);
      }

      public UIComponent getComponent(String componentName) throws Exception {
        return panel.getTabGroup(componentName);
      }
    });
    map.put(ComboBox.TYPE_NAME, new ComponentAccessorAdapter() {
      public UIComponent getComponent() throws Exception {
        return panel.getComboBox();
      }

      public UIComponent getComponent(ComponentMatcher matcher) throws Exception {
        return panel.getComboBox(matcher);
      }

      public UIComponent getComponent(String componentName) throws Exception {
        return panel.getComboBox(componentName);
      }
    });
    map.put(org.uispec4j.Desktop.TYPE_NAME, new ComponentAccessorAdapter() {
      public UIComponent getComponent() throws Exception {
        return panel.getDesktop();
      }

      public UIComponent getComponent(ComponentMatcher matcher) throws Exception {
        return panel.getDesktop(matcher);
      }

      public UIComponent getComponent(String componentName) throws Exception {
        return panel.getDesktop(componentName);
      }
    });
    map.put(ProgressBar.TYPE_NAME, new ComponentAccessorAdapter() {
      public UIComponent getComponent() throws Exception {
        return panel.getProgressBar();
      }

      public UIComponent getComponent(ComponentMatcher matcher) throws Exception {
        return panel.getProgressBar(matcher);
      }

      public UIComponent getComponent(String componentName) throws Exception {
        return panel.getProgressBar(componentName);
      }
    });
    map.put(RadioButton.TYPE_NAME, new ComponentAccessorAdapter() {
      public UIComponent getComponent(ComponentMatcher matcher) throws Exception {
        return panel.getRadioButton(matcher);
      }

      public UIComponent getComponent(String componentName) throws Exception {
        return panel.getRadioButton(componentName);
      }

      public UIComponent getComponent() throws Exception {
        return panel.getRadioButton();
      }

    });
    map.put(Panel.TYPE_NAME, new ComponentAccessorAdapter() {

      public UIComponent getComponent(ComponentMatcher matcher) throws Exception {
        return panel.getPanel(matcher);
      }

      public UIComponent getComponent(String componentName) throws Exception {
        return panel.getPanel(componentName);
      }

      public UIComponent getComponent() throws Exception {
        return panel.getPanel();
      }
    });
    map.put(ListBox.TYPE_NAME, new ComponentAccessorAdapter() {
      public UIComponent getComponent(ComponentMatcher matcher) throws Exception {
        return panel.getListBox(matcher);
      }

      public UIComponent getComponent(String componentName) throws Exception {
        return panel.getListBox(componentName);
      }

      public UIComponent getComponent() throws Exception {
        return panel.getListBox();
      }
    });
    map.put(Table.TYPE_NAME, new ComponentAccessorAdapter() {
      public UIComponent getComponent(ComponentMatcher matcher) throws Exception {
        return panel.getTable(matcher);
      }

      public UIComponent getComponent(String componentName) throws Exception {
        return panel.getTable(componentName);
      }

      public UIComponent getComponent() throws Exception {
        return panel.getTable();
      }
    });
    map.put(Tree.TYPE_NAME, new ComponentAccessorAdapter() {
      public UIComponent getComponent(ComponentMatcher matcher) throws Exception {
        return panel.getTree(matcher);
      }

      public UIComponent getComponent(String componentName) throws Exception {
        return panel.getTree(componentName);
      }

      public UIComponent getComponent() throws Exception {
        return panel.getTree();
      }
    });
    map.put(Spinner.TYPE_NAME, new ComponentAccessorAdapter() {
      public UIComponent getComponent(ComponentMatcher matcher) throws Exception {
        return panel.getSpinner(matcher);
      }

      public UIComponent getComponent(String componentName) throws Exception {
        return panel.getSpinner(componentName);
      }

      public UIComponent getComponent() throws Exception {
        return panel.getSpinner();
      }
    });
    map.put(Slider.TYPE_NAME, new ComponentAccessorAdapter() {
      public UIComponent getComponent(ComponentMatcher matcher) throws Exception {
        return panel.getSlider(matcher);
      }

      public UIComponent getComponent(String componentName) throws Exception {
        return panel.getSlider(componentName);
      }

      public UIComponent getComponent() throws Exception {
        return panel.getSlider();
      }
    });
    map.put(PasswordField.TYPE_NAME, new ComponentAccessorAdapter() {
      public UIComponent getComponent(ComponentMatcher matcher) throws Exception {
        return panel.getPasswordField(matcher);
      }

      public UIComponent getComponent(String componentName) throws Exception {
        return panel.getPasswordField(componentName);
      }

      public UIComponent getComponent() throws Exception {
        return panel.getPasswordField();
      }
    });
    return map;
  }

  private interface TypedComponentAccessor {
    UIComponent getComponent(ComponentMatcher matcher) throws Exception;

    UIComponent getComponent(String componentName) throws Exception;

    UIComponent getComponent() throws Exception;
  }

  private abstract static class ComponentAccessorAdapter implements TypedComponentAccessor {
    public UIComponent getComponent(String componentName) throws Exception {
      throw new RuntimeException("No such method");
    }
  }

  private void addWithScrollPane(Component containedComponent, JPanel main) {
    JScrollPane scroll = new JScrollPane();
    scroll.getViewport().add(containedComponent);
    main.add(scroll);
  }
}

⌨️ 快捷键说明

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