Package org.izi

Examples of org.izi.ModelForTests


   @Test
   public void shouldBindModelToFormattedValue() throws Exception
   {
      // given
      JFormattedTextField textField = new JFormattedTextField(new DateFormatter());
      ModelForTests model = new ModelForTests();
      bind().valueOf(model, ModelForTests.DATE).toValueOf(textField);
      Calendar calendar = Calendar.getInstance();
      calendar.set(2010, Calendar.APRIL, 10);
      // when
      model.setDate(calendar.getTime());
      // then
      assertNotNull(textField.getValue());
      calendar.setTime((Date) textField.getValue());
      assertEquals(2010, calendar.get(Calendar.YEAR));
      assertEquals(Calendar.APRIL, calendar.get(Calendar.MONTH));
View Full Code Here


   @Test
   public void shouldBindValuesFromTextFieldToModelAfterCustomEvent()
   {
      // given
      JTextField textField = new JTextField();
      ModelForTests model = new ModelForTests();
      bind().textOf(textField).after(ActionListener.class).to(model, ModelForTests.NAME);
      textField.setText("newData");
      assertEquals("", model.getName());
      // when
      // todo fest-based key simulation would be better that this
      textField.postActionEvent();
      // then
      assertEquals("newData", model.getName());
   }
View Full Code Here

   @Test
   public void shouldBindModelValueOnAlternateProperty()
   {
      // given
      ModelForTests model = new ModelForTests();
      ModelForTests output = new ModelForTests();
      bind().valueOf(model, ModelForTests.FULL_NAME).after(ModelForTests.NAME, ModelForTests.SURNAME).to(output, ModelForTests.NAME);
      // when
      model.setName("John");
      model.setSurname("Smith");
      // then
      assertEquals("John Smith", output.getName());
   }
View Full Code Here

   @Test
   public void shouldUnbindModelValueOnAlternateProperty()
   {
      // given
      ModelForTests model = new ModelForTests();
      ModelForTests output = new ModelForTests();
      BindingRegistration reg = bind().valueOf(model, ModelForTests.FULL_NAME).after(ModelForTests.NAME, ModelForTests.SURNAME).to(output, ModelForTests.NAME);
      model.setName("John");
      model.setSurname("Smith");
      assertEquals("John Smith", output.getName());

      reg.unbind();
      // when
      model.setName("Jane");
      model.setSurname("Doe");
      // then
      assertEquals("John Smith", output.getName());

   }
View Full Code Here

   @Test
   public void shouldBindModelValueOnAlternateEvent()
   {
      // given
      ModelForTests model = new ModelForTests();
      ModelForTests output = new ModelForTests();
      bind().valueOf(model, ModelForTests.FULL_NAME).after(PropertyChangeListener.class).to(output, ModelForTests.NAME);
      // when
      model.setName("John");
      model.setSurname("Smith");
      // then
      assertEquals("John Smith", output.getName());
   }
View Full Code Here

   @Test
   public void shouldBindMultipleModelValues()
   {
      // given
      ModelForTests model = new ModelForTests();
      ModelForTests output = new ModelForTests();
      bind().valueOf(model, ModelForTests.NAME, ModelForTests.SURNAME).through(new MultipleValuesExpression()
      {
         @Expressive
         public String formatName(String name, String sureName)
         {
            return name + " " + sureName;
         }
      }).to(output, ModelForTests.NAME);
      // when
      model.setName("John");
      model.setSurname("Smith");
      // then
      assertEquals("John Smith", output.getName());
   }
View Full Code Here

   @Test
   public void shouldUnbindMultipleModelValues()
   {
      // given
      ModelForTests model = new ModelForTests();
      ModelForTests output = new ModelForTests();
      BindingRegistration to = bind().valueOf(model, ModelForTests.NAME, ModelForTests.SURNAME).through(new MultipleValuesExpression()
      {
         @Expressive
         public String formatName(String name, String sureName)
         {
            return name + " " + sureName;
         }
      }).to(output, ModelForTests.NAME);
      model.setName("John");
      model.setSurname("Smith");
      assertEquals("John Smith", output.getName());
      // when
      to.unbind();
      model.setName("Jane");
      model.setSurname("Doe");
      // then
      assertEquals("John Smith", output.getName());
   }
View Full Code Here

   @Test
   public void shouldBindArrayToTableModelIndirectly()
   {
      // given
      ModelForTests model = new ModelForTests();
      JTable table = new JTable();
      bind().valueOf(model, ModelForTests.TABLE_ITEMS).after(ModelForTests.ITEMS).toModelOf(table);
      Object[] items = {"a", "b", "c"};
      // when
      model.setItems(items);
      // then
      assertEquals(2, table.getColumnCount());
      assertEquals(3, table.getRowCount());
   }
View Full Code Here

   @Test
   public void shouldBindArrayToListModel()
   {
      // given
      ModelForTests model = new ModelForTests();
      JList list = new JList();
      bind().valueOf(model, ModelForTests.ITEMS).toModelOf(list);
      Object[] items = {"a", "b", "c"};
      // when
      model.setItems(items);
      // then
      assertEquals(3, list.getModel().getSize());
   }
View Full Code Here

   @Test
   public void shouldBindCollectionToListModel()
   {
      // given
      ModelForTests model = new ModelForTests();
      JList list = new JList();
      bind().valueOf(model, ModelForTests.ITEMS_AS_LIST).toModelOf(list);
      Object[] items = {"a", "b", "c"};
      // when
      model.setItemsAsList(Arrays.asList(items));
      // then
      assertEquals(3, list.getModel().getSize());
   }
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.