TimeFrameEditor implements FunctionParameterEditor { public void init(TimeFrame tf, Command onChangeCommand) { this.onChangeCommand = onChangeCommand; this.timeFrame = tf != null ? tf : TimeFrame.parse("begin[year] till end[year]"); this.fromEditor = beanManager.lookupBean(TimeInstantEditor.class).newInstance(); this.fromEditor.init(timeFrame.getFrom(), new Command() { public void execute() { fromEditor.getTimeInstant().setFirstMonthOfYear(getFirstMonthOfYear()); timeFrame.setFrom(fromEditor.getTimeInstant()); changeFirstMonthAvailability(); fireChanges(); } }); this.toEditor = beanManager.lookupBean(TimeInstantEditor.class).newInstance(); this.toEditor.init(timeFrame.getTo(), new Command() { public void execute() { toEditor.getTimeInstant().setFirstMonthOfYear(getFirstMonthOfYear()); timeFrame.setTo(toEditor.getTimeInstant()); changeFirstMonthAvailability(); fireChanges(); } }); view.init(this); initFirstMonthSelector(); changeFirstMonthAvailability(); } @Inject  TimeFrameEditor(View view, SyncBeanManager beanManager); @Override Widget asWidget(); TimeFrame getTimeFrame(); TimeInstantEditor getFromEditor(); TimeInstantEditor getToEditor(); void init(TimeFrame tf, Command onChangeCommand); boolean isFirstMonthAvailable(); Month getFirstMonthOfYear(); void setFirstMonthOfYear(Month month); @Override void setFocus(boolean focus); void changeFirstMonth();  }
@Test public void testViewInitialization() { timeFrameEditor.init(TEN_DAYS, changeCommand); assertEquals(timeFrameView, timeFrameEditor.view); verify(timeFrameView).init(timeFrameEditor); verify(timeFrameView).clearFirstMonthSelector(); verify(timeFrameView, times(Month.values().length)).addFirstMonthItem(any(Month.class)); verify(timeFrameView).setSelectedFirstMonthIndex(Month.MARCH.getIndex() - 1); }
@Test public void testNullInitialization() { timeFrameEditor.init(UNDEFINED, changeCommand); assertEquals(timeFrameView, timeFrameEditor.view); verify(timeFrameView).init(timeFrameEditor); verify(timeFrameView).clearFirstMonthSelector(); verify(timeFrameView, times(Month.values().length)).addFirstMonthItem(any(Month.class)); verify(timeFrameView).setSelectedFirstMonthIndex(Month.JANUARY.getIndex() - 1); }
@Test public void testChangeTimeAmountQuantity() { TimeFrame timeFrame = TimeFrame.parse("now -1year till now"); timeFrameEditor.init(timeFrame, changeCommand); long qb = timeFrame.getFrom().getTimeAmount().getQuantity(); fromAmountEditor.decreaseQuantity(); long qa = timeFrame.getFrom().getTimeAmount().getQuantity(); verify(changeCommand).execute(); assertEquals(qb - 1, qa); }
@Test public void testChangeTimeAmountType() { TimeFrame timeFrame = TimeFrame.parse("now -1year till now"); timeFrameEditor.init(timeFrame, changeCommand); when(timeAmountView.getSelectedTypeIndex()).thenReturn(3); fromAmountEditor.changeIntervalType(); DateIntervalType type = timeFrame.getFrom().getTimeAmount().getType(); verify(changeCommand).execute(); assertEquals(type, DateIntervalType.DAY); }
@Test public void testChangeTimeInstant() { TimeFrame timeFrame = TimeFrame.parse("now -1year till now"); timeFrameEditor.init(timeFrame, changeCommand); when(timeInstantView.getSelectedIntervalTypeIndex()).thenReturn(3); fromInstantEditor.changeIntervalType(); DateIntervalType type = timeFrame.getFrom().getIntervalType(); verify(changeCommand).execute(); assertEquals(type, DateIntervalType.MONTH); }