コード例 #1
0
  public void test_getDisplayValue_noRenderer() throws Exception {
    comp = new JComboBox(new String[] {"1", "2", "3"});
    wrapper = new ComboBoxWrapper("toto", comp);

    wrapper.setXmlValue("2");
    assertEquals("2", wrapper.getXmlValue());
    assertEquals("2", wrapper.getDisplayValue());
  }
コード例 #2
0
  public void test_setXmlValue_NULL_in_model() throws Exception {
    comp = new JComboBox(new String[] {"null", "other"});
    wrapper = new ComboBoxWrapper("toto", comp);

    wrapper.setXmlValue("null");
    assertEquals("null", wrapper.getXmlValue());
    assertEquals(0, comp.getSelectedIndex());
  }
コード例 #3
0
  public void test_wrapp() throws Exception {
    comp.setSelectedItem(6);

    assertEquals("6", wrapper.getXmlValue());

    wrapper.setXmlValue("5");

    assertEquals(5, comp.getSelectedItem());
  }
コード例 #4
0
 public void test_setXmlValue_unknownValue() throws Exception {
   try {
     wrapper.setXmlValue("987sdflkj");
     fail("Valeur non présente dans le modèle");
   } catch (IllegalArgumentException ex) {; // erreur
   }
 }
コード例 #5
0
  public void test_getDisplayValue_noJLabelRendererThrowsAnException() throws Exception {
    comp = new JComboBox(new String[] {"1", "2", "3"});
    comp.setRenderer(
        new ListCellRenderer() {
          public Component getListCellRendererComponent(
              JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            return new JPanel();
          }
        });
    wrapper = new ComboBoxWrapper("toto", comp);

    wrapper.setXmlValue("2");
    assertEquals("2", wrapper.getXmlValue());

    try {
      wrapper.getDisplayValue();
      fail();
    } catch (Exception e) {
      assertEquals("Impossible de renvoyer la valeur affichée par le renderer.", e.getMessage());
    }
  }
コード例 #6
0
  public void test_getDisplayValue_aJLabelRenderer() throws Exception {
    comp = new JComboBox(new String[] {"1", "2", "3"});
    comp.setRenderer(
        new DefaultListCellRenderer() {
          @Override
          public Component getListCellRendererComponent(
              JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            if ("1".equals(value)) {
              setText("one");
            } else if ("2".equals(value)) {
              setText("two");
            } else if ("3".equals(value)) {
              setText("three");
            }
            return this;
          }
        });
    wrapper = new ComboBoxWrapper("toto", comp);

    wrapper.setXmlValue("2");
    assertEquals("2", wrapper.getXmlValue());
    assertEquals("two", wrapper.getDisplayValue());
  }
コード例 #7
0
 public void test_getDisplayValue_editableComboBox() throws Exception {
   comp.setEditable(true);
   wrapper.setXmlValue("unknownValue");
   assertEquals("unknownValue", wrapper.getXmlValue());
   assertEquals("unknownValue", wrapper.getDisplayValue());
 }
コード例 #8
0
 @Override
 protected void changeValueThroughWrapper() {
   wrapper.setXmlValue("6");
 }