Package org.izi

Examples of org.izi.ModelForTests


   @Test
   public void shouldNotPropagateValuesWhenUnbound_controlToModelCase()
   {
      // given
      JTextField textField = new JTextField();
      ModelForTests model = new ModelForTests();
      BindingRegistration to = bind().textOf(textField).to(model, ModelForTests.NAME);
      textField.setText("newData");
      to.unbind();
      // when
      textField.setText("someOtherText");
      // then
      assertEquals("newData", model.getName());
   }
View Full Code Here


   @Test
   public void shouldBindMultipleModelValuesOnlyThroughExpression()
   {
      // given
      ModelForTests model = new ModelForTests();
      ModelForTests output = new ModelForTests();
      MultipleValuesExpression nameFormatter = new MultipleValuesExpression<Object[], String>()
      {
         @Expressive
         public String fullName(String name, String surname)
         {
            return name + ' ' + surname;
         }
      };
      bind().valueOf(model, ModelForTests.NAME, ModelForTests.SURNAME).through(nameFormatter).to(output, ModelForTests.NAME);
      // when
      model.setName("John");
      model.setSurname("Smith");
      // then
      assertEquals("John Smith", output.getName());
   }
View Full Code Here

   @Test
   public void shouldRemindAboutMissingAnnotationWhenBindMultipleModelValuesOnlyThroughExpression()
   {
      // given
      ModelForTests model = new ModelForTests();
      ModelForTests output = new ModelForTests();
      MultipleValuesExpression nameFormatter = new MultipleValuesExpression<Object[], String>()
      {
         /**
          * Commented on purpose
          * @Expressive
 
View Full Code Here

   public void shouldAllowUnbindingAllBindingsAtTheSameTime()
   {
      // given
      JTextField textField1 = new JTextField();
      JTextField textField2 = new JTextField();
      ModelForTests model = new ModelForTests();
      Binding bind = Binding.bind();

      bind.valueOf(model, ModelForTests.NAME).toTextOf(textField1);
      bind.valueOf(model, ModelForTests.SURNAME).toTextOf(textField2);

      // when
      bind.unbindAll();
      // then
      model.setName("ABC123");
      model.setSurname("ABC123");
      assertEquals("", textField1.getText());
      assertEquals("", textField2.getText());
   }
View Full Code Here

   public void shouldAllowExecutingAllOfTheBindings()
   {
      // given
      JTextField textField1 = new JTextField();
      JTextField textField2 = new JTextField();
      ModelForTests model = new ModelForTests();
      Binding bind = Binding.bind();

      bind.valueOf(model, ModelForTests.NAME).after(never()).toTextOf(textField1);
      bind.valueOf(model, ModelForTests.SURNAME).after(never()).toTextOf(textField2);

      model.setName("ABC123");
      model.setSurname("ABC123");

      assertEquals("", textField1.getText());
      assertEquals("", textField2.getText());

      // when
View Full Code Here

   @Test
   public void shouldBindOnSelectable()
   {
      // given
      ModelForTests model = new ModelForTests();
      JComboBox combo = new JComboBox(Arrays.asList("A", "B", "C").toArray());
      bind().selectedOf(combo).to(model, ModelForTests.SELECTED);
      // when
      combo.setSelectedItem("B");
      // then
      assertEquals("B", ((Object[]) model.getSelected())[0]);
   }
View Full Code Here

   @Test
   public void shouldBindOnButtonSelectionChange()
   {
      // given
      ModelForTests model = new ModelForTests();
      JCheckBox checkBox = new JCheckBox();
      bind().selectedOf(checkBox).to(model, ModelForTests.SELECTED);
      // when
      checkBox.setSelected(true);
      // then
      assertEquals(Boolean.TRUE, model.getSelected());
   }
View Full Code Here

   @Test
   public void shouldUnregisterBindOnButtonSelectionChange()
   {
      // given
      ModelForTests model = new ModelForTests();
      JCheckBox checkBox = new JCheckBox();
      BindingRegistration reg = bind().selectedOf(checkBox).to(model, ModelForTests.SELECTED);
      checkBox.setSelected(true);
      assertEquals(Boolean.TRUE, model.getSelected());

      reg.unbind();
      // when
      checkBox.setSelected(false);
      // then
      assertEquals(Boolean.TRUE, model.getSelected());
   }
View Full Code Here

   @Test
   public void shouldBindModelToButtonSelection()
   {
      // given
      ModelForTests model = new ModelForTests();
      JCheckBox checkBox = new JCheckBox();
      bind().valueOf(model, ModelForTests.SELECTED).toSelectedOf(checkBox);
      // when
      model.setSelected(Boolean.TRUE);
      // then
      assertTrue(checkBox.isSelected());
   }
View Full Code Here

   @Test
   public void shouldBindToBoundPropertiesOnComponents()
   {
      // given
      ModelForTests model = new ModelForTests();
      JButton component = new JButton();
      bind().valueOf(component, "defaultCapable").to(model, ModelForTests.VALUE);
      // when
      component.setDefaultCapable(true);
      // then
      assertTrue(Boolean.TRUE.equals(model.getValue()));
   }
View Full Code Here

TOP

Related Classes of org.izi.ModelForTests

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.