Package org.izi

Examples of org.izi.ModelForTests


   @Test
   @SuppressWarnings("deprecation")
   public void shouldAllowBindingToControlsOnSpecificEvents()
   {
      // given
      ModelForTests model = new ModelForTests();
      JTextField component = new JTextField();
      bind().textOf(component).after(eventsOf(MouseListener.class, MouseEvent.MOUSE_CLICKED)).to(model, ModelForTests.VALUE);
      component.setText("Text to be transferred on specific event");
      assertEquals("", model.getValue());
      // when
      component.dispatchEvent(new MouseEvent(component, MouseEvent.MOUSE_CLICKED, 0, 0, 0, 0, 1, false));
      // then
      assertEquals("Text to be transferred on specific event", model.getValue());
   }
View Full Code Here


   @Test
   public void shouldAllowBindingToControlsThroughExpressions()
   {
      // given
      ModelForTests model = new ModelForTests();
      JTextField component = new JTextField();
      bind().textOf(component).through(toUpperCase()).to(model, ModelForTests.VALUE);
      // when
      component.setText("Text to be transferred on focus lost");
      // then
      assertEquals("TEXT TO BE TRANSFERRED ON FOCUS LOST", model.getValue());
   }
View Full Code Here

   @Test
   public void shouldAllowExecutingControlBindingOnDemand()
   {
      // given
      ModelForTests model = new ModelForTests();
      JTextField component = new JTextField();
      BindingRegistration registration =
         bind().textOf(component).after(EventRegistrations.never()).to(model, ModelForTests.VALUE);
      component.setText("Text");
      assertEquals("", model.getValue());
      // when
      registration.execute();
      // then
      assertEquals("Text", model.getValue());
   }
View Full Code Here

   @Test
   public void shouldAllowExecutingModelBindingOnDemand()
   {
      // given
      ModelForTests from = new ModelForTests();
      ModelForTests to = new ModelForTests();
      BindingRegistration registration =
         bind().valueOf(from, ModelForTests.VALUE).after(EventRegistrations.never())
            .to(to, ModelForTests.VALUE);
      from.setValue("Text");
      assertNull(to.getValue());
      // when
      registration.execute();
      // then
      assertEquals("Text", to.getValue());
   }
View Full Code Here

   @Test
   public void shouldAllowBindingOnListenersOfSpecificEventType()
   {
      // given
      JTextField textInput = new JTextField();
      ModelForTests model = new ModelForTests();
      bind().textOf(textInput).after(EventRegistrations.eventsOf(MouseListener.class, MouseEvent.MOUSE_PRESSED)).to(model, ModelForTests.NAME);
      textInput.setText("abc");
      assertEquals("", model.getName());
      // when
      textInput.dispatchEvent(new MouseEvent(textInput, MouseEvent.MOUSE_PRESSED, 0, 0, 0, 0, 0, false));
      // then
      assertEquals("abc", model.getName());
   }
View Full Code Here

   @Test
   public void shouldFilteredEventShouldNotTriggerBindingOnListenersOfSpecificEventType()
   {
      // given
      JTextField textInput = new JTextField();
      ModelForTests model = new ModelForTests();
      bind().textOf(textInput).after(EventRegistrations.eventsOf(MouseListener.class, MouseEvent.MOUSE_PRESSED)).to(model, ModelForTests.NAME);
      textInput.setText("abc");
      assertEquals("", model.getName());
      // when
      textInput.dispatchEvent(new MouseEvent(textInput, MouseEvent.MOUSE_RELEASED, 0, 0, 0, 0, 0, false));
      // then
      assertEquals("", model.getName());
   }
View Full Code Here

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

   @Test
   public void shouldBindValuesFromModelToTextField()
   {
      // given
      JTextField textField = new JTextField();
      ModelForTests model = new ModelForTests();
      bind().valueOf(model, ModelForTests.NAME).toTextOf(textField);
      // when
      model.setName("ABC123");
      // then
      assertEquals("ABC123", textField.getText());
   }
View Full Code Here

   @Test
   public void shouldBindValuesBetweenModels()
   {
      // given
      ModelForTests model = new ModelForTests();
      bind().valueOf(model, ModelForTests.NAME).to(model, ModelForTests.SURNAME);
      // when
      model.setName("ABC123");
      // then
      assertEquals("ABC123", model.getSurname());
   }
View Full Code Here

   @Test
   public void shouldBindFormattedValueToModel() throws Exception
   {
      // given
      JFormattedTextField textField = new JFormattedTextField(new DateFormatter());
      ModelForTests model = new ModelForTests();
      bind().valueOf(textField).to(model, ModelForTests.DATE);
      Calendar calendar = Calendar.getInstance();
      calendar.set(2010, 4, 10);
      // when
      textField.setText(textField.getFormatter().valueToString(calendar.getTime()));
      textField.commitEdit();
      // then
      assertNotNull(model.getDate());
      calendar.setTime(model.getDate());
      assertEquals(2010, calendar.get(Calendar.YEAR));
      assertEquals(4, calendar.get(Calendar.MONTH));
      assertEquals(10, calendar.get(Calendar.DAY_OF_MONTH));

   }
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.